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