From 17564e0ed9e5948c6c34cecf63bc45fd08c7135a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=81=E3=83=AB=E3=83=8E?= Date: Fri, 31 Aug 2018 05:40:23 -0500 Subject: [PATCH] nixos/zeronet: init (#44842) --- nixos/modules/misc/ids.nix | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/networking/zeronet.nix | 102 ++++++++++++++++++ .../networking/p2p/zeronet/default.nix | 12 +-- 4 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 nixos/modules/services/networking/zeronet.nix diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 0928e368d80..8292cdc995e 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -328,6 +328,7 @@ qemu-libvirtd = 301; # kvm = 302; # unused # render = 303; # unused + zeronet = 304; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -616,6 +617,7 @@ qemu-libvirtd = 301; kvm = 302; # default udev rules from systemd requires these render = 303; # default udev rules from systemd requires these + zeronet = 304; # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 93e6050e1dd..4795922abcf 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -620,6 +620,7 @@ ./services/networking/xl2tpd.nix ./services/networking/xrdp.nix ./services/networking/zerobin.nix + ./services/networking/zeronet.nix ./services/networking/zerotierone.nix ./services/networking/znc.nix ./services/printing/cupsd.nix diff --git a/nixos/modules/services/networking/zeronet.nix b/nixos/modules/services/networking/zeronet.nix new file mode 100644 index 00000000000..2377cb2c8f1 --- /dev/null +++ b/nixos/modules/services/networking/zeronet.nix @@ -0,0 +1,102 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.services.zeronet; + + zConfFile = pkgs.writeTextFile { + name = "zeronet.conf"; + + text = '' + [global] + data_dir = ${cfg.dataDir} + log_dir = ${cfg.logDir} + '' + lib.optionalString (cfg.port != null) '' + ui_port = ${toString cfg.port} + '' + cfg.extraConfig; + }; +in with lib; { + options.services.zeronet = { + enable = mkEnableOption "zeronet"; + + dataDir = mkOption { + type = types.path; + default = "/var/lib/zeronet"; + example = "/home/okina/zeronet"; + description = "Path to the zeronet data directory."; + }; + + logDir = mkOption { + type = types.path; + default = "/var/log/zeronet"; + example = "/home/okina/zeronet/log"; + description = "Path to the zeronet log directory."; + }; + + port = mkOption { + type = types.nullOr types.int; + default = null; + example = 15441; + description = "Optional zeronet port."; + }; + + tor = mkOption { + type = types.bool; + default = false; + description = "Use TOR for all zeronet traffic."; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + + description = '' + Extra configuration. Contents will be added verbatim to the + configuration file at the end. + ''; + }; + }; + + config = mkIf cfg.enable { + services.tor = mkIf cfg.tor { + enable = true; + controlPort = 9051; + extraConfig = "CookieAuthentication 1"; + }; + + systemd.services.zeronet = { + description = "zeronet"; + after = [ "network.target" (optionalString cfg.tor "tor.service") ]; + wantedBy = [ "multi-user.target" ]; + + preStart = '' + # 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 zeronet:zeronet ${escapeShellArg cfg.dataDir} ${escapeShellArg cfg.logDir} + ''; + + serviceConfig = { + PermissionsStartOnly = true; + PrivateTmp = "yes"; + User = "zeronet"; + Group = "zeronet"; + ExecStart = "${pkgs.zeronet}/bin/zeronet --config_file ${zConfFile}"; + }; + }; + + users = { + groups.zeronet.gid = config.ids.gids.zeronet; + + users.zeronet = { + description = "zeronet service user"; + home = cfg.dataDir; + createHome = true; + group = "zeronet"; + extraGroups = mkIf cfg.tor [ "tor" ]; + uid = config.ids.uids.zeronet; + }; + }; + }; + + meta.maintainers = with maintainers; [ chiiruno ]; +} diff --git a/pkgs/applications/networking/p2p/zeronet/default.nix b/pkgs/applications/networking/p2p/zeronet/default.nix index 8a8d1b33ca7..33acd103d8b 100644 --- a/pkgs/applications/networking/p2p/zeronet/default.nix +++ b/pkgs/applications/networking/p2p/zeronet/default.nix @@ -3,6 +3,7 @@ python2Packages.buildPythonApplication rec { pname = "zeronet"; version = "0.6.2"; + format = "other"; src = fetchFromGitHub { owner = "HelloZeroNet"; @@ -12,9 +13,6 @@ python2Packages.buildPythonApplication rec { }; propagatedBuildInputs = with python2Packages; [ msgpack gevent ]; - - format = "other"; - buildPhase = "${python2Packages.python.interpreter} -O -m compileall ."; installPhase = '' @@ -22,14 +20,10 @@ python2Packages.buildPythonApplication rec { cp -r plugins src tools *.py $out/share/ ''; - # Wrap the main executable and set the log and data dir to something out of - # the store postFixup = '' makeWrapper "$out/share/zeronet.py" "$out/bin/zeronet" \ - --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" + --set PYTHONPATH "$PYTHONPATH" \ + --set PATH ${python2Packages.python}/bin ''; meta = with stdenv.lib; {