-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
144 lines (144 loc) · 5.25 KB
/
flake.nix
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{
description = "Library for home-manager flakes";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
alejandra = {
url = "github:kamadorueda/alejandra";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = flakeInputs @ {
self,
home-manager,
...
}:
with builtins; let
std = flakeInputs.nixpkgs.lib;
utils = import ./src/utils.nix {inherit (flakeInputs) nixpkgs;};
in {
inputs = flakeInputs;
formatter = std.mapAttrs (system: pkgs: pkgs.default) flakeInputs.alejandra.packages;
templates = {
home = {
path = ./templates/home;
description = "A simple home-manager flake using signal modules";
};
sys = {
path = ./templates/sys;
description = "A simple NixOS configuration flake using signal modules";
};
};
lib = {
enum = import ./src/enum.nix flakeInputs;
fs = import ./src/fs.nix flakeInputs;
home = import ./src/home.nix flakeInputs;
list = import ./src/list.nix flakeInputs;
meta = import ./src/meta.nix flakeInputs;
monad = import ./src/monad.nix flakeInputs;
set = import ./src/set.nix flakeInputs;
signal = import ./src/signal.nix flakeInputs;
sys = import ./src/sys.nix flakeInputs;
inherit utils;
option = import ./src/option.nix flakeInputs;
mkDefaultEnableOption = name: (std.mkEnableOption name) // {default = true;};
genNixpkgsForList = {
nixpkgs,
overlays,
systems,
}:
self.lib.genNixpkgsForFn {
inherit nixpkgs systems;
overlayFn = system: overlays;
};
genNixpkgsForFn = {
nixpkgs,
overlayFn,
systems,
allowUnfree,
}:
std.genAttrs systems (system:
import nixpkgs {
config.allowUnfree = allowUnfree;
localSystem = builtins.currentSystem or system;
crossSystem = system;
overlays = overlayFn system;
});
genNixpkgsFor = inputs @ {
nixpkgs,
overlays ? [],
systems ? self.lib.home.systems,
}:
if isList overlays
then self.lib.genNixpkgsForList {inherit nixpkgs overlays systems;}
else
self.lib.genNixpkgsForFn {
inherit nixpkgs systems;
overlayFn = overlays;
};
resolveDependencies = {
inputs,
filter ? [],
resolveFn ? (incumbent: challenger:
if incumbent.lastModified >= challenger.lastModified
then incumbent
else challenger),
}:
foldl' (acc: inputName: let
input = inputs.${inputName};
in
acc
// (std.mapAttrs (dName: dep:
if acc ? ${dName}
then resolveFn acc.${dName} dep
else dep)
(input.dependencies or {}))) (removeAttrs inputs (filter ++ ["self"])) (attrNames inputs);
collectSelfAndDepOverlays = flake: overlayNames: self.lib.set.selectFrom (map (flake: flake.overlays or {}) ([flake] ++ (attrValues flake.dependencies))) overlayNames;
zipFlakeOverlays = inputs: zipAttrsWith (name: values: values) (map (input: input.overlays or {}) inputs);
zipLibOverlays = inputs: zipAttrsWith (name: values: concatLists values) (map (input: input.lib.overlays or {}) inputs);
zipOverlays = {
inputs,
libFilter ? ["self"],
flakeFilter ? ["nixpkgs"],
}:
foldl' (acc: inputName: let
input = inputs.${inputName};
inputLibOverlays =
if elem inputName libFilter
then {}
else input.lib.overlays or {};
libOverlays = self.lib.concatAttrs acc inputLibOverlays;
inputFlakeOverlays =
if elem inputName flakeFilter
then {}
else input.overlays or {};
in
self.lib.set.append libOverlays inputFlakeOverlays) {} (attrNames inputs);
mergeOverlays = overlays: (final: prev: foldl' (acc: overlay: acc // (overlay final prev)) {} overlays);
aggregateOverlays = {
inputs,
filter ? ["self"],
}:
foldl' (acc: inputName: let
input = inputs.${inputName};
in
if elem inputName filter
then acc
else (zipAttrsWith (key: values: self.lib.mergeOverlays values) [acc (input.overlays or {})])) {} (attrNames inputs);
collectInputAttrs = top: nxt: inputs:
foldl' (
acc: i:
acc ++ (std.optional (i ? ${top} && i ? ${top}.${nxt}) i.${top}.${nxt})
) []
inputs;
# exportFlakes = { flakes, filter = [ "self" ] }: foldl' () ;
collectInputModules' = self.lib.collectInputAttrs "homeManagerModules";
collectInputModules = self.lib.collectInputModules' "default";
collectInputOverlays' = self.lib.collectInputAttrs "overlays";
collectInputOverlays = self.lib.collectInputOverlays' "default";
};
};
}