diff --git a/nixos/modules/services/networking/yggdrasil.nix b/nixos/modules/services/networking/yggdrasil.nix index 7a0b5b4d3d4c..81ed6d1dd566 100644 --- a/nixos/modules/services/networking/yggdrasil.nix +++ b/nixos/modules/services/networking/yggdrasil.nix @@ -4,16 +4,23 @@ let keysPath = "/var/lib/yggdrasil/keys.json"; cfg = config.services.yggdrasil; - configProvided = cfg.config != { }; + settingsProvided = cfg.settings != { }; configFileProvided = cfg.configFile != null; + format = pkgs.formats.json { }; in { + imports = [ + (mkRenamedOptionModule + [ "services" "yggdrasil" "config" ] + [ "services" "yggdrasil" "settings" ]) + ]; + options = with types; { services.yggdrasil = { enable = mkEnableOption "the yggdrasil system service"; - config = mkOption { - type = attrs; + settings = mkOption { + type = format.type; default = {}; example = { Peers = [ @@ -138,11 +145,11 @@ in { wantedBy = [ "multi-user.target" ]; preStart = - (if configProvided || configFileProvided || cfg.persistentKeys then + (if settingsProvided || configFileProvided || cfg.persistentKeys then "echo " - + (lib.optionalString configProvided - "'${builtins.toJSON cfg.config}'") + + (lib.optionalString settingsProvided + "'${builtins.toJSON cfg.settings}'") + (lib.optionalString configFileProvided "$(cat ${cfg.configFile})") + (lib.optionalString cfg.persistentKeys "$(cat ${keysPath})") + " | ${pkgs.jq}/bin/jq -s add | ${binYggdrasil} -normaliseconf -useconf" diff --git a/nixos/tests/yggdrasil.nix b/nixos/tests/yggdrasil.nix index b409d9ed7853..b60a0e6b06cc 100644 --- a/nixos/tests/yggdrasil.nix +++ b/nixos/tests/yggdrasil.nix @@ -42,7 +42,7 @@ in import ./make-test-python.nix ({ pkgs, ...} : { services.yggdrasil = { enable = true; - config = { + settings = { Listen = ["tcp://0.0.0.0:12345"]; MulticastInterfaces = [ ]; }; @@ -112,7 +112,7 @@ in import ./make-test-python.nix ({ pkgs, ...} : { services.yggdrasil = { enable = true; denyDhcpcdInterfaces = [ "ygg0" ]; - config = { + settings = { IfTAPMode = true; IfName = "ygg0"; MulticastInterfaces = [ "eth1" ];