From acf460ec7a094a2945144fefd670473b20a169cb Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Thu, 28 Oct 2021 15:51:41 -0400 Subject: [PATCH] merge morph metadata into system configurations --- lib/morph.nix | 15 +++------------ modules/morph.nix | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 modules/morph.nix diff --git a/lib/morph.nix b/lib/morph.nix index 7349c2b..b24ce37 100644 --- a/lib/morph.nix +++ b/lib/morph.nix @@ -5,13 +5,6 @@ , extraMorphModules ? [ ] }: -let - - allHostsMeta = builtins.mapAttrs - (n: v: import (path + "/${n}")) - nixosConfigurations; - -in { morph-entrypoint = system: let @@ -29,7 +22,7 @@ in getConfig = name: value: { ... }: { imports = extraMorphModules ++ nixosConfigurations.${name}.extraArgs.modules; config = nixpkgs.lib.mkMerge [ - { inherit (allHostsMeta.${name}) deployment; } + { inherit (value.config.sconfig.morph) deployment; } { deployment.healthChecks = globalHealthChecks; } ]; }; @@ -53,7 +46,7 @@ in sshKnownHostsTxt = pkgs.writeText "known_hosts" (concatMapStrings (hostName: - let m = allHostsMeta.${hostName}; + let m = nixosConfigurations.${hostName}.config.sconfig.morph; in concatMapStrings (key: "${m.deployment.targetHost} ${key}\n") m.sshPublicKeys ) (builtins.attrNames nixosConfigurations) @@ -91,9 +84,7 @@ in ''; ssh = sh '' - [ -n "$1" ] || die "Specify a host" - [ -d "${path}/$1" ] || die "Invalid host" - ip="$(nix eval --raw --file "${path}/$1" deployment.targetHost)" + ip="$(nix eval --raw --file ./. "nixosConfigurations.\"$1\".config.sconfig.morph.deployment.targetHost")" shift exec ssh -F"${sshConfig}" "$ip" "$@" ''; diff --git a/modules/morph.nix b/modules/morph.nix new file mode 100644 index 0000000..2bd2dd7 --- /dev/null +++ b/modules/morph.nix @@ -0,0 +1,17 @@ +{ lib, ... }: +with lib.types; +{ + options.sconfig.morph = { + + sshPublicKeys = lib.mkOption { + type = listOf str; + default = [ ]; + }; + + deployment = lib.mkOption { + type = attrs; + default = { }; + }; + + }; +}