blob: f048ef45742238d73cd4b55e90d131f2c6ad38fe [file] [log] [blame]
Serge Bazanskib1de7572020-10-29 00:43:43 +01001{ hscloud, pkgs, ... }:
2
3# This supports building laserproxy in nix, which is used for deploying it to customs.
4# This is mildly hacky and should be reworked to function for any hscloud bazel target
5# in a more generic fashion.
6#
7# To build:
8# ~/hscloud $ nix-build -A hswaw.laserproxy
9
10pkgs.buildBazelPackage rec {
11 name = "laserproxy";
12 src = hscloud.root;
13 bazelTarget = "//hswaw/laserproxy";
14 nativeBuildInputs = with pkgs; [
15 git python3 postgresql go
16 ];
17 patches = [
Serge Bazanskib1de7572020-10-29 00:43:43 +010018 ./nix-use-system-go.patch
19 ./nix-disable-workspace-status.patch
20 ];
21
22 removeRulesCC = false;
23 fetchConfigured = true;
24 fetchAttrs = {
Serge Bazanskiae2886b2021-10-16 20:35:21 +020025 # Nicked from nixpkgs' usages of buildBazelPackage in bazel_watcher.
Serge Bazanskib1de7572020-10-29 00:43:43 +010026 preInstall = ''
Serge Bazanskiae2886b2021-10-16 20:35:21 +020027 # Remove the go_sdk (it's just a copy of the go derivation) and all
28 # references to it from the marker files. Bazel does not need to download
29 # this sdk because we have patched the WORKSPACE file to point to the one
30 # currently present in PATH. Without removing the go_sdk from the marker
31 # file, the hash of it will change anytime the Go derivation changes and
32 # that would lead to impurities in the marker files which would result in
33 # a different sha256 for the fetch phase.
Serge Bazanskib1de7572020-10-29 00:43:43 +010034 rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
35 sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
Serge Bazanskiae2886b2021-10-16 20:35:21 +020036
37 # Retains go build input markers
Serge Bazanskib1de7572020-10-29 00:43:43 +010038 chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
39 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
Serge Bazanskiae2886b2021-10-16 20:35:21 +020040
41 # Remove the gazelle tools, they contain go binaries that are built
42 # non-deterministically. As long as the gazelle version matches the tools
43 # should be equivalent.
Serge Bazanskib1de7572020-10-29 00:43:43 +010044 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
45 sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker
46 '';
Serge Bazanskiae2886b2021-10-16 20:35:21 +020047 sha256 = "178ai44v8lczzy9gyqnkqmcnjvmw8m89qzaqv6my5fqkw6psliqz";
Serge Bazanskib1de7572020-10-29 00:43:43 +010048 };
49 buildAttrs = {
50 inherit patches;
51 installPhase = ''
52 install -Dm755 bazel-bin/hswaw/laserproxy/*/laserproxy $out/bin/laserproxy
53 '';
54 };
55}