1 { config, lib, pkgs, ... }:
4 inherit (lib) generators literalExpression mkEnableOption mkPackageOption
5 mkIf mkOption recursiveUpdate types;
6 cfg = config.services.zeronet;
7 dataDir = "/var/lib/zeronet";
8 configFile = pkgs.writeText "zeronet.conf" (generators.toINI {} (recursiveUpdate defaultSettings cfg.settings));
15 fileserver_port = cfg.fileserverPort;
16 tor = if !cfg.tor then "disable" else if cfg.torAlways then "always" else "enable";
20 options.services.zeronet = {
21 enable = mkEnableOption "zeronet";
23 package = mkPackageOption pkgs "zeronet" { };
26 type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
28 example = literalExpression "{ global.tor = enable; }";
31 {file}`zeronet.conf` configuration. Refer to
32 <https://zeronet.readthedocs.io/en/latest/faq/#is-it-possible-to-use-a-configuration-file>
33 for details on supported values;
40 description = "Optional zeronet web UI port.";
43 fileserverPort = mkOption {
44 # Not optional: when absent zeronet tries to write one to the
45 # read-only config file and crashes
48 description = "Zeronet fileserver port.";
54 description = "Use TOR for zeronet traffic where possible.";
57 torAlways = mkOption {
60 description = "Use TOR for all zeronet traffic.";
64 config = mkIf cfg.enable {
65 services.tor = mkIf cfg.tor {
70 CacheDirectoryGroupReadable 1
71 CookieAuthentication 1
72 CookieAuthFileGroupReadable 1
76 systemd.services.zeronet = {
77 description = "zeronet";
78 after = [ "network.target" ] ++ optional cfg.tor "tor.service";
79 wantedBy = [ "multi-user.target" ];
84 StateDirectory = "zeronet";
85 SupplementaryGroups = mkIf cfg.tor [ "tor" ];
86 ExecStart = "${cfg.package}/bin/zeronet --config_file ${configFile}";
92 (mkRemovedOptionModule [ "services" "zeronet" "dataDir" ] "Zeronet will store data by default in /var/lib/zeronet")
93 (mkRemovedOptionModule [ "services" "zeronet" "logDir" ] "Zeronet will log by default in /var/lib/zeronet")
96 meta.maintainers = with maintainers; [ Madouura ];