hosts.nix 1.9 KB
Newer Older
1
2
# This file does some magic in order to use the handy deploy command defined in ./default.nix
{ pkgs ? import ../../pkgs { /* TODO system */} }:
Matthias Adamczyk's avatar
Matthias Adamczyk committed
3
4
5
6

with pkgs.lib;

rec {
7
  hostsDir = ../../hosts;
Matthias Adamczyk's avatar
Matthias Adamczyk committed
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

  hostNames = attrNames (
    filterAttrs (
      name: type: type == "directory"
    ) (
      builtins.readDir hostsDir
    )
  );

  # HACK: We want to choose a nixpkgs version depending on the host architecture, but
  # the host architecture is set in the NixOS config. We accept the limitation that
  # nixpkgs.system must be set in the main configuration.nix file to prevent reading
  # the host configuration twice.
  hostArch = hostName:
    (
      (
        import (hostsDir + "/${hostName}/configuration.nix") {
          inherit (pkgs) pkgs lib;
          config = {};
          modulesPath = "";
        }
      ).nixpkgs or {}
    ).system or "x86_64-linux"
  ;

33
  nixpkgsFor = hostName: (import ../../pkgs {
Matthias Adamczyk's avatar
Matthias Adamczyk committed
34
35
36
37
38
39
40
41
42
    system = hostArch hostName;
  }).path;

  hostConfig = hostName: { config, ... }: {
    _module.args = {
      inherit hosts groups;
    };
    imports = [
      (import (hostsDir + "/${hostName}/configuration.nix"))
43
      ../../modules
Matthias Adamczyk's avatar
Matthias Adamczyk committed
44
45
46
47
    ];
    networking = {
      inherit hostName;
    };
48
    nixpkgs.pkgs = import ../../pkgs {
Matthias Adamczyk's avatar
Matthias Adamczyk committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
      inherit (config.nixpkgs) config system;
    };
  };

  hosts = listToAttrs (
    map (
      hostName: nameValuePair hostName (
        import ((nixpkgsFor hostName) + "/nixos") {
          configuration = hostConfig hostName;
          system = hostArch hostName;
        }
      )
    ) hostNames
  );

  groupNames = unique (
    concatLists (
      mapAttrsToList (
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
67
        name: host: host.config.finf.deploy.groups
Matthias Adamczyk's avatar
Matthias Adamczyk committed
68
69
70
71
72
73
74
75
      ) hosts
    )
  );

  groups = listToAttrs (
    map (
      groupName: nameValuePair groupName (
        filter (
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
76
          host: elem groupName host.config.finf.deploy.groups
Matthias Adamczyk's avatar
Matthias Adamczyk committed
77
78
79
80
81
82
83
        ) (
          attrValues hosts
        )
      )
    ) groupNames
  );
}