summaryrefslogtreecommitdiffstats
path: root/hosts/default.nix
blob: 4f5d29823b23611c1007c7b4378b4dcdcc80289b (plain) (blame)
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
50
{
  self,
  extra_lib,
  module_args,
  special_args,
  nixpkgs-stable,
  nixpkgs-unstable,
  deploy-rs,
  system,
}: let
  hosts = extra_lib.mkByName {
    useShards = false;
    baseDirectory = ./by-name;
    fileName = "configuration.nix";
  };

  mkNixosConfiguration = name: path: let
    host_file = builtins.fromTOML (builtins.readFile (path + "/../host.toml"));
    nixpkgs =
      if host_file.nixpkgs == "stable"
      then nixpkgs-stable
      else nixpkgs-unstable;
  in
    nixpkgs.lib.nixosSystem {
      specialArgs = special_args;
      modules = [
        {
          _module.args = module_args;
        }
        path

        ../modules
        # ../modules/common
      ];
    };
  mkDeployHost = name: path: let
    host_file = builtins.fromTOML (builtins.readFile path + "/host.toml");
  in {
    inherit (host_file) hostname;
    profiles.system = {
      user = "root";
      path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations."${name}";
    };
  };

  nixosConfigurations = builtins.mapAttrs mkNixosConfiguration hosts;
  nodes = builtins.mapAttrs mkDeployHost hosts;
in {
  inherit nixosConfigurations nodes;
}