blob: 9bba78caf31c8724edaf53e19d3ae0caf750fb5f [file] [log] [blame]
{ hscloud, lib, pkgs, ... }:
# This supports building laserproxy in nix, which is used for deploying it to customs.
# This is mildly hacky and should be reworked to function for any hscloud bazel target
# in a more generic fashion.
#
# To build:
# ~/hscloud $ nix-build -A hswaw.laserproxy
pkgs.buildBazelPackage rec {
name = "laserproxy";
# Cleanup source tree to limit impact of unrelated changes to hscloud source
# tree on nix build cache. This should only pass over:
# //BUILD, //WORKSPACE, //.bazelrc
# //hscloud/go/**
# //hscloud/third_party/**
# //hscloud/devtools/gerrit/** (WORKSPACE reference)
# //hswaw/laserproxy/** (our build target)
src = lib.cleanSourceWith {
filter = name: type: (
lib.strings.hasInfix "/go" name ||
lib.strings.hasInfix "/third_party" name ||
lib.strings.hasSuffix "/devtools" name ||
lib.strings.hasInfix "/devtools/gerrit" name ||
lib.strings.hasSuffix "/hswaw" name ||
lib.strings.hasInfix "/hswaw/site" name ||
lib.strings.hasInfix "/hswaw/laserproxy" name ||
lib.strings.hasInfix "/hswaw/site" name ||
lib.strings.hasSuffix "/BUILD" name ||
lib.strings.hasSuffix "/WORKSPACE" name ||
lib.strings.hasSuffix "/.bazelrc" name
);
src = ../..;
};
bazel = pkgs.bazel_5;
bazelTargets = [ "//hswaw/laserproxy" ];
nativeBuildInputs = with pkgs; [
git python3 postgresql go
];
patches = [
./nix-use-system-go.patch
./nix-disable-workspace-status.patch
];
removeRulesCC = false;
fetchConfigured = true;
fetchAttrs = {
# Nicked from nixpkgs' usages of buildBazelPackage in bazel_watcher.
preInstall = ''
# FIXME: dirty hack to avoid permission errors later from "rm" calls
# without "-f"
${pkgs.findutils}/bin/find $bazelOut/external/python3* -exec chmod u+w {} +
# Remove the go_sdk (it's just a copy of the go derivation) and all
# references to it from the marker files. Bazel does not need to download
# this sdk because we have patched the WORKSPACE file to point to the one
# currently present in PATH. Without removing the go_sdk from the marker
# file, the hash of it will change anytime the Go derivation changes and
# that would lead to impurities in the marker files which would result in
# a different sha256 for the fetch phase.
rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker
# Retains go build input markers
chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
# Remove the gazelle tools, they contain go binaries that are built
# non-deterministically. As long as the gazelle version matches the tools
# should be equivalent.
rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker}
sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker
'';
sha256 = "sha256-Z6H8K10DhbeoKQ3+3vPHrRE6VD/HBSnYfbMWCLModAk=";
};
buildAttrs = {
inherit patches;
installPhase = ''
install -Dm755 bazel-bin/hswaw/laserproxy/*/laserproxy $out/bin/laserproxy
'';
};
}