summaryrefslogtreecommitdiffstats
path: root/lib/default.nix
blob: a5f3e1727469e8de8f1ee2678558cfbd7a331c58 (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
{ sources ? import ../npins
, pkgs ? import sources.nixpkgs {}
}:
let
  inherit (pkgs) lib;

  eval = configuration:
    let
      self =
        lib.evalModules {
          modules = [
            configuration
            {
              options = {
                machines = lib.mkOption {
                  type = lib.types.attrsOf lib.types.raw;
                  default = {};
                };
                outputs = lib.mkOption {
                  type = lib.types.attrsOf lib.types.raw;
                  default = {};
                };
              };
              config = {
                outputs.machines = lib.mapAttrs (name: configuration:
                  nixos configuration
                ) self.config.machines;
              };
            }
          ];
          specialArgs.self = self;
        };
      
      # nixos = config: lib.evalModules {
      #   modules = [
      #     config
      #     {
      #       # XXX Otherwise building manual fails
      #       documentation.enable = false;

      #       boot.loader.grub.device = "nodev";
      #       fileSystems."/".device = "tmpfs";
      #       nixpkgs.localSystem = "x86_64-linux";
      #     }
      #   ];
      #   specialArgs.self = self;
      # };

      nixos = config: import (sources.nixpkgs + "/nixos/lib/eval-config.nix") {
        modules = [
          config
          {
            # XXX Otherwise building manual fails
            documentation.enable = false;

            boot.loader.grub.device = "nodev";
            fileSystems."/".device = "tmpfs";
            nixpkgs.localSystem = {
              system = "x86_64-linux";
            };
          }
        ];
        specialArgs.self = self;

        # The system is inherited from the current pkgs above.
        # Set it to null, to remove the "legacy" entrypoint's non-hermetic default.
        system = null;
      };
    in
    self;

in
{
  inherit eval;
}