From 1b55d9f4628a7ae44796accc6320444ddf714274 Mon Sep 17 00:00:00 2001 From: huangyi Date: Thu, 23 May 2024 15:00:41 +0800 Subject: [PATCH 1/2] Problem: flake overlays not re-usable Solution: - cleanup for usage in testground which will reuse this flake and add sth else on top --- flake.nix | 74 +++++++------------------------------------ nix/cronos-matrix.nix | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 62 deletions(-) create mode 100644 nix/cronos-matrix.nix diff --git a/flake.nix b/flake.nix index 36fc0bfe97..5fea04c927 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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; - } - ); + }) + ]; }; } diff --git a/nix/cronos-matrix.nix b/nix/cronos-matrix.nix new file mode 100644 index 0000000000..d8a585716e --- /dev/null +++ b/nix/cronos-matrix.nix @@ -0,0 +1,58 @@ +{ lib +, stdenv +, callPackage +, pkgsBuildBuild +, buildPackages +, runCommand +, rev ? "dirty" +, bundle-exe +}: +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 + ]; + }; + 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 +binaries From 37a7fdc92853f5a7c61638c84c021360ad0aca1e Mon Sep 17 00:00:00 2001 From: huangyi Date: Thu, 23 May 2024 15:02:58 +0800 Subject: [PATCH 2/2] cleanup --- nix/cronos-matrix.nix | 58 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/nix/cronos-matrix.nix b/nix/cronos-matrix.nix index d8a585716e..e6016121bb 100644 --- a/nix/cronos-matrix.nix +++ b/nix/cronos-matrix.nix @@ -1,11 +1,10 @@ { lib , stdenv , callPackage -, pkgsBuildBuild , buildPackages , runCommand -, rev ? "dirty" , bundle-exe +, rev ? "dirty" }: let # make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references. @@ -27,32 +26,31 @@ let "tarball" # tarball of the bundle, for distribution and checksum ]; }; - 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 -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 +)