Summary Files Commits Branches @commit @diff @stats
path: root / autoconfig.nix
blob: 7434a79ee915a02875c1c6cb99c35ee58eb363fd (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{ inputs, ... }:
let
  inherit (inputs) nixpkgs;
  inherit (nixpkgs) lib;
in {
  configurations =
    lib.mapAttrs
    (dir: _:
      let
        inherit (import ./machines/${dir}/sysidentity.nix) sysidentity;

        package-modules =
          let
            listget = attrname:
              if sysidentity ? ${attrname}
              then map
                    (v: ./modules + ("/" + v + (if lib.hasSuffix ".nix" v then "" else ".nix")))
                    sysidentity.${attrname}
              else [];
            droplist = listget "drop";
            startsempty = (sysidentity ? defaultempty) && sysidentity.defaultempty;
            # When we start empty, we expect to have many packages in "have"
            # but when we don't start empty, we expect to have many packages in "modelist"
            # So it makes more sense to make droplist remove items from the "many packages"
            # list, instead of only one of the two, or both
            havelist = if startsempty then listget "have" else [];
            modulelist =
              if startsempty
              then listget "have"
              else lib.mapAttrsToList
                    (name: _: ./modules + ("/" + name))
                    (lib.filterAttrs (_: type: type == "regular") (builtins.readDir ./modules));
          in
            (lib.subtractLists droplist modulelist) ++ havelist;

        inputs-overlays =
          lib.mapAttrs
          (_: nixpkgs-special:
            nixpkgs-special.legacyPackages.${sysidentity.arch})
          (lib.filterAttrs
            (name: _:
              lib.hasPrefix "nixpkgs-" name)
            inputs);

        custom-packages-overlays =
          lib.mapAttrs
          (name: _:
            nixpkgs.legacyPackages.${sysidentity.arch}.callPackage ./packages/${name} { })
          (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./packages));

        package-overlays =
          lib.mapAttrsToList
          (name: _: (import ./overlays/${name}))
          (builtins.readDir ./overlays);

      in
      lib.nixosSystem {
        system = sysidentity.arch;
        modules = [
          ./machines/${dir}/hardware-configuration.nix
          ./configuration.nix
          ({ ... }: {
            networking.hostName = sysidentity.name;
            nixpkgs.overlays = [ (_: _: inputs-overlays) (_: _: custom-packages-overlays) ] ++ package-overlays;
          })
        ]
        ++ (if lib.pathIsRegularFile ./machines/${dir}/configuration.nix
            then [ ./machines/${dir}/configuration.nix ]
            else [])
        ++ package-modules;
      })
    (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./machines));
}