infra/ci.nix

40 lines
1.7 KiB
Nix
Raw Normal View History

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,
...
}: 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.
inherit hostname drv;
effectScript = ''
2022-08-13 10:48:09 +02:00
writeSSHKey ssh ~/.ssh/id_ed25519
cat >>~/.ssh/known_hosts <<EOF
build01.nix-community.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIElIQ54qAy7Dh63rBudYKdbzJHrrbrrMXLYl7Pkmk88H
build02.nix-community.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMm3/o1HguyRL1z/nZxLBY9j/YUNXeNuDoiBLZAyt88Z
build03.nix-community.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFiozp1A1+SUfJQPa5DZUQcVc6CZK2ZxL6FJtNdh+2TP
build04.nix-community.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPU/gbREwVuI1p3ag1iG72jxl2/92yGl38c+TPOfFMH8
EOF
2022-08-13 10:28:24 +02:00
${pkgs.openssh}/bin/ssh -i deploy-key root@"$hostname" "\$(nix-store -r $drv)/bin/switch-to-configuration switch"
2022-08-13 09:15:38 +02:00
'';
});
2020-04-18 00:12:32 +02:00
in
2022-08-13 09:15:38 +02:00
(nixpkgs.lib.mapAttrs' (name: config: nixpkgs.lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel) self.outputs.nixosConfigurations) // {
build01 = deployNixOS {
hostname = "build01.nix-community.org";
# using the drv path here avoids downloading the closure on the deploying machine
2022-08-13 10:08:40 +02:00
drv = builtins.unsafeDiscardStringContext self.outputs.nixosConfigurations.nix-community-build01.config.system.build.toplevel.drvPath;
2022-08-13 09:15:38 +02:00
};
}