-
Notifications
You must be signed in to change notification settings - Fork 33
/
package.nix
55 lines (44 loc) · 1.7 KB
/
package.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
48
49
50
51
52
53
54
55
{ lib
, buildNpmPackage
, jq
, unzip
}:
buildNpmPackage rec {
pname = "dolos";
version = "2.8.0";
src = ./.;
npmDepsHash = "sha256-HhJnzQKNg8GdWL45iMod+HY/8cqiaJsckm3cNNbvH1g=";
npmWorkspace="cli";
makeWrapperArgs = "--prefix PATH : ${lib.makeBinPath [ unzip ]}";
makeCacheWritable = true;
prePatch = ''
test -f parsers/bash/binding.gyp || (echo -e "\n Submodules are not present, run flake with '.?submodules=1'\n" && exit 1)
'';
postPatch = ''
${jq}/bin/jq -r 'del(.devDependencies) | del(.scripts.prepare)' parsers/package.json > package.json.tmp
mv package.json.tmp parsers/package.json
'';
buildInputs = [ unzip ];
buildPhase = ''
# Build each needed workspace
for dir in core parsers lib web cli; do
echo "Building dolos-$dir"
npm --workspace="$dir" run build
done
'';
postInstall = ''
for dir in core parsers lib web; do
# npm creates a symlink to each dependent workspace in node_modules
# overwrite each link with that workspace's build output (with npm pack)
local module="$packageOut/node_modules/@dodona/dolos-$dir"
rm "$module"
while IFS= read -r file; do
local dest="$module/$(dirname "$file")"
mkdir -p "$dest"
cp "$dir/$file" "$dest"
done < <(${jq}/bin/jq --raw-output '.[0].files | map(.path | select(. | startswith("node_modules/") | not)) | join("\n")' <<< "$(npm_config_cache="$HOME/.npm" npm pack --json --dry-run --loglevel=warn --no-foreground-scripts --workspace="$dir")")
done
# dolos-parsers does not include the built parsers with npm pack, copy them
cp -r parsers/build "$packageOut/node_modules/@dodona/dolos-parsers"
'';
}