2018-08-31 12:40:23 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.zeronet;
|
|
|
|
|
|
|
|
zConfFile = pkgs.writeTextFile {
|
|
|
|
name = "zeronet.conf";
|
2019-03-23 17:57:41 +01:00
|
|
|
|
2018-08-31 12:40:23 +02:00
|
|
|
text = ''
|
|
|
|
[global]
|
|
|
|
data_dir = ${cfg.dataDir}
|
|
|
|
log_dir = ${cfg.logDir}
|
|
|
|
'' + lib.optionalString (cfg.port != null) ''
|
|
|
|
ui_port = ${toString cfg.port}
|
2019-03-23 17:57:41 +01:00
|
|
|
'' + lib.optionalString (cfg.fileserverPort != null) ''
|
|
|
|
fileserver_port = ${toString cfg.fileserverPort}
|
2018-09-08 19:12:11 +02:00
|
|
|
'' + lib.optionalString (cfg.torAlways) ''
|
|
|
|
tor = always
|
2018-08-31 12:40:23 +02:00
|
|
|
'' + cfg.extraConfig;
|
|
|
|
};
|
|
|
|
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.";
|
|
|
|
};
|
|
|
|
|
|
|
|
logDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/log/zeronet";
|
|
|
|
example = "/home/okina/zeronet/log";
|
|
|
|
description = "Path to the zeronet log directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
2018-09-08 19:12:11 +02:00
|
|
|
example = 43110;
|
|
|
|
description = "Optional zeronet web UI port.";
|
2018-08-31 12:40:23 +02:00
|
|
|
};
|
|
|
|
|
2019-03-23 17:57:41 +01:00
|
|
|
fileserverPort = mkOption {
|
|
|
|
# Not optional: when absent zeronet tries to write one to the
|
|
|
|
# read-only config file and crashes
|
|
|
|
type = types.int;
|
|
|
|
default = 12261;
|
|
|
|
example = 12261;
|
|
|
|
description = "Zeronet fileserver port.";
|
|
|
|
};
|
|
|
|
|
2018-08-31 12:40:23 +02:00
|
|
|
tor = mkOption {
|
2018-09-08 19:12:11 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Use TOR for zeronet traffic where possible.";
|
|
|
|
};
|
|
|
|
|
|
|
|
torAlways = mkOption {
|
2018-08-31 12:40:23 +02:00
|
|
|
type = types.bool;
|
|
|
|
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;
|
2018-09-08 19:12:11 +02:00
|
|
|
extraConfig = ''
|
|
|
|
CacheDirectoryGroupReadable 1
|
|
|
|
CookieAuthentication 1
|
|
|
|
CookieAuthFileGroupReadable 1
|
|
|
|
'';
|
2018-08-31 12:40:23 +02:00
|
|
|
};
|
2018-09-08 19:12:11 +02:00
|
|
|
|
2019-02-24 13:39:53 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 750 zeronet zeronet - -"
|
|
|
|
"d '${cfg.logDir}' 750 zeronet zeronet - -"
|
|
|
|
];
|
|
|
|
|
2018-08-31 12:40:23 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ chiiruno ];
|
|
|
|
}
|