Piotr Dobrowolski | 20c6bcb | 2021-10-16 23:07:29 +0200 | [diff] [blame] | 1 | { hscloud, lib, pkgs, ... }: |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 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 | |
| 10 | pkgs.buildBazelPackage rec { |
| 11 | name = "laserproxy"; |
Piotr Dobrowolski | 20c6bcb | 2021-10-16 23:07:29 +0200 | [diff] [blame] | 12 | |
| 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 Bazanski | 2f6c92c | 2022-07-04 21:02:31 +0200 | [diff] [blame] | 29 | lib.strings.hasInfix "/hswaw/site" name || |
Piotr Dobrowolski | 20c6bcb | 2021-10-16 23:07:29 +0200 | [diff] [blame] | 30 | lib.strings.hasInfix "/hswaw/laserproxy" name || |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 31 | lib.strings.hasInfix "/hswaw/site" name || |
Piotr Dobrowolski | 20c6bcb | 2021-10-16 23:07:29 +0200 | [diff] [blame] | 32 | |
| 33 | lib.strings.hasSuffix "/BUILD" name || |
| 34 | lib.strings.hasSuffix "/WORKSPACE" name || |
| 35 | lib.strings.hasSuffix "/.bazelrc" name |
| 36 | ); |
| 37 | src = hscloud.root; |
| 38 | }; |
| 39 | |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 40 | bazelTarget = "//hswaw/laserproxy"; |
| 41 | nativeBuildInputs = with pkgs; [ |
| 42 | git python3 postgresql go |
| 43 | ]; |
| 44 | patches = [ |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 45 | ./nix-use-system-go.patch |
| 46 | ./nix-disable-workspace-status.patch |
| 47 | ]; |
| 48 | |
| 49 | removeRulesCC = false; |
| 50 | fetchConfigured = true; |
| 51 | fetchAttrs = { |
Serge Bazanski | ae2886b | 2021-10-16 20:35:21 +0200 | [diff] [blame] | 52 | # Nicked from nixpkgs' usages of buildBazelPackage in bazel_watcher. |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 53 | preInstall = '' |
Serge Bazanski | ae2886b | 2021-10-16 20:35:21 +0200 | [diff] [blame] | 54 | # Remove the go_sdk (it's just a copy of the go derivation) and all |
| 55 | # references to it from the marker files. Bazel does not need to download |
| 56 | # this sdk because we have patched the WORKSPACE file to point to the one |
| 57 | # currently present in PATH. Without removing the go_sdk from the marker |
| 58 | # file, the hash of it will change anytime the Go derivation changes and |
| 59 | # that would lead to impurities in the marker files which would result in |
| 60 | # a different sha256 for the fetch phase. |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 61 | rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker} |
| 62 | sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker |
Serge Bazanski | ae2886b | 2021-10-16 20:35:21 +0200 | [diff] [blame] | 63 | |
| 64 | # Retains go build input markers |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 65 | chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} |
| 66 | rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} |
Serge Bazanski | ae2886b | 2021-10-16 20:35:21 +0200 | [diff] [blame] | 67 | |
| 68 | # Remove the gazelle tools, they contain go binaries that are built |
| 69 | # non-deterministically. As long as the gazelle version matches the tools |
| 70 | # should be equivalent. |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 71 | rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker} |
| 72 | sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker |
| 73 | ''; |
vuko | 5319e61 | 2021-12-28 18:45:14 +0100 | [diff] [blame] | 74 | sha256 = "sha256-WbM9+9Pt//21MCwb/zVro29uKVdNXHnWpuh7kILUbco="; |
Serge Bazanski | b1de757 | 2020-10-29 00:43:43 +0100 | [diff] [blame] | 75 | }; |
| 76 | buildAttrs = { |
| 77 | inherit patches; |
| 78 | installPhase = '' |
| 79 | install -Dm755 bazel-bin/hswaw/laserproxy/*/laserproxy $out/bin/laserproxy |
| 80 | ''; |
| 81 | }; |
| 82 | } |