summaryrefslogtreecommitdiff
path: root/lib/builders.nix
blob: 6669c2d463b7cb54089dd71c98e8723cf74dad12 (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
{
  lib,
  inputs,
  self,
}:
let
  # function -> function -> { } -> { }
  # wrap the `args` applied to `builder` with the result of `apply`
  # applied to those `args`
  wrapBuilderWith =
    apply: builder: args:
    builder (apply args);

  # string -> function -> { } -> { }
  # wrap the `args` for `builder` of type `type` with nice defaults
  wrapBuilder =
    type:
    wrapBuilderWith (
      {
        modules ? [ ],
        specialArgs ? { },
        ...
      }@args:
      args
      // {
        modules = modules ++ lib.attrValues (self."${type}Modules" or { });

        specialArgs = specialArgs // {
          inherit inputs;
        };
      }
    );

  # function -> { } -> { }
  # wrap the `args` to the nixos `builder` function with nice defaults
  wrapNixOS = builder: args: wrapBuilder "nixos" builder args;
  # function -> { } -> { }
  # wrap the `args` to the darwin `builder` function with nice defaults
  wrapDarwin = builder: args: wrapBuilder "darwin" builder args;

  # function -> { } -> { }
  # wrap the `args` to the homeManager `builder` function with nice defaults
  wrapUser =
    builder: args:
    wrapBuilderWith (
      {
        modules ? [ ],
        extraSpecialArgs ? { },
        ...
      }@args:
      args
      // {
        modules = modules ++ lib.attrValues (self.homeManagerModules or { });

        extraSpecialArgs = extraSpecialArgs // {
          inherit inputs;
        };
      }
    ) builder args;
in
{

  # { } -> { }
  # apply nice defaults to the `args` of `nixosSystem`
  nixosSystem = wrapNixOS inputs.nixpkgs.lib.nixosSystem;
  # { } -> { }
  # apply nice defaults to the `args` of (stable) `nixosSystem`
  nixosSystemStable = wrapNixOS inputs.nixpkgs-stable.lib.nixosSystem;
  # { } -> { }
  # apply nice defaults to the `args` of `darwinSystem`
  darwinSystem = wrapDarwin inputs.nix-darwin.lib.darwinSystem;
  # { } -> { }
  # apply nice defaults to the `args` of `homeManagerConfiguration`
  homeManagerConfiguration = wrapUser inputs.home-manager.lib.homeManagerConfiguration;
}