summaryrefslogtreecommitdiff
path: root/lib/lib.nix
blob: 5b7ee7de2136332007e2bd6a28acf896539fa845 (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
{
  lib,
  self,
  inputs,
  ...
}: let
  wrapBuilderWith = apply: builder: args: builder (apply args);

  wrapBuilder = type:
    wrapBuilderWith ({
        modules ? [],
        specialArgs ? {},
        ...
      } @ args:
        args
        // {
          modules =
            modules
            ++ lib.attrValues (self."${type}Modules" or {});

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

  wrapNixOS = wrapBuilder "nixos";
  wrapDarwin = wrapBuilder "darwin";

  wrapUser = wrapBuilderWith ({
      modules ? [],
      extraSpecialArgs ? {},
      ...
    } @ args:
      args
      // {
        modules =
          modules
          ++ lib.attrValues (self.homeManagerModules or {});

        extraSpecialArgs = extraSpecialArgs // {inherit inputs;};
      });
in {
  nixosSystem = wrapNixOS inputs.nixpkgs.lib.nixosSystem;
  nixosSystemStable = wrapNixOS inputs.nixpkgs-stable.lib.nixosSystem;
  darwinSystem = wrapDarwin inputs.nix-darwin.lib.darwinSystem;
  homeManagerConfiguration = wrapUser inputs.home-manager.lib.homeManagerConfiguration;

  nginx = import ./nginx.nix lib;
}