From 7ad716b827276c081affdd6b1d25c33760178036 Mon Sep 17 00:00:00 2001 From: kat witch Date: Sat, 7 Aug 2021 03:02:27 +0100 Subject: [PATCH] Deploy target autodefinition overhaul --- config/hosts/dummy/meta.nix | 1 + config/modules/meta/deploy.nix | 14 ++++++++++++-- default.nix | 10 +++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/config/hosts/dummy/meta.nix b/config/hosts/dummy/meta.nix index 64f5ff2c..55e1c22d 100644 --- a/config/hosts/dummy/meta.nix +++ b/config/hosts/dummy/meta.nix @@ -1,4 +1,5 @@ { lib, config, ... }: with lib; { + deploy.targets.dummy.enable = false; network.nodes.dummy = { imports = lib.hostImport "dummy"; networking = { diff --git a/config/modules/meta/deploy.nix b/config/modules/meta/deploy.nix index e7dd06db..c49b59ae 100644 --- a/config/modules/meta/deploy.nix +++ b/config/modules/meta/deploy.nix @@ -48,6 +48,7 @@ in { targets = let type = types.submodule ({ config, name, ... }: { options = { + enable = mkEnableOption "Enable the target" // { default = true; }; name = mkOption { type = types.str; default = name; @@ -99,13 +100,22 @@ in { }; }; config = { + deploy.targets = let + nodeNames = attrNames config.network.nodes; + targets = config.deploy.targets; + explicitlyDefinedHosts = concatLists (mapAttrsToList (targetName: target: remove targetName target.nodeNames) config.deploy.targets); + in genAttrs nodeNames ( nodeName: { + enable = mkDefault (! elem nodeName explicitlyDefinedHosts); + nodeNames = singleton nodeName; + }); + runners = { run = mkMerge (mapAttrsToList (targetName: target: mapAttrs' (k: run: nameValuePair run.name run.set - ) target.tf.runners.run) cfg.targets); + ) target.tf.runners.run) (filterAttrs (_: v: v.enable) cfg.targets)); lazy.run = mkMerge (mapAttrsToList (targetName: target: mapAttrs' (k: run: nameValuePair run.name run.set - ) target.tf.runners.lazy.run) cfg.targets); + ) target.tf.runners.lazy.run) (filterAttrs (_: v: v.enable) cfg.targets)); }; }; } diff --git a/default.nix b/default.nix index b47c46a9..c6eb46b4 100644 --- a/default.nix +++ b/default.nix @@ -38,12 +38,12 @@ let # This is where the meta config is evaluated. eval = lib.evalModules { - modules = [ - metaConfig - ./config/modules/meta/default.nix - ] ++ (lib.attrValues hosts) + modules = lib.singleton metaConfig ++ (lib.attrValues (removeAttrs argGen.targets ["common"])) - ++ (lib.optional (builtins.pathExists ./config/trusted/meta.nix) ./config/trusted/meta.nix); + ++ (lib.attrValues hosts) + ++ (lib.optional (builtins.pathExists ./config/trusted/meta.nix) ./config/trusted/meta.nix) + ++ lib.singleton ./config/modules/meta/default.nix; + specialArgs = { inherit sources; inherit (argGen) profiles users services;