mirror of
https://github.com/buckley310/nixos-config.git
synced 2024-12-21 19:24:15 +00:00
merge morph metadata into system configurations
This commit is contained in:
parent
37d4634ee0
commit
acf460ec7a
2 changed files with 20 additions and 12 deletions
|
@ -5,13 +5,6 @@
|
||||||
, extraMorphModules ? [ ]
|
, extraMorphModules ? [ ]
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
allHostsMeta = builtins.mapAttrs
|
|
||||||
(n: v: import (path + "/${n}"))
|
|
||||||
nixosConfigurations;
|
|
||||||
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
morph-entrypoint = system:
|
morph-entrypoint = system:
|
||||||
let
|
let
|
||||||
|
@ -29,7 +22,7 @@ in
|
||||||
getConfig = name: value: { ... }: {
|
getConfig = name: value: { ... }: {
|
||||||
imports = extraMorphModules ++ nixosConfigurations.${name}.extraArgs.modules;
|
imports = extraMorphModules ++ nixosConfigurations.${name}.extraArgs.modules;
|
||||||
config = nixpkgs.lib.mkMerge [
|
config = nixpkgs.lib.mkMerge [
|
||||||
{ inherit (allHostsMeta.${name}) deployment; }
|
{ inherit (value.config.sconfig.morph) deployment; }
|
||||||
{ deployment.healthChecks = globalHealthChecks; }
|
{ deployment.healthChecks = globalHealthChecks; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -53,7 +46,7 @@ in
|
||||||
|
|
||||||
sshKnownHostsTxt = pkgs.writeText "known_hosts" (concatMapStrings
|
sshKnownHostsTxt = pkgs.writeText "known_hosts" (concatMapStrings
|
||||||
(hostName:
|
(hostName:
|
||||||
let m = allHostsMeta.${hostName};
|
let m = nixosConfigurations.${hostName}.config.sconfig.morph;
|
||||||
in concatMapStrings (key: "${m.deployment.targetHost} ${key}\n") m.sshPublicKeys
|
in concatMapStrings (key: "${m.deployment.targetHost} ${key}\n") m.sshPublicKeys
|
||||||
)
|
)
|
||||||
(builtins.attrNames nixosConfigurations)
|
(builtins.attrNames nixosConfigurations)
|
||||||
|
@ -91,9 +84,7 @@ in
|
||||||
'';
|
'';
|
||||||
|
|
||||||
ssh = sh ''
|
ssh = sh ''
|
||||||
[ -n "$1" ] || die "Specify a host"
|
ip="$(nix eval --raw --file ./. "nixosConfigurations.\"$1\".config.sconfig.morph.deployment.targetHost")"
|
||||||
[ -d "${path}/$1" ] || die "Invalid host"
|
|
||||||
ip="$(nix eval --raw --file "${path}/$1" deployment.targetHost)"
|
|
||||||
shift
|
shift
|
||||||
exec ssh -F"${sshConfig}" "$ip" "$@"
|
exec ssh -F"${sshConfig}" "$ip" "$@"
|
||||||
'';
|
'';
|
||||||
|
|
17
modules/morph.nix
Normal file
17
modules/morph.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
with lib.types;
|
||||||
|
{
|
||||||
|
options.sconfig.morph = {
|
||||||
|
|
||||||
|
sshPublicKeys = lib.mkOption {
|
||||||
|
type = listOf str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
|
||||||
|
deployment = lib.mkOption {
|
||||||
|
type = attrs;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue