blob: 1a03992258b163ed386a8bb354fc40c003f92ad1 [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 ||
Serge Bazanski2f6c92c2022-07-04 21:02:31 +020029 lib.strings.hasInfix "/hswaw/site" name ||
Piotr Dobrowolski20c6bcb2021-10-16 23:07:29 +020030 lib.strings.hasInfix "/hswaw/laserproxy" name ||
31
32 lib.strings.hasSuffix "/BUILD" name ||
33 lib.strings.hasSuffix "/WORKSPACE" name ||
34 lib.strings.hasSuffix "/.bazelrc" name
35 );
36 src = hscloud.root;
37 };
38
Serge Bazanskib1de7572020-10-29 00:43:43 +010039 bazelTarget = "//hswaw/laserproxy";
40 nativeBuildInputs = with pkgs; [
41 git python3 postgresql go
42 ];
43 patches = [
Serge Bazanskib1de7572020-10-29 00:43:43 +010044 ./nix-use-system-go.patch
45 ./nix-disable-workspace-status.patch
46 ];
47
48 removeRulesCC = false;
49 fetchConfigured = true;
50 fetchAttrs = {
Serge Bazanskiae2886b2021-10-16 20:35:21 +020051 # Nicked from nixpkgs' usages of buildBazelPackage in bazel_watcher.
Serge Bazanskib1de7572020-10-29 00:43:43 +010052 preInstall = ''
Serge Bazanskiae2886b2021-10-16 20:35:21 +020053 # Remove the go_sdk (it's just a copy of the go derivation) and all
54 # references to it from the marker files. Bazel does not need to download
55 # this sdk because we have patched the WORKSPACE file to point to the one
56 # currently present in PATH. Without removing the go_sdk from the marker
57 # file, the hash of it will change anytime the Go derivation changes and
58 # that would lead to impurities in the marker files which would result in
59 # a different sha256 for the fetch phase.
Serge Bazanskib1de7572020-10-29 00:43:43 +010060 rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
61 sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
Serge Bazanskiae2886b2021-10-16 20:35:21 +020062
63 # Retains go build input markers
Serge Bazanskib1de7572020-10-29 00:43:43 +010064 chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
65 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
Serge Bazanskiae2886b2021-10-16 20:35:21 +020066
67 # Remove the gazelle tools, they contain go binaries that are built
68 # non-deterministically. As long as the gazelle version matches the tools
69 # should be equivalent.
Serge Bazanskib1de7572020-10-29 00:43:43 +010070 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
71 sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker
72 '';
vuko5319e612021-12-28 18:45:14 +010073 sha256 = "sha256-WbM9+9Pt//21MCwb/zVro29uKVdNXHnWpuh7kILUbco=";
Serge Bazanskib1de7572020-10-29 00:43:43 +010074 };
75 buildAttrs = {
76 inherit patches;
77 installPhase = ''
78 install -Dm755 bazel-bin/hswaw/laserproxy/*/laserproxy $out/bin/laserproxy
79 '';
80 };
81}