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

nzbget: Fix script for copying default config file template #51235

Merged
merged 7 commits into from Feb 13, 2019

Conversation

WhittlesJr
Copy link
Contributor

Motivation for this change

Fixes #51234

I feel like the options should be more robust and actually allow you to configure the service through nix, but this at least gets it working out of the box.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

nixos/modules/services/misc/nzbget.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/nzbget.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/nzbget.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/nzbget.nix Outdated Show resolved Hide resolved
@flokli
Copy link
Contributor

flokli commented Dec 18, 2018

added some comments, we can use StateDirectory= to simplify the script a lot.

@flokli
Copy link
Contributor

flokli commented Feb 13, 2019

@WhittlesJr can you rebase to master?

@WhittlesJr
Copy link
Contributor Author

@flokli, should I also squash?

@flokli flokli merged commit 58d6951 into NixOS:master Feb 13, 2019
@flokli
Copy link
Contributor

flokli commented Feb 13, 2019

fine, I squash & merge'd.

@flokli
Copy link
Contributor

flokli commented Feb 13, 2019

Thanks for the PR and followups!

@WhittlesJr
Copy link
Contributor Author

Thank you! Sorry for the lag and the poor commit management on my end.

@flokli
Copy link
Contributor

flokli commented Feb 14, 2019

No worries :-)

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.

@WhittlesJr I know it seems weird to submit a review after this has been merged... but I tried enabling this service which I have never used before and it did not run. I took a look at the module and noticed these problems.

ping @flokli

sed -i -e 's/MainDir=.*/MainDir=\/tmp/g' $configfile
}
echo "Ensuring proper ownership of $datadir (${cfg.user}:${cfg.group})."
chown -R ${cfg.user}:${cfg.group} $datadir
Copy link
Member

Choose a reason for hiding this comment

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

The systemd service has PermissionsStartOnly = "true"; which means that everything executed in the preStart is run as root, including the install call. Since you have taken out the call to chown everything would be owned by root.

@@ -4,6 +4,7 @@ with lib;

let
cfg = config.services.nzbget;
dataDir = builtins.dirOf cfg.configFile;
Copy link
Member

Choose a reason for hiding this comment

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

Now the dataDir option is no longer being used, but remains in the module. If the option is really to be removed you should use mkRemovedOptionModule and possibly mention in release notes.

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

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

@aanderse you're right - Seems I missed some bits here - added my comments, too.

@WhittlesJr when looking at reducing complexity anyhow:

Is it common to run nzbget as a regular user, or is running as a service more common? In that case, we could use DynamicUser=true, and avoid allocating (and asking for) users and groups alltogether.

@@ -93,6 +89,8 @@ in {
'';

serviceConfig = {
StateDirectory = dataDir;
Copy link
Contributor

Choose a reason for hiding this comment

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

StateDirectory needs to be passed relative to /var/lib/. I'd just hardcode this to nzbget.

@@ -41,6 +42,12 @@ in {
default = "nzbget";
description = "Group under which NZBGet runs";
};

configFile = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can probably be dropped too, and just be hardcoded to /var/lib/nzbget/nzbget.conf.

@aanderse
Copy link
Member

@flokli nzbget I would probably suggest keeping the separate nzbget user, adding something like serviceConfig.UMask = "0002"; to the systemd service, and then for each user who needs access you can add extraGroups = [ "nzbget" ]; so users can access the files. The problem with DynamicUser is that files become inaccessible to the user.

@WhittlesJr
Copy link
Contributor Author

I don't personally use this service, and I won't have time to apply these changes any time soon. Could one of you start a new PR?

@aanderse
Copy link
Member

@flokli I'll take this one as I would have eventually got around to it as part of #56265 anyways. Do my DynamicUser comments make sense?

Thanks for the heads up @WhittlesJr

@flokli
Copy link
Contributor

flokli commented Apr 22, 2019

@aanderse the comments about DynamicUser make sense - I forgot state directories go through the /var/lib/private isolation when dynamic users are enabled.

@garrett-hopper
Copy link

I'm having an issue with the NzbGet service not creating the parent directory before trying to copy the default config.
58d6951#r34419534

@aanderse
Copy link
Member

@Jumblemuddle Can you please post relevant output from journald? Are you running off of master from after #60019 was merged?

@garrett-hopper
Copy link

Jul 23 22:34:51 iapetus y4wv84dd10iqgjb0n2i5d9a1r65y319i-unit-script-nzbget-pre-start[8524]: /var/lib/nzbget/nzbget.conf not found. Copying default config /nix/store/h8v16pj65vvswdq4lfqdx0gp5w0qx9hg-nzbget-20.0/share/nzbget/nzbget.conf to /var/lib/nzbget/nzbget.conf
Jul 23 22:34:51 iapetus y4wv84dd10iqgjb0n2i5d9a1r65y319i-unit-script-nzbget-pre-start[8524]: install: cannot create regular file '/var/lib/nzbget/nzbget.conf': No such file or directory

I don't think I have the changes from #60019, since I got the ... Copying default config ... message.
I've since switched to having the config file in the nix store. I think this error report can be disregarded. :)

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.

nzbget service not creating its default configFIle
5 participants