blob: d6f48f13a52b43f4f925b19da7e34da0eaf8fa7c [file] [log] [blame]
Piotr Dobrowolski20c6bcb2021-10-16 23:07:29 +02001{ hscloud, lib, pkgs, ... }:
Serge Bazanskib1de7572020-10-29 00:43:43 +01002
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";
Piotr Dobrowolski20c6bcb2021-10-16 23:07:29 +020012
13 # Cleanup source tree to limit impact of unrelated changes to hscloud source
14 # tree on nix build cache. This should only pass over:
15 # //BUILD, //WORKSPACE, //.bazelrc
16 # //hscloud/go/**
17 # //hscloud/third_party/**
18 # //hscloud/devtools/gerrit/** (WORKSPACE reference)
19 # //hswaw/laserproxy/** (our build target)
20 src = lib.cleanSourceWith {
21 filter = name: type: (
22 lib.strings.hasInfix "/go" name ||
23 lib.strings.hasInfix "/third_party" name ||
24
25 lib.strings.hasSuffix "/devtools" name ||
26 lib.strings.hasInfix "/devtools/gerrit" name ||
27
28 lib.strings.hasSuffix "/hswaw" name ||
29 lib.strings.hasInfix "/hswaw/laserproxy" name ||
30
31 lib.strings.hasSuffix "/BUILD" name ||
32 lib.strings.hasSuffix "/WORKSPACE" name ||
33 lib.strings.hasSuffix "/.bazelrc" name
34 );
35 src = hscloud.root;
36 };
37
Serge Bazanskib1de7572020-10-29 00:43:43 +010038 bazelTarget = "//hswaw/laserproxy";
39 nativeBuildInputs = with pkgs; [
40 git python3 postgresql go
41 ];
42 patches = [
Serge Bazanskib1de7572020-10-29 00:43:43 +010043 ./nix-use-system-go.patch
44 ./nix-disable-workspace-status.patch
45 ];
46
47 removeRulesCC = false;
48 fetchConfigured = true;
49 fetchAttrs = {
Serge Bazanskiae2886b2021-10-16 20:35:21 +020050 # Nicked from nixpkgs' usages of buildBazelPackage in bazel_watcher.
Serge Bazanskib1de7572020-10-29 00:43:43 +010051 preInstall = ''
Serge Bazanskiae2886b2021-10-16 20:35:21 +020052 # Remove the go_sdk (it's just a copy of the go derivation) and all
53 # references to it from the marker files. Bazel does not need to download
54 # this sdk because we have patched the WORKSPACE file to point to the one
55 # currently present in PATH. Without removing the go_sdk from the marker
56 # file, the hash of it will change anytime the Go derivation changes and
57 # that would lead to impurities in the marker files which would result in
58 # a different sha256 for the fetch phase.
Serge Bazanskib1de7572020-10-29 00:43:43 +010059 rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
60 sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
Serge Bazanskiae2886b2021-10-16 20:35:21 +020061
62 # Retains go build input markers
Serge Bazanskib1de7572020-10-29 00:43:43 +010063 chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
64 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
Serge Bazanskiae2886b2021-10-16 20:35:21 +020065
66 # Remove the gazelle tools, they contain go binaries that are built
67 # non-deterministically. As long as the gazelle version matches the tools
68 # should be equivalent.
Serge Bazanskib1de7572020-10-29 00:43:43 +010069 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
70 sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker
71 '';
Serge Bazanskiae2886b2021-10-16 20:35:21 +020072 sha256 = "178ai44v8lczzy9gyqnkqmcnjvmw8m89qzaqv6my5fqkw6psliqz";
Serge Bazanskib1de7572020-10-29 00:43:43 +010073 };
74 buildAttrs = {
75 inherit patches;
76 installPhase = ''
77 install -Dm755 bazel-bin/hswaw/laserproxy/*/laserproxy $out/bin/laserproxy
78 '';
79 };
80}