dream2nix/v1/nix/modules/drv-parts/nodejs-devshell/default.nix

50 lines
1.4 KiB
Nix
Raw Normal View History

2023-06-29 17:06:07 +03:00
{
config,
lib,
dream2nix,
packageSets,
...
}: let
l = lib // builtins;
cfg = config.nodejs-devshell;
nodeModulesDrv = dream2nix.lib.evalModules {
inherit packageSets;
modules = [
dream2nix.modules.drv-parts.nodejs-node-modules
{inherit (config) nodejs-package-lock name version;}
{mkDerivation.src = l.mkForce null;}
];
};
nodeModulesDir = "${nodeModulesDrv}/lib/node_modules/${config.name}/node_modules";
in {
imports = [
dream2nix.modules.drv-parts.mkDerivation
dream2nix.modules.drv-parts.nodejs-package-lock
];
# rsync the node_modules folder
# - tracks node-modules store path via .dream2nix/.node_modules_id
# - omits copying if store path did not change
# - if store path changes, only replaces updated files
# - rsync can be restarted from any point, if failed or aborted mid execution.
# Options:
# -a -> all files recursive, preserve symlinks, etc.
# --delete -> removes deleted files
# --chmod=+ug+w -> make folder writeable by user+group
mkDerivation.shellHook = ''
ID=${nodeModulesDir}
currID=$(cat .dream2nix/.node_modules_id 2> /dev/null)
mkdir -p .dream2nix
if [[ "$ID" != "$currID" || ! -d "node_modules" ]];
then
${config.deps.rsync}/bin/rsync -a --chmod=ug+w --delete ${nodeModulesDir}/ ./node_modules/
echo -n $ID > .dream2nix/.node_modules_id
echo "Ok: node_modules updated"
fi
'';
}