allow extraFiles to contain paths

This commit is contained in:
jacekpoz 2024-09-13 11:31:31 +02:00
parent 8d74fade2b
commit 1d5ebbce46
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 15 additions and 7 deletions

View file

@ -51,7 +51,9 @@ it accepts an attrset of:
- `extraArgs` - an attrset of additional arguments passed to all entries and templates
- `entries` - a list of all entry files to be processed
- `templates` - a list of all template files to be applied
- `extraFiles` - a list of attrsets of `source` and `destination`:
- `extraFiles` - a list of either:
- a path to the source file - will be copied to `$out` in the `installPhase`
- attrset of `source` and `destination`:
- `source` - a path, if relative `$PWD` is `$src` in the `installPhase`
- `destination` - a path, never absolute, appended to `$out` in the `installPhase`
@ -86,6 +88,7 @@ mkNteDerivation {
];
extraFiles = [
./data.txt # equivalent to { source = ./data.txt; destination = "/"; }
{ source = ./image.png; destination = "/assets/"; }
{ source = ./image2.png; destination = "/assets/dupa.png"; }
{ source = "./data/*"; destination = "/assets/data/"; }

View file

@ -8,6 +8,7 @@ pkgs: engine: {
extraFiles ? []
}: let
inherit (pkgs) lib;
inherit (lib.attrsets) isAttrs;
inherit (lib.lists) forEach init;
inherit (lib.strings) concatStrings concatStringsSep match normalizePath optionalString splitString;
in pkgs.stdenv.mkDerivation {
@ -28,12 +29,16 @@ in pkgs.stdenv.mkDerivation {
${concatStrings (forEach extraFiles
(extraFile: let
isInSubdir = (match ".+/.*" extraFile.destination) != null;
outDir = normalizePath "$out/${concatStringsSep "/" (init (splitString "/" extraFile.destination))}";
outPath = normalizePath "$out/${extraFile.destination}";
fileAttrs = if isAttrs extraFile
then extraFile
else { source = extraFile; destination = "/"; };
isInSubdir = (match ".+/.*" fileAttrs.destination) != null;
outDir = normalizePath "$out/${concatStringsSep "/" (init (splitString "/" fileAttrs.destination))}";
outPath = normalizePath "$out/${fileAttrs.destination}";
in /*sh*/''
${optionalString isInSubdir /*sh*/"mkdir -p ${outDir}"}
cp -r ${extraFile.source} ${outPath}
cp -r ${fileAttrs.source} ${outPath}
''))
}