Skip to content

Commit

Permalink
nix: drop dependency to ihp source to reduce derivation size
Browse files Browse the repository at this point in the history
Until now the IHP build did depend on the full ihp source code instead of Makefile.dist and ihp static files. Now we only depend on the specific files, reducing the overall derivation size. This should speed up deployments by a bit.
  • Loading branch information
mpscholten committed Nov 17, 2024
1 parent d1613e6 commit d93f07e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 19 additions & 12 deletions NixSupport/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ let
(otherDeps pkgs)
];

ihpLibWithMakefile = filter { root = ihp; include = ["lib/IHP/Makefile.dist"]; name = "ihpLibWithMakefile"; };
ihpLibWithMakefileAndStatic = filter { root = ihp; include = ["lib/IHP/Makefile.dist" "lib/IHP/static"]; name = "ihpLibWithMakefileAndStatic"; };

schemaObjectFiles =
let
self = projectPath;
Expand All @@ -33,18 +36,19 @@ let
mkdir -p build/Generated
build-generated-code
export IHP=${ihp}/lib/IHP
export IHP=${ihpLibWithMakefile}/lib/IHP
ghc -O${if optimized then optimizationLevel else "0"} $(make print-ghc-options) --make build/Generated/Types.hs -odir build/RunProdServer -hidir build/RunProdServer
cp -r build $out
'';
src = filter { root = self; include = ["Application/Schema.sql" "Makefile"]; };
src = filter { root = self; include = ["Application/Schema.sql" "Makefile"]; name = "schemaObjectFiles-source"; };
nativeBuildInputs =
[ (ghc.ghcWithPackages (p: [ p.ihp-ide ])) # Needed for build-generated-code
]
;
dontInstall = true;
dontFixup = false;
disallowedReferences = [ ihp ]; # Prevent including the large full IHP source code
};

prodGhcOptions = "-funbox-strict-fields -fconstraint-solver-iterations=100 -fdicts-strict -with-rtsopts=\"${rtsFlags}\"";
Expand All @@ -59,8 +63,8 @@ let
chmod -R +w build/RunProdServer/*
export IHP_LIB=${ihp}/lib/IHP
export IHP=${ihp}/lib/IHP
export IHP_LIB=${ihpLibWithMakefile}/lib/IHP
export IHP=${ihpLibWithMakefile}/lib/IHP
mkdir -p build/bin build/RunUnoptimizedProdServer
Expand Down Expand Up @@ -114,10 +118,11 @@ let
done
'';
dontFixup = true;
src = filter { root = pkgs.nix-gitignore.gitignoreSource [] projectPath; include = [filter.isDirectory "Makefile" (filter.matchExt "hs")]; exclude = ["static" "Frontend"]; };
src = filter { root = pkgs.nix-gitignore.gitignoreSource [] projectPath; include = [filter.isDirectory "Makefile" (filter.matchExt "hs")]; exclude = ["static" "Frontend"]; name = "${appName}-source"; };
buildInputs = [allHaskellPackages];
nativeBuildInputs = [ pkgs.makeWrapper ];
nativeBuildInputs = [ pkgs.makeWrapper schemaObjectFiles];
enableParallelBuilding = true;
disallowedReferences = [ ihp ]; # Prevent including the large full IHP source code
};
in
pkgs.stdenv.mkDerivation {
Expand All @@ -134,8 +139,8 @@ in
# See https://github.com/svanderburg/node2nix/issues/217#issuecomment-751311272
export HOME=/tmp
export IHP_LIB=${ihp}/lib/IHP
export IHP=${ihp}/lib/IHP
export IHP_LIB=${ihpLibWithMakefileAndStatic}/lib/IHP
export IHP=${ihpLibWithMakefileAndStatic}/lib/IHP
make -j static/app.css static/app.js
Expand All @@ -148,11 +153,11 @@ in
mkdir -p $out/bin $out/lib
INPUT_HASH="$((basename $out) | cut -d - -f 1)"
makeWrapper ${binaries}/bin/RunProdServer $out/bin/RunProdServer --set-default IHP_ASSET_VERSION $INPUT_HASH --set-default IHP_LIB ${ihp}/lib/IHP --run "cd $out/lib" --prefix PATH : ${pkgs.lib.makeBinPath (otherDeps pkgs)}
makeWrapper ${binaries}/bin/RunProdServer $out/bin/RunProdServer --set-default IHP_ASSET_VERSION $INPUT_HASH --set-default IHP_LIB ${ihpLibWithMakefileAndStatic}/lib/IHP --run "cd $out/lib" --prefix PATH : ${pkgs.lib.makeBinPath (otherDeps pkgs)}
# Copy job runner binary to bin/ if we built it
if [ -f ${binaries}/bin/RunJobs ]; then
makeWrapper ${binaries}/bin/RunJobs $out/bin/RunJobs --set-default IHP_ASSET_VERSION $INPUT_HASH --set-default IHP_LIB ${ihp}/lib/IHP --run "cd $out/lib" --prefix PATH : ${pkgs.lib.makeBinPath (otherDeps pkgs)}
makeWrapper ${binaries}/bin/RunJobs $out/bin/RunJobs --set-default IHP_ASSET_VERSION $INPUT_HASH --set-default IHP_LIB ${ihpLibWithMakefileAndStatic}/lib/IHP --run "cd $out/lib" --prefix PATH : ${pkgs.lib.makeBinPath (otherDeps pkgs)}
fi;
# Copy other binaries, excluding RunProdServer and RunJobs
Expand All @@ -168,13 +173,15 @@ in
'';
dontFixup = true;
src = pkgs.nix-gitignore.gitignoreSource [] projectPath;
buildInputs = builtins.concatLists [ [allHaskellPackages] allNativePackages ];
buildInputs = builtins.concatLists [ allNativePackages ];
nativeBuildInputs = builtins.concatLists [
[ pkgs.makeWrapper
pkgs.cacert # Needed for npm install to work from within the IHP build process
pkgs.cacert # Needed for npm install to work from within the IHP build process
[allHaskellPackages]
]
];
shellHook = "eval $(egrep ^export ${allHaskellPackages}/bin/ghc)";
enableParallelBuilding = true;
impureEnvVars = pkgs.lib.fetchers.proxyImpureEnvVars; # Needed for npm install to work from within the IHP build process
disallowedReferences = [ ihp ]; # Prevent including the large full IHP source code
}
2 changes: 2 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ ihpFlake:
name = "ihp-schema";
src = ihp;
phases = [ "unpackPhase" "installPhase" ];
nativeBuildInputs = [ihp.ihp-ide];
installPhase = ''
mkdir $out
cp ${ihp.ihp-ide}/lib/IHP/IHPSchema.sql $out/
'';
allowedReferences = [];
};


Expand Down

0 comments on commit d93f07e

Please sign in to comment.