-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathflake.nix
More file actions
224 lines (202 loc) · 6.79 KB
/
flake.nix
File metadata and controls
224 lines (202 loc) · 6.79 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{
description = "Home Manager for Nix";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{
self,
nixpkgs,
...
}:
{
nixosModules = rec {
home-manager = ./nixos;
default = home-manager;
};
darwinModules = rec {
home-manager = ./nix-darwin;
default = home-manager;
};
flakeModules = rec {
home-manager = ./flake-module.nix;
default = home-manager;
};
templates = {
default = self.templates.standalone;
nixos = {
path = ./templates/nixos;
description = "Home Manager as a NixOS module,";
};
nix-darwin = {
path = ./templates/nix-darwin;
description = "Home Manager as a nix-darwin module,";
};
standalone = {
path = ./templates/standalone;
description = "Standalone setup";
};
};
lib = import ./lib { inherit (nixpkgs) lib; };
}
// (
let
forAllPkgs =
f:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
forCI = nixpkgs.lib.genAttrs [
"aarch64-darwin"
"x86_64-linux"
];
testChunks =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
# Create chunked test packages for better CI parallelization
tests = import ./tests {
inherit pkgs;
# Disable big tests since this is only used for CI
enableBig = false;
};
allTests = lib.attrNames tests.build;
# Remove 'all' from the test list as it's a meta-package
filteredTests = lib.filter (name: name != "all") allTests;
# NOTE: Just a starting value, we can tweak this to find a good value.
targetTestsPerChunk = 50;
numChunks = lib.max 1 (
builtins.ceil ((builtins.length filteredTests) / (targetTestsPerChunk * 1.0))
);
chunkSize = builtins.ceil ((builtins.length filteredTests) / (numChunks * 1.0));
makeChunk =
chunkNum: testList:
let
start = (chunkNum - 1) * chunkSize;
end = lib.min (start + chunkSize) (builtins.length testList);
chunkTests = lib.sublist start (end - start) testList;
chunkAttrs = lib.genAttrs chunkTests (name: tests.build.${name});
in
pkgs.symlinkJoin {
name = "test-chunk-${toString chunkNum}";
paths = lib.attrValues chunkAttrs;
passthru.tests = chunkTests;
};
in
lib.listToAttrs (
lib.genList (
i: lib.nameValuePair "test-chunk-${toString (i + 1)}" (makeChunk (i + 1) filteredTests)
) numChunks
);
integrationTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
in
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux (
let
tests = import ./tests/integration { inherit pkgs lib; };
renameTestPkg = n: v: lib.nameValuePair "integration-${n}" v;
in
lib.mapAttrs' renameTestPkg (lib.removeAttrs tests [ "all" ])
);
buildTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests { inherit pkgs; };
renameTestPkg = n: nixpkgs.lib.nameValuePair "test-${n}";
in
nixpkgs.lib.mapAttrs' renameTestPkg tests.build;
buildTestsNoBig =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests {
inherit pkgs;
enableBig = false;
};
in
{
test-all-enableBig-false-enableLegacyIfd-false = tests.build.all;
};
buildTestsNoBigIfd =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests {
inherit pkgs;
enableBig = false;
enableLegacyIfd = true;
};
in
{
test-all-enableBig-false-enableLegacyIfd-true = tests.build.all;
};
integrationTestPackages =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
tests = import ./tests/integration { inherit pkgs lib; };
renameTestPkg = n: lib.nameValuePair "integration-test-${n}";
in
lib.mapAttrs' renameTestPkg tests;
in
{
formatter = forAllPkgs (pkgs: pkgs.callPackage ./home-manager/formatter.nix { });
# TODO: increase buildbot testing scope
buildbot = forCI (
system:
let
allIntegrationTests = integrationTests system;
workingIntegrationTests = nixpkgs.lib.filterAttrs (
name: _:
nixpkgs.lib.elem name [
"integration-nixos-basics"
"integration-nixos-legacy-profile-management"
]
) allIntegrationTests;
in
(testChunks system) // workingIntegrationTests
);
packages = forAllPkgs (
pkgs:
let
releaseInfo = nixpkgs.lib.importJSON ./release.json;
docs = import ./docs {
inherit pkgs;
inherit (releaseInfo) release isReleaseBranch;
};
hmPkg = pkgs.callPackage ./home-manager { path = "${self}"; };
in
{
default = hmPkg;
home-manager = hmPkg;
create-news-entry = pkgs.writeShellScriptBin "create-news-entry" ''
./modules/misc/news/create-news-entry.sh
'';
tests = pkgs.callPackage ./tests/package.nix { flake = self; };
docs-html = docs.manual.html;
docs-htmlOpenTool = docs.manual.htmlOpenTool;
docs-json = docs.options.json;
docs-jsonModuleMaintainers = docs.jsonModuleMaintainers;
docs-manpages = docs.manPages;
}
);
devShells = forAllPkgs (pkgs: {
default = pkgs.callPackage ./home-manager/devShell.nix { };
});
legacyPackages = forAllPkgs (
pkgs:
let
system = pkgs.stdenv.hostPlatform.system;
in
(buildTests system)
// (integrationTestPackages system)
// (buildTestsNoBig system)
// (buildTestsNoBigIfd system)
// (testChunks system)
// (integrationTests system)
);
}
);
}