-
Notifications
You must be signed in to change notification settings - Fork 0
/
nte-drv.nix
47 lines (39 loc) · 1.21 KB
/
nte-drv.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pkgs: engine: {
name,
version,
src,
extraArgs ? {},
entries ? [],
templates ? [],
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 {
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
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 ${fileAttrs.source} ${outPath}
''))
}
runHook postInstall
'';
}