Summary Files Commits Branches @commit @diff @stats
path: root / autoconfig.nix
blob: 74424f13579599d8d8507344c4093a1ad7481394 (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
{ self, inputs, ... }:
let
  inherit (inputs) nixpkgs;
  inherit (nixpkgs) lib;
  _mergeAttrs =
    let
      recurse = attrset:
        lib.zipAttrsWith
        (name: values:
          if builtins.isAttrs (builtins.head values) then
            recurse (builtins.filter (val: builtins.isAttrs val) values)
          else if builtins.isList (builtins.head values) then
            lib.concatLists (builtins.filter (val: builtins.isList val) values)
          else
            lib.last values
        )
        attrset;
    in
      recurse;
in {
  configurations =
    lib.mapAttrs
    (dir: _:
      let
        inherit (import ./machines/${dir}/sysidentity.nix) sysidentity;
      in lib.nixosSystem {
        system = sysidentity.arch;
        modules = [
          ./machines/${dir}/hardware-configuration.nix
          ./configuration.nix
          self.packages
        ];
      })
    (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./machines));

  packages =
    let
      package-groups = import ./packages/default.nix { inherit nixpkgs; };
    in
      lib.foldlAttrs
      (config: _: package-group:
        let
          config-from-group =
            lib.foldlAttrs
            (acc: pkg-name: pkg-settings:
              if pkg-name == "list" then
                _mergeAttrs [
                  acc
                  {
                    environment.systemPackages = pkg-settings;
                  }]
              else
                _mergeAttrs [
                  acc
                  (lib.filterAttrs (name: _: name != "ref") pkg-settings)
                  {
                    environment.systemPackages = [pkg-settings.ref];
                  }])
            {}
            package-group;
          in
            _mergeAttrs [config config-from-group])
      {}
      package-groups; # TODO: filter on machine type
}