2020-04-18 00:12:32 +02:00
|
|
|
# Add derivations to be built from the cache to this file
|
2021-12-23 21:15:46 +01:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, src ? { ref = null; }
|
|
|
|
}:
|
2020-04-18 00:12:32 +02:00
|
|
|
let
|
2022-04-10 22:29:46 +02:00
|
|
|
self = builtins.getFlake (toString ./.);
|
|
|
|
nixpkgs = self.inputs.nixpkgs;
|
2022-08-13 10:28:24 +02:00
|
|
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
2022-04-10 22:29:46 +02:00
|
|
|
effects = self.inputs.hercules-ci-effects.lib.withPkgs nixpkgs.legacyPackages.x86_64-linux;
|
2022-08-13 09:15:38 +02:00
|
|
|
|
|
|
|
deployNixOS = args@{
|
|
|
|
hostname,
|
|
|
|
drv,
|
2022-08-13 11:13:06 +02:00
|
|
|
knownHosts,
|
2022-08-13 09:15:38 +02:00
|
|
|
...
|
|
|
|
}: effects.mkEffect (args // {
|
2022-08-13 10:48:09 +02:00
|
|
|
secretsMap.ssh = "default-ssh";
|
2022-08-13 09:15:38 +02:00
|
|
|
# This style of variable passing allows overrideAttrs and modification in
|
|
|
|
# hooks like the userSetupScript.
|
2022-08-13 11:13:06 +02:00
|
|
|
inherit hostname drv knownHosts;
|
2022-08-13 09:15:38 +02:00
|
|
|
effectScript = ''
|
2022-08-13 11:13:06 +02:00
|
|
|
export PATH=$PATH:${pkgs.openssh}/bin
|
2022-08-13 10:48:09 +02:00
|
|
|
writeSSHKey ssh ~/.ssh/id_ed25519
|
2022-08-13 11:13:06 +02:00
|
|
|
echo "$knownHosts" >>~/.ssh/known_hosts
|
2022-08-13 11:18:33 +02:00
|
|
|
ssh root@"$hostname" "\$(nix-store -r $drv)/bin/switch-to-configuration switch"
|
2022-08-13 09:15:38 +02:00
|
|
|
'';
|
|
|
|
});
|
2022-08-13 11:13:06 +02:00
|
|
|
deployNixOS' = name: config: nixpkgs.lib.nameValuePair "deploy-${name}" (deployNixOS {
|
|
|
|
hostname = config.config.networking.fqdn;
|
|
|
|
knownHosts = config.config.environment.etc."ssh/ssh_known_hosts".text;
|
|
|
|
drv = builtins.unsafeDiscardStringContext config.config.system.build.toplevel.drvPath;
|
|
|
|
});
|
2020-04-18 00:12:32 +02:00
|
|
|
in
|
2022-08-13 11:13:06 +02:00
|
|
|
(nixpkgs.lib.mapAttrs' (name: config: nixpkgs.lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel) self.outputs.nixosConfigurations) //
|
|
|
|
(nixpkgs.lib.mapAttrs' deployNixOS' self.outputs.nixosConfigurations)
|