-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
40 lines (34 loc) · 1.2 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
{
description = "a small flake that allows adding patches to nixpkgs conditionally";
outputs = { self }: {
patch = nixpkgs: patchSources: let
lib = if nixpkgs ? lib then nixpkgs.lib
else import "${nixpkgs}/lib";
origPkgs = import "${nixpkgs}" { system = "x86_64-linux"; };
collectPatchesFromSource = source:
builtins.map (el: lib.elemAt el 1)
(lib.filter (el: lib.elemAt el 0) (source.patches4nixpkgs nixpkgs));
collectPatches = sources:
lib.concatMap (collectPatchesFromSource)
(lib.filter (source: source ? "patches4nixpkgs") sources);
patches = collectPatches patchSources;
in origPkgs.stdenvNoCC.mkDerivation {
name = "patched-nixpkgs";
src = "${nixpkgs}";
dontBuild = true;
dontFixup = true;
nativeBuildInputs = [ origPkgs.git ];
installPhase = ''
for p in ${origPkgs.lib.concatStringsSep " " patches}; do
echo "applying patch $p"
git apply -p1 "$p"
done
cp -r . $out
'';
};
eval = patchPkgs: let
self = patchPkgs // ((import "${patchPkgs}/flake.nix").outputs { inherit self; });
in
self;
};
}