nte/nte-drv.nix

48 lines
1.2 KiB
Nix
Raw Normal View History

2024-09-12 21:45:32 +02:00
pkgs: engine: {
name,
version,
src,
extraArgs ? {},
entries ? [],
templates ? [],
extraFiles ? []
}: let
inherit (pkgs) lib;
2024-09-13 11:31:31 +02:00
inherit (lib.attrsets) isAttrs;
inherit (lib.lists) forEach init;
inherit (lib.strings) concatStrings concatStringsSep match normalizePath optionalString splitString;
in pkgs.stdenv.mkDerivation {
2024-09-12 21:45:32 +02:00
inherit name version src;
buildPhase = /*sh*/''
runHook preBuild
${engine src {inherit extraArgs entries templates;}}
runHook postBuild
'';
installPhase = optionalString (extraFiles != []) /*sh*/''
runHook preInstall
mkdir -p $out
${concatStrings (forEach extraFiles
(extraFile: let
2024-09-13 11:31:31 +02:00
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}"}
2024-09-13 11:31:31 +02:00
cp -r ${fileAttrs.source} ${outPath}
''))
}
runHook postInstall
'';
2024-09-12 21:45:32 +02:00
}