on master help sign in
prybar/build-prybar.nix
81 lines 2.6 kB history raw
1{ language, buildInputs ? [ ], binaries ? [ ], setFlags ? false
2, pkgName ? language }:
4{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git
5, python3, copyPathToStore, rev, makeWrapper }:
7buildGoModule {
8 pname = "prybar-${language}";
9 version = rev;
11 src = ./.;
13 inherit buildInputs;
14 nativeBuildInputs = [ pkg-config makeWrapper ];
16 subPackages = [ "languages/${language}" ];
18 vendorSha256 = "1nrycpyjmmhs8cl6bmrajfwczxsv8z20y7a9k7js8p7z60fz7pya";
20 # This prebiuild hook will setup the compiler flags on demand based on the package
21 # If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
22 # for pkg-config to detect it. Otherwise, we can't find the required flags.
23 preBuild = ''
24 export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
25 ${if setFlags then ''
26 export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
27 export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
28 '' else
29 ""}
31 ${bash}/bin/bash ./scripts/inject.sh ${language}
32 go generate ./languages/${language}/main.go
34 if [[ -f "languages/${language}/compile" ]]; then
35 patchShebangs languages/${language}/compile
36 languages/${language}/compile;
37 fi
38 '';
40 # The test file expect the binary to be in the current directory rather than bin
41 preCheck = ''
42 cp $GOPATH/bin/${language} ./prybar-${language}
43 '';
45 # Add all the dependencies to the check. Binaries should include the language interpreter/binaries
46 # for testing the language.
47 checkInputs = [ expect ] ++ buildInputs ++ binaries;
49 # Run the end-to-end tests for this specific language
50 checkPhase = ''
51 runHook preCheck
53 # Nix unsets HOME but some tests rely on it, let's set it to whatever tmp dir the check
54 # is running in.
55 export HOME=$(echo pwd)
57 # Currently the go tests won't work in nix because of something w/ nix's sandboxing.
59 DISABLE_GO_TESTS=1 "${bash}/bin/bash" "./run_tests_language" "${language}"
61 runHook postCheck
62 '';
64 # Delete the test binary we copied in the preCheck
65 postCheck = ''
66 rm -f ./prybar-${language}
67 '';
69 postInstall = ''
70 mv $out/bin/${language} $out/bin/prybar-${language}
72 if [ -d "./prybar_assets/${language}" ]
73 then
74 mkdir -p "$out/prybar_assets/${language}"
75 cp -R "./prybar_assets/${language}" "$out/prybar_assets/"
77 wrapProgram "$out/bin/prybar-${language}" \
78 --set PRYBAR_ASSETS_DIR "$out/prybar_assets"
79 fi
80 '';