aboutsummaryrefslogtreecommitdiff
path: root/lib/nix-furnace/mkSystem.nix
blob: 3285f3a50d305aa7fddebf27309d7ef174361142 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
let
  my-lib = import ../lib.nix;
  inherit (my-lib.globimport) getSubdirs lazyImport;

  listModules = getSubdirs ../../modules;

  mkNixosSystem = {
    inputs,
    hostname,
    username,
    module_types,
  }:
    inputs.nixpkgs.lib.nixosSystem {
      specialArgs = {inherit inputs my-lib;};
      modules = [
        {networking.hostName = hostname;}

        ../../hosts/${hostname}/config.nix

        # Nixos-sided modules
        {
          imports =
            [
              ../../modules/options.nix
              ../../hosts/${hostname}/config.nix
              (lazyImport ../../hosts/${hostname}/nixos.nix)
            ]
            ++ (listModules
              |> (builtins.map (modName: [
                (lazyImport ../../modules/${modName}/options.nix)
                (lazyImport ../../modules/${modName}/nixos/default.nix)
              ]))
              |> my-lib.flatten);
        }

        # Home-sided modules
        (
          if (builtins.elem "home" module_types)
          then {
            imports = [
              inputs.home-manager.nixosModules.home-manager
            ];
            home-manager = {
              backupFileExtension = "bak";
              useGlobalPkgs = true;
              useUserPackages = true;
              extraSpecialArgs = {inherit inputs my-lib;};
              users.${username} = {
                imports =
                  [
                    ../../modules/options.nix
                    ../../hosts/${hostname}/config.nix
                    (lazyImport ../../hosts/${hostname}/home.nix)
                    {
                      home.preferXdgDirectories = true;
                    }
                  ]
                  ++ (listModules
                    |> (builtins.map (modName: [
                      (lazyImport ../../modules/${modName}/options.nix)
                      (lazyImport ../../modules/${modName}/home/default.nix)
                    ]))
                    |> my-lib.flatten);
              };
            };
          }
          else {}
        )

        # Hjem-sided modules
        (
          if (builtins.elem "hjem" module_types)
          then {
            imports = [
              inputs.hjem.nixosModules.hjem
            ];
            hjem = {
              extraModules =
                [
                  ../../modules/options.nix
                  ../../hosts/${hostname}/config.nix
                  (lazyImport ../../hosts/${hostname}/hjem.nix)
                ]
                ++ (listModules
                  |> (builtins.map (modName: [
                    (lazyImport ../../modules/${modName}/options.nix)
                    (lazyImport ../../modules/${modName}/hjem/default.nix)
                  ]))
                  |> my-lib.flatten);
              specialArgs = {inherit inputs my-lib;};
              users.${username} = {
                enable = true;
                user = username;
                directory = "/home/${username}";
              };
            };
          }
          else {}
        )

        # This is where we would add nix-on-droid modules
      ];
    };
in
  mkNixosSystem