From f2fc1b004635e2bf6e6dd2e672fd09dac6922814 Mon Sep 17 00:00:00 2001
From: Okinan <okinan@chiru.no>
Date: Thu, 3 Oct 2019 01:25:08 -0500
Subject: [PATCH 1/2] nixos/zeronet: remove static uid and gid
---
nixos/modules/misc/ids.nix | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index ac6af1ce8b7..3e8a5b07a5e 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -328,7 +328,7 @@
qemu-libvirtd = 301;
# kvm = 302; # unused
# render = 303; # unused
- zeronet = 304;
+ # zeronet = 304; # removed 2019-01-03
lirc = 305;
lidarr = 306;
slurm = 307;
@@ -629,7 +629,7 @@
qemu-libvirtd = 301;
kvm = 302; # default udev rules from systemd requires these
render = 303; # default udev rules from systemd requires these
- zeronet = 304;
+ # zeronet = 304; # removed 2019-01-03
lirc = 305;
lidarr = 306;
slurm = 307;
From 5c18c08da9fd13d583b56d3b8cc698621ce8cd16 Mon Sep 17 00:00:00 2001
From: Okinan <okinan@chiru.no>
Date: Thu, 3 Oct 2019 17:03:32 -0500
Subject: [PATCH 2/2] nixos/zeronet: improved config, dynamic user
---
nixos/modules/services/networking/zeronet.nix | 90 +++++++------------
1 file changed, 32 insertions(+), 58 deletions(-)
diff --git a/nixos/modules/services/networking/zeronet.nix b/nixos/modules/services/networking/zeronet.nix
index f4988a90268..f354a9d42c7 100644
--- a/nixos/modules/services/networking/zeronet.nix
+++ b/nixos/modules/services/networking/zeronet.nix
@@ -1,44 +1,39 @@
{ config, lib, pkgs, ... }:
let
+ inherit (lib) generators literalExample mkEnableOption mkIf mkOption recursiveUpdate types;
cfg = config.services.zeronet;
+ dataDir = "/var/lib/zeronet";
+ configFile = pkgs.writeText "zeronet.conf" (generators.toINI {} (recursiveUpdate defaultSettings cfg.settings));
- 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}
- '' + lib.optionalString (cfg.fileserverPort != null) ''
- fileserver_port = ${toString cfg.fileserverPort}
- '' + lib.optionalString (cfg.torAlways) ''
- tor = always
- '' + cfg.extraConfig;
+ defaultSettings = {
+ global = {
+ data_dir = dataDir;
+ log_dir = dataDir;
+ ui_port = cfg.port;
+ fileserver_port = cfg.fileserverPort;
+ tor = if !cfg.tor then "disable" else if cfg.torAlways then "always" else "enable";
+ };
};
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.";
- };
+ settings = mkOption {
+ type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
+ default = {};
+ example = literalExample "global.tor = enable;";
- logDir = mkOption {
- type = types.path;
- default = "/var/log/zeronet";
- example = "/home/okina/zeronet/log";
- description = "Path to the zeronet log directory.";
+ description = ''
+ <filename>zeronet.conf</filename> configuration. Refer to
+ <link xlink:href="https://zeronet.readthedocs.io/en/latest/faq/#is-it-possible-to-use-a-configuration-file"/>
+ for details on supported values;
+ '';
};
port = mkOption {
- type = types.nullOr types.int;
- default = null;
+ type = types.int;
+ default = 43110;
example = 43110;
description = "Optional zeronet web UI port.";
};
@@ -63,22 +58,13 @@ in with lib; {
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 = ''
CacheDirectoryGroupReadable 1
CookieAuthentication 1
@@ -86,37 +72,25 @@ in with lib; {
'';
};
- systemd.tmpfiles.rules = [
- "d '${cfg.dataDir}' 750 zeronet zeronet - -"
- "d '${cfg.logDir}' 750 zeronet zeronet - -"
- ];
-
systemd.services.zeronet = {
description = "zeronet";
after = [ "network.target" (optionalString cfg.tor "tor.service") ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
- 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;
+ DynamicUser = true;
+ StateDirectory = "zeronet";
+ SupplementaryGroups = mkIf cfg.tor [ "tor" ];
+ ExecStart = "${pkgs.zeronet}/bin/zeronet --config_file ${configFile}";
};
};
};
+ imports = [
+ (mkRemovedOptionModule [ "services" "zeronet" "dataDir" ] "Zeronet will store data by default in /var/lib/zeronet")
+ (mkRemovedOptionModule [ "services" "zeronet" "logDir" ] "Zeronet will log by default in /var/lib/zeronet")
+ ];
+
meta.maintainers = with maintainers; [ chiiruno ];
}