0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 14:10:33 +03:00

nixos/ncdns: Replace custom config format handling with pkgs.formats.toml

This commit is contained in:
nicoo 2024-05-26 18:17:02 +00:00
parent 7a2e88f7c1
commit adaee656c2

View file

@ -6,23 +6,7 @@ let
dataDir = "/var/lib/ncdns";
username = "ncdns";
valueType = with lib.types; oneOf [ int str bool path ]
// { description = "setting type (integer, string, bool or path)"; };
configType = with lib.types; attrsOf (nullOr (either valueType configType))
// { description = ''
ncdns.conf configuration type. The format consists of an
attribute set of settings. Each setting can be either `null`,
a value or an attribute set. The allowed values are integers,
strings, booleans or paths.
'';
};
configFile = pkgs.runCommand "ncdns.conf"
{ json = builtins.toJSON cfg.settings;
passAsFile = [ "json" ];
}
"${pkgs.remarshal}/bin/json2toml < $jsonPath > $out";
format = pkgs.formats.toml {};
defaultFiles = {
public = "${dataDir}/bit.key";
@ -160,7 +144,7 @@ in
};
settings = lib.mkOption {
type = configType;
type = format.type;
default = { };
example = lib.literalExpression ''
{ # enable webserver
@ -257,7 +241,7 @@ in
User = "ncdns";
StateDirectory = "ncdns";
Restart = "on-failure";
ExecStart = "${pkgs.ncdns}/bin/ncdns -conf=${configFile}";
ExecStart = "${pkgs.ncdns}/bin/ncdns -conf=${format.generate "ncdns.conf" cfg.settings}";
};
preStart = lib.optionalString (cfg.dnssec.enable && needsKeygen) ''