Skip to content

Commit

Permalink
Problem: flake overlays not re-usable (#1457)
Browse files Browse the repository at this point in the history
* Problem: flake overlays not re-usable

Solution:
- cleanup for usage in testground which will reuse this flake and add
  sth else on top

* cleanup
  • Loading branch information
yihuang authored May 23, 2024
1 parent de34f9e commit b2a47a2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 62 deletions.
74 changes: 12 additions & 62 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./nix/build_overlay.nix)
poetry2nix.overlays.default
gomod2nix.overlays.default
self.overlay
];
overlays = self.overlays.default;
config = { };
};
in
Expand Down Expand Up @@ -73,62 +68,17 @@
}
)
) // {
overlay = final: super: {
go = super.go_1_22;
test-env = final.callPackage ./nix/testenv.nix { };
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: final.runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with final.buildPackages; [ gnutar gzip ];
} ''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; };
} // (with final;
let
matrix = lib.cartesianProductOfSets {
network = [ "mainnet" "testnet" ];
pkgtype = [
"nix" # normal nix package
"bundle" # relocatable bundled package
"tarball" # tarball of the bundle, for distribution and checksum
];
overlays.default = [
(import ./nix/build_overlay.nix)
poetry2nix.overlays.default
gomod2nix.overlays.default
(final: super: {
go = super.go_1_22;
test-env = final.callPackage ./nix/testenv.nix { };
cronos-matrix = final.callPackage ./nix/cronos-matrix.nix {
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
};
binaries = builtins.listToAttrs (builtins.map
({ network, pkgtype }: {
name = builtins.concatStringsSep "-" (
[ "cronosd" ] ++
lib.optional (network != "mainnet") network ++
lib.optional (pkgtype != "nix") pkgtype
);
value =
let
cronosd = callPackage ./. {
inherit rev network;
};
bundle =
if stdenv.hostPlatform.isWindows then
bundle-win-exe cronosd
else
bundle-exe cronosd;
in
if pkgtype == "bundle" then
bundle
else if pkgtype == "tarball" then
make-tarball bundle
else
cronosd;
})
matrix
);
in
{
cronos-matrix = binaries;
}
);
})
];
};
}
56 changes: 56 additions & 0 deletions nix/cronos-matrix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ lib
, stdenv
, callPackage
, buildPackages
, runCommand
, bundle-exe
, rev ? "dirty"
}:
let
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with buildPackages; [ gnutar gzip ];
} ''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: callPackage ./bundle-win-exe.nix { cronosd = drv; };
matrix = lib.cartesianProductOfSets {
network = [ "mainnet" "testnet" ];
pkgtype = [
"nix" # normal nix package
"bundle" # relocatable bundled package
"tarball" # tarball of the bundle, for distribution and checksum
];
};
in
builtins.listToAttrs (builtins.map
({ network, pkgtype }: {
name = builtins.concatStringsSep "-" (
[ "cronosd" ] ++
lib.optional (network != "mainnet") network ++
lib.optional (pkgtype != "nix") pkgtype
);
value =
let
cronosd = callPackage ../. {
inherit rev network;
};
bundle =
if stdenv.hostPlatform.isWindows then
bundle-win-exe cronosd
else
bundle-exe cronosd;
in
if pkgtype == "bundle" then
bundle
else if pkgtype == "tarball" then
make-tarball bundle
else
cronosd;
})
matrix
)

0 comments on commit b2a47a2

Please sign in to comment.