2018-08-31 10:40:23 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2023-11-27 00:19:27 +00:00
|
|
|
inherit (lib) generators literalExpression mkEnableOption mkPackageOption
|
|
|
|
mkIf mkOption recursiveUpdate types;
|
2018-08-31 10:40:23 +00:00
|
|
|
cfg = config.services.zeronet;
|
2019-10-03 22:03:32 +00:00
|
|
|
dataDir = "/var/lib/zeronet";
|
|
|
|
configFile = pkgs.writeText "zeronet.conf" (generators.toINI {} (recursiveUpdate defaultSettings cfg.settings));
|
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
2018-08-31 10:40:23 +00:00
|
|
|
};
|
|
|
|
in with lib; {
|
|
|
|
options.services.zeronet = {
|
|
|
|
enable = mkEnableOption "zeronet";
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "zeronet" { };
|
2022-05-21 15:06:28 +00:00
|
|
|
|
2019-10-03 22:03:32 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
|
|
|
|
default = {};
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression "{ global.tor = enable; }";
|
2018-08-31 10:40:23 +00:00
|
|
|
|
2019-10-03 22:03:32 +00:00
|
|
|
description = ''
|
|
|
|
{file}`zeronet.conf` configuration. Refer to
|
|
|
|
<https://zeronet.readthedocs.io/en/latest/faq/#is-it-possible-to-use-a-configuration-file>
|
|
|
|
for details on supported values;
|
|
|
|
'';
|
2018-08-31 10:40:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-08-01 11:09:26 +00:00
|
|
|
type = types.port;
|
2019-10-03 22:03:32 +00:00
|
|
|
default = 43110;
|
2018-09-08 17:12:11 +00:00
|
|
|
description = "Optional zeronet web UI port.";
|
2018-08-31 10:40:23 +00:00
|
|
|
};
|
|
|
|
|
2019-03-23 16:57:41 +00:00
|
|
|
fileserverPort = mkOption {
|
|
|
|
# Not optional: when absent zeronet tries to write one to the
|
|
|
|
# read-only config file and crashes
|
2021-08-01 11:09:26 +00:00
|
|
|
type = types.port;
|
2019-03-23 16:57:41 +00:00
|
|
|
default = 12261;
|
|
|
|
description = "Zeronet fileserver port.";
|
|
|
|
};
|
|
|
|
|
2018-08-31 10:40:23 +00:00
|
|
|
tor = mkOption {
|
2018-09-08 17:12:11 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Use TOR for zeronet traffic where possible.";
|
|
|
|
};
|
|
|
|
|
|
|
|
torAlways = mkOption {
|
2018-08-31 10:40:23 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Use TOR for all zeronet traffic.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.tor = mkIf cfg.tor {
|
|
|
|
enable = true;
|
|
|
|
controlPort = 9051;
|
2019-10-03 22:03:32 +00:00
|
|
|
|
2018-09-08 17:12:11 +00:00
|
|
|
extraConfig = ''
|
|
|
|
CacheDirectoryGroupReadable 1
|
|
|
|
CookieAuthentication 1
|
|
|
|
CookieAuthFileGroupReadable 1
|
|
|
|
'';
|
2018-08-31 10:40:23 +00:00
|
|
|
};
|
2018-09-08 17:12:11 +00:00
|
|
|
|
2018-08-31 10:40:23 +00:00
|
|
|
systemd.services.zeronet = {
|
|
|
|
description = "zeronet";
|
2022-05-21 16:34:10 +00:00
|
|
|
after = [ "network.target" ] ++ optional cfg.tor "tor.service";
|
2018-08-31 10:40:23 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "zeronet";
|
2019-10-03 22:03:32 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "zeronet";
|
|
|
|
SupplementaryGroups = mkIf cfg.tor [ "tor" ];
|
2022-05-21 15:06:28 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/zeronet --config_file ${configFile}";
|
2018-08-31 10:40:23 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-10-03 22:03:32 +00:00
|
|
|
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")
|
|
|
|
];
|
|
|
|
|
2022-04-17 23:13:36 +00:00
|
|
|
meta.maintainers = with maintainers; [ Madouura ];
|
2018-08-31 10:40:23 +00:00
|
|
|
}
|