summaryrefslogtreecommitdiff
path: root/parts/deploy.nix
blob: bebf25cb9b71f934e6d92bdc4442d1426ce3cf2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{
  self,
  inputs,
  lib,
  withSystem,
  ...
}: let
  systems = ["atlas" "p-body"];

  deployedSystems =
    lib.filterAttrs
    (n: _: builtins.elem n systems)
    self.nixosConfigurations;

  deployPkgs = import inputs.nixpkgs rec {
    system = "x86_64-linux";
    overlays = [
      inputs.deploy-rs.overlay
      (_: prev: {
        deploy-rs = {
          inherit (withSystem system (p: p.pkgs)) deploy-rs;
          inherit (prev.deploy-rs) lib;
        };
      })
    ];
  };

  mkNodes = hosts: let
    inherit (builtins) attrNames listToAttrs map;
    vals =
      map (name: let
        system = self.nixosConfigurations.${name};
      in {
        inherit name;
        value = {
          sshUser = "root";
          hostname = system.config.networking.hostName;
          profiles.system.path = deployPkgs.deploy-rs.lib.activate.nixos system;
        };
      })
      (attrNames hosts);
  in
    listToAttrs vals;
in {
  flake.deploy = {
    remoteBuild = true;
    nodes = mkNodes deployedSystems;
  };
}