From 8afbacd6542b5f6ba4532a274fb50001e227deba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20BRAMI?= Date: Sat, 27 Aug 2022 00:42:09 +0200 Subject: [PATCH] build: reduce nix cache miss. Each pkgs.buildGoModule create a .go-modules sub derivation that is equivalent to the vendor directory (aka it is copied to vendor). Before we have a cache miss because this sub derivation has another name but it is the same (comapared with nix-diff) here we rename this sub derivation to hit the network only once. before: $ nix build .#all --dry-run these 15 derivations will be built: /nix/store/64z5ixzsfd536jkybap6364wlkm4s8jn-admin-202208232340-go-modules.drv /nix/store/hjj8dv97h00y5wfvw4xk0ax4745473zl-frontend-202208232340-go-modules.drv /nix/store/xrx1b6hnvq13qkijqrbw7jsbr3gf5fn8-dashboard-202208232340-go-modules.drv /nix/store/kv0spqnh3il0lgimg7gk40cxh5gspvkp-dashboard-202208232340.drv /nix/store/mpa6f97mrvfq7nd0vrwgsq9z2k3hhzgw-scores-sync-zqds-202208232340-go-modules.drv /nix/store/nl1p2k58rdazvjhpifc76948x5bjwr0f-repochecker-202208232340-go-modules.drv /nix/store/pc290pk0rxhm2vrrbn78f92r3k7mmhzx-backend-202208232340-go-modules.drv /nix/store/p5v7ghgndp78gx7g653kdw4yasyxnlad-backend-202208232340.drv /nix/store/sj3vv4sxva1rkrxrb6k7p66vq1b5nlgq-qa-202208232340-go-modules.drv /nix/store/q3f00kq76iq453awbihgh30r8j9np7g0-qa-202208232340.drv /nix/store/q6zcphpyqlk5yc9r0z9c4lbayvr1rnm6-scores-sync-zqds-202208232340.drv /nix/store/r4bq4b8g0pjn3k0r9wh70divbm9m7m3v-frontend-202208232340.drv /nix/store/wffyj2nbgzi0qmv6iqx0kn0hzzm41i61-repochecker-202208232340.drv /nix/store/yfisx4c6zhqcqyflbj064s0p60930v82-admin-202208232340.drv /nix/store/vk06zp9q2hs6149n363hmk8azfhxr683-fic-all.drv this path will be fetched (0.01 MiB download, 0.04 MiB unpacked): /nix/store/7cifvbmgjm5y9ds5a7c6c861g1xcm1qr-stdenv-linux after: $ nix build .#all --dry-run these 9 derivations will be built: /nix/store/826caq9p8rphffwyrvcpxgrs6p3xla13-fic-.-.-202208232340-go-modules.drv /nix/store/29gr8z8zm1qxd3hg4nfj5zpz39w5239j-qa-202208232340.drv /nix/store/2clvljkrlpfxfrlb4cyk68n8zq5xg3m4-dashboard-202208232340.drv /nix/store/5nz6izdjhsklq354m1fdssbadr2fnpkk-repochecker-202208232340.drv /nix/store/95pzd7y6n99v4dn4xyfi677kmdq536qg-frontend-202208232340.drv /nix/store/i79s2fkj5g75729lg76b2i126m7q36w9-scores-sync-zqds-202208232340.drv /nix/store/q1v7hq02hmqn4nql5rcyiwf6grlrdc4q-admin-202208232340.drv /nix/store/vkid4pr7r6w3glfhfyfg5malp501jkaf-backend-202208232340.drv /nix/store/f94c2m5fq6il03f97lyswcwg15s3c50w-fic-all.drv this path will be fetched (0.01 MiB download, 0.04 MiB unpacked): /nix/store/7cifvbmgjm5y9ds5a7c6c861g1xcm1qr-stdenv-linux --- flake.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 22995b56..4726eecf 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,7 @@ # Generate a version based on date version = builtins.substring 0 12 self.lastModifiedDate; vendorSha256 = "sha256-n271oFjC13gelSNV1bZdr/KH724ewoOF1NZ6U7il56I="; + overrideModAttrs = _ : { name = "fic-./.-${version}-go-modules"; }; # System types to support. supportedSystems = @@ -33,7 +34,7 @@ in { fic-admin = pkgs.buildGoModule { pname = "admin"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "admin" ]; @@ -41,7 +42,7 @@ fic-backend = pkgs.buildGoModule { pname = "backend"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "backend" ]; @@ -49,7 +50,7 @@ fic-dashboard = pkgs.buildGoModule { pname = "dashboard"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "dashboard" ]; @@ -57,7 +58,7 @@ fic-frontend = pkgs.buildGoModule { pname = "frontend"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "frontend" ]; @@ -65,7 +66,7 @@ fic-qa = pkgs.buildGoModule { pname = "qa"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "qa" ]; @@ -73,7 +74,7 @@ fic-remote-scores-sync-zqds = pkgs.buildGoModule { pname = "scores-sync-zqds"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "remote/scores-sync-zqds" ]; @@ -81,7 +82,7 @@ fic-repochecker = pkgs.buildGoModule { pname = "repochecker"; - inherit version vendorSha256; + inherit version vendorSha256 overrideModAttrs; src = ./.; subPackages = [ "repochecker" ];