infrastructure/machines/compute01/ds-fr/package/default.nix
Tom Hubrecht dd0865de41
Some checks failed
lint / check (push) Successful in 23s
Check meta / check_meta (pull_request) Successful in 18s
Check meta / check_dns (pull_request) Successful in 20s
build configuration / build_storage01 (pull_request) Successful in 1m18s
build configuration / build_web02 (pull_request) Successful in 1m10s
build configuration / build_web01 (pull_request) Successful in 1m42s
build configuration / build_vault01 (pull_request) Successful in 2m9s
build configuration / build_geo01 (pull_request) Successful in 1m12s
build configuration / build_geo02 (pull_request) Successful in 1m7s
lint / check (pull_request) Successful in 24s
build configuration / build_rescue01 (pull_request) Successful in 2m21s
build configuration / build_compute01 (pull_request) Failing after 3m37s
build configuration / push_to_cache_compute01 (pull_request) Has been skipped
build configuration / build_bridge01 (pull_request) Successful in 2m1s
build configuration / push_to_cache_web02 (pull_request) Successful in 1m32s
build configuration / push_to_cache_storage01 (pull_request) Successful in 1m38s
build configuration / push_to_cache_web01 (pull_request) Successful in 1m57s
build configuration / push_to_cache_geo02 (pull_request) Successful in 1m11s
build configuration / push_to_cache_geo01 (pull_request) Successful in 2m9s
build configuration / push_to_cache_rescue01 (pull_request) Successful in 1m16s
build configuration / push_to_cache_bridge01 (pull_request) Successful in 1m12s
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
2024-09-22 16:34:51 +02:00

193 lines
3.9 KiB
Nix

{
lib,
stdenv,
stdenvNoCC,
fetchFromGitHub,
git,
bun,
nodejs,
ruby_3_2,
bundlerEnv,
logDir ? "/var/log/ds-fr",
dataDir ? "/var/lib/ds-fr",
initialDeploymentDate ? "17941030",
}:
let
inherit (lib) getExe;
# Head of the DGNum repo
dgn-id = "f270f1cdd09e643a9c666c94df1841234430de49";
pname = "ds-fr";
meta = import ./meta.nix;
inherit (meta) version;
src = fetchFromGitHub {
owner = "demarches-simplifiees";
repo = "demarches-simplifiees.fr";
rev = version;
hash = meta.src-hash;
};
rubyEnv = bundlerEnv {
name = "env-${pname}";
gemdir = ./rubyEnv;
ruby = ruby_3_2;
gemset = (import ./rubyEnv/gemset.nix) // {
bundler = {
groups = [ "default" ];
platforms = [ ];
source = {
remotes = [ "https://rubygems.org" ];
sha256 = "deeQ3fNwcSiGSO/yeB2yoTniRq2gHW8WueprXoPX6Jk=";
type = "gem";
};
version = "2.3.11";
};
};
};
bunOfflineCache = stdenvNoCC.mkDerivation {
name = "${pname}-bun-deps";
inherit src;
nativeBuildInputs = [ bun ];
configurePhase = ''
runHook preConfigure
mkdir .home
export HOME="$(pwd)/.home"
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
bun install --no-progress --frozen-lockfile --ignore-scripts
runHook postBuild
'';
installPhase = ''
runHook preInstall
mv $HOME $out
runHook postInstall
'';
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = meta.deps-hash;
};
dsModules = stdenv.mkDerivation {
pname = "${pname}-modules";
inherit src version;
buildInputs = [ rubyEnv ];
nativeBuildInputs = [
bun
nodejs
rubyEnv.wrappedRuby
];
patches = [
# Disable functionnalities as we only precompile assets
./patches/build.patch
];
postPatch = ''
${getExe git} apply -p1 < ${builtins.fetchurl "https://git.dgnum.eu/DGNum/demarches-normaliennes/commit/${dgn-id}.patch"}
'';
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 = ''
bin/rake assets:precompile
'';
installPhase = ''
mkdir -p $out/public
cp -r public/* $out/public
'';
};
in
stdenv.mkDerivation {
name = "demarches-simplifiees.fr-${version}";
inherit src;
buildInputs = [ rubyEnv ];
propagatedBuildInputs = [ rubyEnv.wrappedRuby ];
patches = [
./patches/replay_routing_engine_for_a_cloned_procedure.patch
./patches/smtp_settings.patch
./patches/garage.patch
];
postPatch = ''
${getExe git} apply -p1 < ${builtins.fetchurl "https://git.dgnum.eu/DGNum/demarches-normaliennes/commit/${dgn-id}.patch"}
'';
buildPhase = ''
rm -rf public
ln -s ${dsModules}/public/ public
patchShebangs bin/
rm -rf log storage
ln -s ${logDir} log
ln -s ${dataDir}/tmp tmp
ln -s ${dataDir}/storage storage
for f in $(ls lib/tasks/deployment/); do
[[ ! ${initialDeploymentDate} < $f ]] \
&& rm lib/tasks/deployment/$f;
done;
echo "Removed unused data migrations"
'';
installPhase = ''
mkdir -p $out
cp -r * $out/
'';
passthru = {
inherit rubyEnv;
ruby = rubyEnv.wrappedRuby;
};
meta = with lib; {
description = "Dématérialiser et simplifier les démarches administratives";
homepage = "https://github.com/demarches-simplifiees/demarches-simplifiees.fr";
license = licenses.agpl3Only;
maintainers = with maintainers; [ thubrecht ];
};
}