Skip to content

Commit b2a47a2

Browse files
authored
Problem: flake overlays not re-usable (#1457)
* Problem: flake overlays not re-usable Solution: - cleanup for usage in testground which will reuse this flake and add sth else on top * cleanup
1 parent de34f9e commit b2a47a2

File tree

2 files changed

+68
-62
lines changed

2 files changed

+68
-62
lines changed

flake.nix

+12-62
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@
3131
let
3232
pkgs = import nixpkgs {
3333
inherit system;
34-
overlays = [
35-
(import ./nix/build_overlay.nix)
36-
poetry2nix.overlays.default
37-
gomod2nix.overlays.default
38-
self.overlay
39-
];
34+
overlays = self.overlays.default;
4035
config = { };
4136
};
4237
in
@@ -73,62 +68,17 @@
7368
}
7469
)
7570
) // {
76-
overlay = final: super: {
77-
go = super.go_1_22;
78-
test-env = final.callPackage ./nix/testenv.nix { };
79-
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
80-
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
81-
# reset the ownership and permissions to make the extract result more normal.
82-
make-tarball = drv: final.runCommand "tarball-${drv.name}"
83-
{
84-
nativeBuildInputs = with final.buildPackages; [ gnutar gzip ];
85-
} ''
86-
tar cfv - -C "${drv}" \
87-
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
88-
| gzip -9 > $out
89-
'';
90-
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; };
91-
} // (with final;
92-
let
93-
matrix = lib.cartesianProductOfSets {
94-
network = [ "mainnet" "testnet" ];
95-
pkgtype = [
96-
"nix" # normal nix package
97-
"bundle" # relocatable bundled package
98-
"tarball" # tarball of the bundle, for distribution and checksum
99-
];
71+
overlays.default = [
72+
(import ./nix/build_overlay.nix)
73+
poetry2nix.overlays.default
74+
gomod2nix.overlays.default
75+
(final: super: {
76+
go = super.go_1_22;
77+
test-env = final.callPackage ./nix/testenv.nix { };
78+
cronos-matrix = final.callPackage ./nix/cronos-matrix.nix {
79+
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
10080
};
101-
binaries = builtins.listToAttrs (builtins.map
102-
({ network, pkgtype }: {
103-
name = builtins.concatStringsSep "-" (
104-
[ "cronosd" ] ++
105-
lib.optional (network != "mainnet") network ++
106-
lib.optional (pkgtype != "nix") pkgtype
107-
);
108-
value =
109-
let
110-
cronosd = callPackage ./. {
111-
inherit rev network;
112-
};
113-
bundle =
114-
if stdenv.hostPlatform.isWindows then
115-
bundle-win-exe cronosd
116-
else
117-
bundle-exe cronosd;
118-
in
119-
if pkgtype == "bundle" then
120-
bundle
121-
else if pkgtype == "tarball" then
122-
make-tarball bundle
123-
else
124-
cronosd;
125-
})
126-
matrix
127-
);
128-
in
129-
{
130-
cronos-matrix = binaries;
131-
}
132-
);
81+
})
82+
];
13383
};
13484
}

nix/cronos-matrix.nix

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{ lib
2+
, stdenv
3+
, callPackage
4+
, buildPackages
5+
, runCommand
6+
, bundle-exe
7+
, rev ? "dirty"
8+
}:
9+
let
10+
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
11+
# reset the ownership and permissions to make the extract result more normal.
12+
make-tarball = drv: runCommand "tarball-${drv.name}"
13+
{
14+
nativeBuildInputs = with buildPackages; [ gnutar gzip ];
15+
} ''
16+
tar cfv - -C "${drv}" \
17+
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
18+
| gzip -9 > $out
19+
'';
20+
bundle-win-exe = drv: callPackage ./bundle-win-exe.nix { cronosd = drv; };
21+
matrix = lib.cartesianProductOfSets {
22+
network = [ "mainnet" "testnet" ];
23+
pkgtype = [
24+
"nix" # normal nix package
25+
"bundle" # relocatable bundled package
26+
"tarball" # tarball of the bundle, for distribution and checksum
27+
];
28+
};
29+
in
30+
builtins.listToAttrs (builtins.map
31+
({ network, pkgtype }: {
32+
name = builtins.concatStringsSep "-" (
33+
[ "cronosd" ] ++
34+
lib.optional (network != "mainnet") network ++
35+
lib.optional (pkgtype != "nix") pkgtype
36+
);
37+
value =
38+
let
39+
cronosd = callPackage ../. {
40+
inherit rev network;
41+
};
42+
bundle =
43+
if stdenv.hostPlatform.isWindows then
44+
bundle-win-exe cronosd
45+
else
46+
bundle-exe cronosd;
47+
in
48+
if pkgtype == "bundle" then
49+
bundle
50+
else if pkgtype == "tarball" then
51+
make-tarball bundle
52+
else
53+
cronosd;
54+
})
55+
matrix
56+
)

0 commit comments

Comments
 (0)