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/zeronet: init #44842

Merged
merged 2 commits into from Aug 31, 2018
Merged

nixos/zeronet: init #44842

merged 2 commits into from Aug 31, 2018

Conversation

Chiiruno
Copy link
Contributor

@Chiiruno Chiiruno commented Aug 9, 2018

Motivation for this change

Simple service for zeronet, adjusted the package itself to make things easier.

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)
  • Fits CONTRIBUTING.md.

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Aug 9, 2018

cc @fgaz

# Ensure folder exists or create it and permissions are correct
mkdir -p ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
chmod 750 ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
chown -R zeronet:zeronet ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
Copy link
Member

Choose a reason for hiding this comment

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

If on startup all files are chowned, static uid/gids in nixos/modules/misc/ids.nix are not necessary.

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'm confused, this was fine on my hydron and meguca nix expressions?
Is there something that zeronet does differently?

Copy link
Member

Choose a reason for hiding this comment

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

Not every reviewer knows about everything. I think ids.nix should be avoided if possible, and apparently it's indeed not needed with this.

Copy link
Member

Choose a reason for hiding this comment

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

It can now be removed in meguca as well. Back then when the static numbers where allocated it did not chown everything as this was added later: 36ab899
As meguca might have a large number of image files this could potentially slow down the startup, which why having a static uid/gid would be fine to avoid having to adapt ownership on service start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, so then we do need static uid/gids for zeronet?
If I remember right, zeronet should, at least over time, store at least a few gigabytes, over a lot of files(?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see what you mean now.


makeWrapper "$out/share/zeronet.py" "$out/bin/zeronet_service" \
--set PYTHONPATH "$PYTHONPATH" \
--set PATH ${python2Packages.python}/bin
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use the first wrapper. If you pass a second set of --log_dir and --data_dir, it will override the first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's already defined in the conf this service generates.
Better for ease-of-use and less possible problems.

@Chiiruno
Copy link
Contributor Author

@Mic92 Does anything need to be changed still?

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

@Chiiruno
Copy link
Contributor Author

@infinisil All good?

type = types.path;
default = "/var/log/zeronet";
example = "/home/okina/zeronet/log";
description = "Path to the zeronet log directory.";
Copy link
Member

Choose a reason for hiding this comment

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

Is it not possible to make it use the systemd journal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do this with zeronet?
Is it just a matter of moving the default value to $whatever/systemd/log?

Copy link
Member

Choose a reason for hiding this comment

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

stdout/stderr should work automatically. If it's not possible to tell it to output like that, /proc/self/fd/{1,2} might work

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Does not seems like it can at the moment. It also does not do log rotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there anything we can do here, or should I mark this as resolved?

--set PYTHONPATH "$PYTHONPATH" \
--set PATH ${python2Packages.python}/bin \
--add-flags "--log_dir \$HOME/.local/share/zeronet/logs" \
--add-flags "--data_dir \$HOME/.local/share/zeronet"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this binary should have been wrapped like this in the first place. Nix packages shouldn't pass convenience arguments, that's up to the user. If anything I'd argue to remove these arguments for the main binary and not have the zeronet_service wrapper, makes much more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, zeronet will not start without log_dir and data_dir set, so I think I understand why @fgaz made this a wrapper. Not sure about PYTHONPATH or PATH, though, but I remember having problems calling the .py directly without the wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

Nix packages don't need to provide a binary that runs without any arguments, they just need to provide the binary that gets distributed, optionally wrapped with some env vars to make it work under Nix. Passing the right arguments will be the job of either the user or some wrapper higher up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll see if I can't get rid of the wrappers altogether, but I may still have to wrap the PYTHONPATH and maaaaaybe the PATH. If log_dir and data_dir aren't a problem, then I can easily get rid of the zeronet_service wrapper too.

@Chiiruno
Copy link
Contributor Author

@infinisil Okay, that should do it.
I'll need to do the same for my hydron and meguca package whenever I update them.

@Chiiruno
Copy link
Contributor Author

@infinisil Are we all good?
Thoughts on my question above?

@Chiiruno
Copy link
Contributor Author

Okay, ready for review.

description = "zeronet";
after = [ "network.target" (optionalString cfg.tor "tor.service") ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ zConfFile ];
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this isn't needed when you reference it in ExecStart already

@Chiiruno
Copy link
Contributor Author

@infinisil All good?

@Mic92 Mic92 merged commit 17564e0 into NixOS:master Aug 31, 2018
@Chiiruno Chiiruno deleted the dev/zeronet branch August 31, 2018 20:12
@aanderse aanderse mentioned this pull request Apr 22, 2019
10 tasks
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

6 participants