Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
168 lines (156 loc) · 5.89 KB
/
Copy pathflake.nix
File metadata and controls
168 lines (156 loc) · 5.89 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
{
description = "Single packages take a detour from your nixpkgs (held back while broken, or ahead from an open nixpkgs PR) until nixpkgs catches up";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Consumers make this follow their own nixpkgs-stable.
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-26.05";
};
outputs =
inputs@{
self,
nixpkgs,
nixpkgs-stable,
}:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = f: lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
in
{
lib = {
# holds: held-packages.json (a path) or an attrset; nixpkgs-stable: for `from = "stable"`.
# extraOverlays: your own overlays, so your own packages can be held too.
# config: nixpkgs config for the held sets; default: carried over from yours.
mkHolds =
{
holds,
nixpkgs-stable ? inputs.nixpkgs-stable,
extraOverlays ? [ ],
config ? null,
}:
let
entries = if builtins.isAttrs holds then holds else lib.importJSON holds;
heldIn =
pkgs:
builtins.filter (name: lib.hasAttrByPath (lib.splitString "." name) pkgs) (
builtins.attrNames entries
);
overlay = import ./overlay.nix {
inherit nixpkgs-stable extraOverlays config;
holds = entries;
root = if builtins.isAttrs holds then null else dirOf holds;
};
in
{
inherit overlay;
# NixOS tests of the held packages (`tests`, default nixosTests.<name>):
# the module is from the current nixpkgs and the package from its hold,
# so a mismatch only shows at runtime. Run them with your own overlays.
nixosTests =
pkgs:
let
testsOf = name: entries.${name}.tests or (lib.optional (pkgs.nixosTests ? ${name}) name);
in
lib.genAttrs (lib.unique (lib.concatMap testsOf (heldIn pkgs))) (test: pkgs.nixosTests.${test});
# Per hold, its `releaseWhen` (default: the package) from a set without
# the holds; the hold can go once this builds on the newest nixpkgs.
# `nixHolds` carries the entry, so the tools read the holds in use.
# `nixHoldsPackage` is the package without its hold, `nixHoldsHeld`
# with it: the CLI records the first on the last working nixpkgs
# (`worked`) and checks that the second still is that build.
releaseChecks =
pkgs:
let
heldPkgs = pkgs.extend overlay;
in
lib.genAttrs (heldIn pkgs) (
name:
let
entry = entries.${name};
path = lib.splitString "." (entry.releaseWhen or name);
pkg = lib.attrByPath path null pkgs;
versionSatisfied =
if entry ? untilVersion && pkg != null && pkg ? version then
builtins.compareVersions pkg.version entry.untilVersion >= 0
else
true;
in
(if pkg != null && versionSatisfied then pkg else { })
// {
nixHolds = entry;
nixHoldsPackage = lib.getAttrFromPath (lib.splitString "." name) pkgs;
nixHoldsHeld = lib.getAttrFromPath (lib.splitString "." name) heldPkgs;
}
);
};
# Packages from open nixpkgs PRs of one consumer (see prs.nix).
# prs: its nixpkgs-prs.json (a path) or the same as an attrset
mkPrs = { prs }: import ./prs.nix { inherit lib prs; };
# What the update action checks (see watch.nix): lib.watch.nixos
# nixosSystem, or lib.watch.packages { pkgs, packages }.
watch = import ./watch.nix { inherit lib; };
};
packages = forAllSystems (
pkgs:
let
nix-detour = pkgs.callPackage ./package.nix { };
in
{
default = nix-detour;
inherit nix-detour;
web = pkgs.runCommand "nix-detour-web-${nix-detour.version}" { } ''
ln -s ${nix-detour}/share/nix-detour/web $out
'';
web-server =
pkgs.runCommand "nix-detour-web-server-${nix-detour.version}"
{
meta.mainProgram = "nix-detour-web-server";
}
''
mkdir -p $out/bin
ln -s ${nix-detour}/libexec/nix-detour/web-server $out/bin/nix-detour-web-server
'';
}
);
apps = forAllSystems (pkgs: {
default = {
type = "app";
program = lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.nix-detour;
meta.description = "The nix-detour CLI";
};
web = {
type = "app";
program = toString (
pkgs.writeShellScript "nix-detour-web" ''
exec ${lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.nix-detour} web "$@"
''
);
meta.description = "Run the nix-detour web dashboard";
};
});
checks = forAllSystems (
pkgs:
let
inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) nix-detour;
in
(import ./tests {
inherit
pkgs
nixpkgs
nixpkgs-stable
nix-detour
;
inherit (self.lib) mkHolds watch;
mkPrs = args: import ./prs.nix ({ inherit lib; } // args);
})
// {
package-smoke = nix-detour.passthru.tests.cli;
}
);
formatter = forAllSystems (pkgs: pkgs.nixfmt-tree);
};
}