From 71a99689dac92d2460e57e89c0dd97ae59f0d222 Mon Sep 17 00:00:00 2001 From: Kyle Butt Date: Wed, 14 Feb 2024 12:16:19 -0700 Subject: [PATCH] Add support for placing additional artifacts into the result. A user may want the node_modules and package artifacts as a part of the output in order to have a runnable build artifact without needing the node-modules derivation or the sources available. Add options to control additional copies as a part of the install. Simplify the values used in the derivation so that the conditional logic is almost all in the let rather than in the derivation body. Some of this change should probably rebased into the first commit. --- derivation.nix | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/derivation.nix b/derivation.nix index 556cca0..9d92e89 100644 --- a/derivation.nix +++ b/derivation.nix @@ -33,6 +33,9 @@ in , script ? "build" , distDir ? "dist" , distDirs ? (if workspace == null then [distDir] else (map (c: "${c}/dist") components)) + , distDirIsOut ? true + , installNodeModules ? false + , installPackageFiles ? false , installInPlace ? false , installEnv ? { } , buildEnv ? { } @@ -76,6 +79,14 @@ in ] ) ++ extraNodeModuleSources; # Computed values that loop over something + computedDistFiles = + let + packageFileNames = ["pnpm-lock.yaml"] ++ + map ({ name, ... }: name) packageFilesWithoutLockfile; + in + distDirs ++ + optionals installNodeModules nodeModulesDirs ++ + optionals installPackageFiles packageFileNames; nodeModulesDirs = if isWorkspace then ["node_modules"] ++ (map (c: "${c}/node_modules") components) @@ -90,7 +101,7 @@ in # Flag derived from value computed above, indicating the single dist # should be copied as $out directly, rather than $out/${distDir} computedDistDirIsOut = - length distDirs == 1 && !isWorkspace; + length computedDistFiles == 1 && distDirIsOut && !isWorkspace; in stdenv.mkDerivation ( recursiveUpdate @@ -148,7 +159,7 @@ in mkdir -p $out ${forEachConcat (dDir: '' cp -r --parents ${dDir} $out - '') distDirs + '') computedDistFiles } '' }