2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
101 lines
2.9 KiB
Nix
101 lines
2.9 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
inherit (lib) generators literalExpression mkEnableOption mkIf mkOption recursiveUpdate types;
|
|
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 = {
|
|
enable = mkEnableOption "zeronet";
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.zeronet;
|
|
defaultText = literalExpression "pkgs.zeronet";
|
|
description = lib.mdDoc "ZeroNet package to use";
|
|
};
|
|
|
|
settings = mkOption {
|
|
type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
|
|
default = {};
|
|
example = literalExpression "{ global.tor = enable; }";
|
|
|
|
description = lib.mdDoc ''
|
|
{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;
|
|
'';
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 43110;
|
|
description = lib.mdDoc "Optional zeronet web UI port.";
|
|
};
|
|
|
|
fileserverPort = mkOption {
|
|
# Not optional: when absent zeronet tries to write one to the
|
|
# read-only config file and crashes
|
|
type = types.port;
|
|
default = 12261;
|
|
description = lib.mdDoc "Zeronet fileserver port.";
|
|
};
|
|
|
|
tor = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc "Use TOR for zeronet traffic where possible.";
|
|
};
|
|
|
|
torAlways = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc "Use TOR for all zeronet traffic.";
|
|
};
|
|
};
|
|
|
|
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";
|
|
after = [ "network.target" ] ++ optional cfg.tor "tor.service";
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
User = "zeronet";
|
|
DynamicUser = true;
|
|
StateDirectory = "zeronet";
|
|
SupplementaryGroups = mkIf cfg.tor [ "tor" ];
|
|
ExecStart = "${cfg.package}/bin/zeronet --config_file ${configFile}";
|
|
};
|
|
};
|
|
};
|
|
|
|
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")
|
|
];
|
|
|
|
meta.maintainers = with maintainers; [ Madouura ];
|
|
}
|