git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/zeronet: init (#44842)
commit17564e0ed9e5948c6c34cecf63bc45fd08c7135a authorチルノ <okinan@chiru.no> dateFri 31 Aug 2018, 05:40 (8 years ago) parent297a82f
4 files changed+108−9
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/networking/zeronet.nix+102 pkgs/applications/networking/p2p/zeronet/default.nix+3−9
nixos/modules/misc/ids.nix+2
@@ -328,6 +328,7 @@
328328 qemu-libvirtd = 301;
329329 # kvm = 302; # unused
330330 # render = 303; # unused
331+ zeronet = 304;
331332
332333 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
333334
@@ -616,6 +617,7 @@
616617 qemu-libvirtd = 301;
617618 kvm = 302; # default udev rules from systemd requires these
618619 render = 303; # default udev rules from systemd requires these
620+ zeronet = 304;
619621
620622 # When adding a gid, make sure it doesn't match an existing
621623 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -620,6 +620,7 @@
620620 ./services/networking/xl2tpd.nix
621621 ./services/networking/xrdp.nix
622622 ./services/networking/zerobin.nix
623+ ./services/networking/zeronet.nix
623624 ./services/networking/zerotierone.nix
624625 ./services/networking/znc.nix
625626 ./services/printing/cupsd.nix
nixos/modules/services/networking/zeronet.nixnew file+102
@@ -0,0 +1,102 @@
1+{ config, lib, pkgs, ... }:
2+
3+let
4+ cfg = config.services.zeronet;
5+
6+ zConfFile = pkgs.writeTextFile {
7+ name = "zeronet.conf";
8+
9+ text = ''
10+ [global]
11+ data_dir = ${cfg.dataDir}
12+ log_dir = ${cfg.logDir}
13+ '' + lib.optionalString (cfg.port != null) ''
14+ ui_port = ${toString cfg.port}
15+ '' + cfg.extraConfig;
16+ };
17+in with lib; {
18+ options.services.zeronet = {
19+ enable = mkEnableOption "zeronet";
20+
21+ dataDir = mkOption {
22+ type = types.path;
23+ default = "/var/lib/zeronet";
24+ example = "/home/okina/zeronet";
25+ description = "Path to the zeronet data directory.";
26+ };
27+
28+ logDir = mkOption {
29+ type = types.path;
30+ default = "/var/log/zeronet";
31+ example = "/home/okina/zeronet/log";
32+ description = "Path to the zeronet log directory.";
33+ };
34+
35+ port = mkOption {
36+ type = types.nullOr types.int;
37+ default = null;
38+ example = 15441;
39+ description = "Optional zeronet port.";
40+ };
41+
42+ tor = mkOption {
43+ type = types.bool;
44+ default = false;
45+ description = "Use TOR for all zeronet traffic.";
46+ };
47+
48+ extraConfig = mkOption {
49+ type = types.lines;
50+ default = "";
51+
52+ description = ''
53+ Extra configuration. Contents will be added verbatim to the
54+ configuration file at the end.
55+ '';
56+ };
57+ };
58+
59+ config = mkIf cfg.enable {
60+ services.tor = mkIf cfg.tor {
61+ enable = true;
62+ controlPort = 9051;
63+ extraConfig = "CookieAuthentication 1";
64+ };
65+
66+ systemd.services.zeronet = {
67+ description = "zeronet";
68+ after = [ "network.target" (optionalString cfg.tor "tor.service") ];
69+ wantedBy = [ "multi-user.target" ];
70+
71+ preStart = ''
72+ # Ensure folder exists or create it and permissions are correct
73+ mkdir -p ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
74+ chmod 750 ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
75+ chown zeronet:zeronet ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir}
76+ '';
77+
78+ serviceConfig = {
79+ PermissionsStartOnly = true;
80+ PrivateTmp = "yes";
81+ User = "zeronet";
82+ Group = "zeronet";
83+ ExecStart = "${pkgs.zeronet}/bin/zeronet --config_file ${zConfFile}";
84+ };
85+ };
86+
87+ users = {
88+ groups.zeronet.gid = config.ids.gids.zeronet;
89+
90+ users.zeronet = {
91+ description = "zeronet service user";
92+ home = cfg.dataDir;
93+ createHome = true;
94+ group = "zeronet";
95+ extraGroups = mkIf cfg.tor [ "tor" ];
96+ uid = config.ids.uids.zeronet;
97+ };
98+ };
99+ };
100+
101+ meta.maintainers = with maintainers; [ chiiruno ];
102+}
pkgs/applications/networking/p2p/zeronet/default.nix+3−9
@@ -3,6 +3,7 @@
33python2Packages.buildPythonApplication rec {
44 pname = "zeronet";
55 version = "0.6.2";
6+ format = "other";
67
78 src = fetchFromGitHub {
89 owner = "HelloZeroNet";
@@ -12,9 +13,6 @@ python2Packages.buildPythonApplication rec {
1213 };
1314
1415 propagatedBuildInputs = with python2Packages; [ msgpack gevent ];
15−
16− format = "other";
17−
1816 buildPhase = "${python2Packages.python.interpreter} -O -m compileall .";
1917
2018 installPhase = ''
@@ -22,14 +20,10 @@ python2Packages.buildPythonApplication rec {
2220 cp -r plugins src tools *.py $out/share/
2321 '';
2422
25− # Wrap the main executable and set the log and data dir to something out of
26− # the store
2723 postFixup = ''
2824 makeWrapper "$out/share/zeronet.py" "$out/bin/zeronet" \
29− --set PYTHONPATH "$PYTHONPATH" \
30− --set PATH ${python2Packages.python}/bin \
31− --add-flags "--log_dir \$HOME/.local/share/zeronet/logs" \
32− --add-flags "--data_dir \$HOME/.local/share/zeronet"
25+ --set PYTHONPATH "$PYTHONPATH" \
26+ --set PATH ${python2Packages.python}/bin
3327 '';
3428
3529 meta = with stdenv.lib; {