Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/adguardhome: init #120568

Merged
merged 1 commit into from Apr 30, 2021
Merged

nixos/adguardhome: init #120568

merged 1 commit into from Apr 30, 2021

Conversation

lunik1
Copy link
Contributor

@lunik1 lunik1 commented Apr 24, 2021

Motivation for this change

Adds a system service for AdGuard Home.

The service definition is largely based on the one generated by AdGuard Home itself when passed adguardhome --service install (this won't work on NixOS, as it will try to write to a read-only filesystem), with an additional choice of config, work, and pid file locations that should follow the FHS.

May provide some relief for followers of #61617 while they wait for #108055 & the following PRs (but won't actually work on a pi without overriding the adguardhome package because of #113900)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Comment on lines 23 to 29
confFile = mkOption {
default = "/etc/AdGuardHome.yaml";
type = path;
description = ''
Path to the config file.
'';
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow NixOS/rfcs#42.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a non-mutable config file will not work well for this service. Management via the webui does not work and the config file is migrated automatically between schema versions on some application updates.

Maybe it would be better, as it is mutable, to store the config file in the work dir by default? Anyone who really wants to try for a stateless config can then override confFile and use environment.etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application also fails the initial set-up if the config file is not writable.

@lunik1
Copy link
Contributor Author

lunik1 commented Apr 25, 2021

I think it might make sense to introduce an openFirewall option to this module, although I am not exactly sure what it should cover. The port the webUI is served on is specified by port, but not the port the DNS server is served on (which is specified in the config file / on initial setup). However, ports 53 will be used in the vast majority of cases.

};

pidFile = mkOption {
default = "/run/AdGuardHome.pid";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = "/run/AdGuardHome.pid";
default = "/run/AdGuardHome/AdGuardHome.pid";

Copy link
Contributor Author

@lunik1 lunik1 Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with a "no such file or directory error", looks like the directory must exist. Is leaving it in /run ok or should there be some mechanism to ensure /run/AdGuardHome exists?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what the correct way is to create the directory but otherwise it isn't easily mountable in containers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunik1 lunik1 force-pushed the adguardhome-service branch 3 times, most recently from 67e096f to 6547fb9 Compare April 27, 2021 13:48
'';
};

logFile = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please default to stdout.

'';
};

pidFile = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what scenario does this need to be configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pidFile can't be specified in the config file and if it wasn't configurable (e.g. fixed to /run/AdGuardHome/AdGuardHome.pid) it would be inconvenient to override. A few other modules (mongodb, bitcoind) do allow pidFile to be configured, but I admit I can't think of a use case.

Alternatively, the pid file could be disabled by default and enabled when needed through an extraArgs option. Could probably at least remove verbose in that case too.

options.services.adguardhome = with types; {
enable = mkEnableOption "AdGuard Home network-wide ad blocker";

confFile = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to be mutable? Who manages this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config file should be managed by AdGuard Home, see my response to dotlambda's review for my rationale. If this is the case should it be placed in stateDir?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have briefly read some documentation from upstream and I understand now. This application is definitely an example of an application that should manage its own configuration... not NixOS, as you mention.

I would recommend not including this as an option so. You could probably do something really slick with DynamicUser, RuntimeDirectory (for the pid file and reloads) and StateDirectory as well...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DynamicUser works! What do you think should remain configurable when using it? In my view host and port are the essentials, pidFile could just be set to /run/AdGuardHome/AdGuardHome.pid (I can't see a strong case as to the need to disable it), and logs could always be to stdout?

There could be an extraArgs flag, allowing verbose logs if a user needs it and supplying an escape hatch for future command-line options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good 👍 Whatever you think is needed.

'';
};

workDir = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we call this stateDir, depending on what it is for...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where AdGuard Home stores filter lists / it's internal database. I was just copying AdGuard Home's terminology for workDir (which I saw used in a few other modules). But stateDir is more appropriate, I'll change it (in the morning 😴).

@lunik1 lunik1 marked this pull request as draft April 28, 2021 17:38
@lunik1
Copy link
Contributor Author

lunik1 commented Apr 28, 2021

Marking as draft while I look into DynamicUser

@lunik1
Copy link
Contributor Author

lunik1 commented Apr 29, 2021

Pushed a commit that uses DynamicUser, remove options with no clear use case, and adds an openFirewall option for the webui.

Probably should all be squashed on merge.

@lunik1 lunik1 marked this pull request as ready for review April 29, 2021 15:35
Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the pending changes you are about to push I approve this module 👍 Great work 🎉

Copy link
Member

@dotlambda dotlambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I didn't test it.

nixos/modules/services/networking/adguardhome.nix Outdated Show resolved Hide resolved
@dotlambda dotlambda merged commit 248a57d into NixOS:master Apr 30, 2021
@lunik1
Copy link
Contributor Author

lunik1 commented Apr 30, 2021

Thanks everybody for the help and feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants