1 { config, lib, pkgs, ... }:
4 inherit (lib) generators literalExpression mkEnableOption mkIf mkOption recursiveUpdate types;
5 cfg = config.services.zeronet;
6 dataDir = "/var/lib/zeronet";
7 configFile = pkgs.writeText "zeronet.conf" (generators.toINI {} (recursiveUpdate defaultSettings cfg.settings));
14 fileserver_port = cfg.fileserverPort;
15 tor = if !cfg.tor then "disable" else if cfg.torAlways then "always" else "enable";
19 options.services.zeronet = {
20 enable = mkEnableOption (lib.mdDoc "zeronet");
24 default = pkgs.zeronet;
25 defaultText = literalExpression "pkgs.zeronet";
26 description = lib.mdDoc "ZeroNet package to use";
30 type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
32 example = literalExpression "{ global.tor = enable; }";
34 description = lib.mdDoc ''
35 {file}`zeronet.conf` configuration. Refer to
36 <https://zeronet.readthedocs.io/en/latest/faq/#is-it-possible-to-use-a-configuration-file>
37 for details on supported values;
44 description = lib.mdDoc "Optional zeronet web UI port.";
47 fileserverPort = mkOption {
48 # Not optional: when absent zeronet tries to write one to the
49 # read-only config file and crashes
52 description = lib.mdDoc "Zeronet fileserver port.";
58 description = lib.mdDoc "Use TOR for zeronet traffic where possible.";
61 torAlways = mkOption {
64 description = lib.mdDoc "Use TOR for all zeronet traffic.";
68 config = mkIf cfg.enable {
69 services.tor = mkIf cfg.tor {
74 CacheDirectoryGroupReadable 1
75 CookieAuthentication 1
76 CookieAuthFileGroupReadable 1
80 systemd.services.zeronet = {
81 description = "zeronet";
82 after = [ "network.target" ] ++ optional cfg.tor "tor.service";
83 wantedBy = [ "multi-user.target" ];
88 StateDirectory = "zeronet";
89 SupplementaryGroups = mkIf cfg.tor [ "tor" ];
90 ExecStart = "${cfg.package}/bin/zeronet --config_file ${configFile}";
96 (mkRemovedOptionModule [ "services" "zeronet" "dataDir" ] "Zeronet will store data by default in /var/lib/zeronet")
97 (mkRemovedOptionModule [ "services" "zeronet" "logDir" ] "Zeronet will log by default in /var/lib/zeronet")
100 meta.maintainers = with maintainers; [ Madouura ];