Skip to content

Commit

Permalink
Add support for placing additional artifacts into the result.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iteratee committed Feb 27, 2024
1 parent a17fd10 commit 71a9968
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? { }
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -148,7 +159,7 @@ in
mkdir -p $out
${forEachConcat (dDir: ''
cp -r --parents ${dDir} $out
'') distDirs
'') computedDistFiles
}
''
}
Expand Down

0 comments on commit 71a9968

Please sign in to comment.