Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: flake overlays not re-usable #1457

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
Comment on lines +21 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The matrix defines combinations of network (mainnet, testnet) and pkgtype (nix, bundle, tarball). However, the current definitions in flake.nix only show packages.cronosd, packages.cronosd-testnet, and apps.cronosd. This indicates that not all combinations are represented.

  • packages.cronosd (mainnet, nix)
  • packages.cronosd-testnet (testnet, nix)
  • apps.cronosd (mainnet, nix)

The following combinations are missing:

  • mainnet, bundle
  • mainnet, tarball
  • testnet, bundle
  • testnet, tarball

Please ensure that all combinations of network and pkgtype are correctly represented in the package and app definitions in flake.nix.

Analysis chain

The matrix and package generation logic are well-structured. Ensure that all configurations are correctly applied in practice.


To ensure that all configurations in the matrix are correctly applied, we need to verify the usage of matrix in flake.nix. Let's search for the relevant sections in flake.nix and analyze how the configurations are applied.


The matrix configurations are used to define packages and apps in flake.nix. We need to ensure that all combinations of network and pkgtype are correctly represented in these definitions.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all configurations in the matrix are correctly applied.

# Test: Search for the usage of `matrix` configurations. Expect: Correct application in all instances.
rg --type nix $'matrix'

Length of output: 250



Script:

#!/bin/bash
# Description: Verify the usage of `matrix` configurations in `flake.nix`.

# Search for the usage of `matrix` in `flake.nix` and display the relevant sections.
rg --type nix 'matrix' flake.nix -A 10

Length of output: 612



Script:

#!/bin/bash
# Description: Verify the presence of all expected package and app variants in `flake.nix`.

# List all package and app definitions in `flake.nix` to ensure all combinations are represented.
rg --type nix 'packages\.' flake.nix
rg --type nix 'apps\.' flake.nix

Length of output: 263

Loading