aboutsummaryrefslogtreecommitdiff
path: root/lib/nix-furnace/mkSystem.nix
blob: 856655af507ad87b55d05d5feb20928ada2d3374 (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
let
  my-lib = import ../lib.nix;
  inherit (my-lib.globimport) getSubdirs lazyImport;

  hosts = (builtins.fromTOML (builtins.readFile ../../hosts.toml)).hosts;

  listModules = getSubdirs ../../modules;

  nixosModules = hostname:
    [
      ../../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);

  hjemModules = hostname:
    [
      ../../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);

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

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

        # Nixos-sided modules
        {imports = nixosModules hostname;}

        # Hjem-sided modules
        {
          imports = [
            inputs.hjem.nixosModules.hjem
          ];
          hjem = {
            extraModules = hjemModules hostname;
            specialArgs = {inherit inputs my-lib hosts;};
            users.${username} = {
              enable = true;
              user = username;
              directory = "/home/${username}";
            };
          };
        }
      ];
    };

  genDocs = {
    lib,
    pkgs,
    inputs,
    hostname,
    ...
  }: let
    eval = lib.evalModules {
      modules = listModules |> (builtins.map (m: (lazyImport ../../modules/${m}/options.nix)));
      specialArgs = {
        inherit my-lib pkgs;
      };
      check = false;
    };

    optionsDoc = pkgs.nixosOptionsDoc {
      inherit (eval) options;
    };
  in
    pkgs.runCommand "options-doc.md" {
      buildInputs = [pkgs.pandoc];
    } ''
      mkdir -p $out
      cat ${optionsDoc.optionsCommonMark} | pandoc -t html -o - | tee $out/index.html
    '';
in {
  inherit mkNixosSystem genDocs;
}