From dd0865de4176ce1d5e34268e13fe95142d1a37f2 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 22 Sep 2024 16:34:51 +0200 Subject: [PATCH] fix(ds-fr): Update the way we construct the derivation We no longer copy all of the node_modules, but instead use bun's cache, which reduces the size of the deps --- machines/compute01/ds-fr/package/default.nix | 68 ++++++++++++-------- machines/compute01/ds-fr/package/meta.nix | 2 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/machines/compute01/ds-fr/package/default.nix b/machines/compute01/ds-fr/package/default.nix index 482d863..0303674 100644 --- a/machines/compute01/ds-fr/package/default.nix +++ b/machines/compute01/ds-fr/package/default.nix @@ -1,6 +1,7 @@ { lib, stdenv, + stdenvNoCC, fetchFromGitHub, git, bun, @@ -48,36 +49,42 @@ let }; }; - node_modules = stdenv.mkDerivation { - pname = "${pname}-node_modules"; - inherit src version; - - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ - "GIT_PROXY_COMMAND" - "SOCKS_SERVER" - ]; + bunOfflineCache = stdenvNoCC.mkDerivation { + name = "${pname}-bun-deps"; + inherit src; nativeBuildInputs = [ bun ]; - dontConfigure = true; + configurePhase = '' + runHook preConfigure + + mkdir .home + export HOME="$(pwd)/.home" + + runHook postConfigure + ''; buildPhase = '' - bun install --no-progress --frozen-lockfile --ignore-scripts - rm -r node_modules/.cache + runHook preBuild - # Remove inconsistent file - rm node_modules/.bin/grunt + bun install --no-progress --frozen-lockfile --ignore-scripts + + runHook postBuild ''; installPhase = '' - mv node_modules $out + runHook preInstall + + mv $HOME $out + + runHook postInstall ''; dontFixup = true; - outputHash = meta.deps-hash or lib.fakeHash; outputHashAlgo = "sha256"; outputHashMode = "recursive"; + outputHash = meta.deps-hash; }; dsModules = stdenv.mkDerivation { @@ -91,9 +98,6 @@ let rubyEnv.wrappedRuby ]; - RAILS_ENV = "production"; - NODE_ENV = "dev"; - patches = [ # Disable functionnalities as we only precompile assets ./patches/build.patch @@ -103,17 +107,27 @@ let ${getExe git} apply -p1 < ${builtins.fetchurl "https://git.dgnum.eu/DGNum/demarches-normaliennes/commit/${dgn-id}.patch"} ''; - OTP_SECRET_KEY = "precompile_placeholder"; - SECRET_KEY_BASE = "precompile_placeholder"; - APP_HOST = "precompile_placeholder"; + env = { + RAILS_ENV = "production"; + NODE_ENV = "dev"; + + OTP_SECRET_KEY = "precompile_placeholder"; + SECRET_KEY_BASE = "precompile_placeholder"; + APP_HOST = "precompile_placeholder"; + HOME = bunOfflineCache; + }; + + configurePhase = '' + runHook preConfigure + + bun install --no-progress --frozen-lockfile --ignore-scripts + patchShebangs bin/ + patchShebangs node_modules/ + + runHook postConfigure + ''; buildPhase = '' - cp -R ${node_modules} node_modules - chmod u+w -R node_modules - - patchShebangs node_modules - patchShebangs bin/ - bin/rake assets:precompile ''; diff --git a/machines/compute01/ds-fr/package/meta.nix b/machines/compute01/ds-fr/package/meta.nix index 0adbbec..81a79f8 100644 --- a/machines/compute01/ds-fr/package/meta.nix +++ b/machines/compute01/ds-fr/package/meta.nix @@ -1,5 +1,5 @@ { version = "2024-04-24-01"; src-hash = "sha256-+FjthJZb1KqqFttFmXr/FN5qaFcY9RGTKAqhdLGVFSg="; - deps-hash = "sha256-Vj8WCB+LSHJM67qbsZ5CPc+jK1KWO1MXnSFp/LH0Ow8="; + deps-hash = "sha256-EOvlzBYRtZnGQ4KU0k3/rgZzk/JnJzfF7bi8CmpY4V8="; } -- 2.47.0