push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
{
stdenv,
lndir,
lib,
}:
args@{
bazel,
registry ? null,
bazelRepoCache ? null,
bazelVendorDeps ? null,
startupArgs ? [ ],
commandArgs ? [ ],
bazelPreBuild ? "",
bazelPostBuild ? "",
serverJavabase ? null,
targets,
command,
...
}:
stdenv.mkDerivation (
{
preBuildPhases = [ "preBuildPhase" ];
preBuildPhase =
(lib.optionalString (bazelRepoCache != null) ''
# repo_cache needs to be writeable even in air-gapped builds
mkdir repo_cache
${lndir}/bin/lndir -silent ${bazelRepoCache}/repo_cache repo_cache
'')
+ (lib.optionalString (bazelVendorDeps != null) ''
mkdir vendor_dir
${lndir}/bin/lndir -silent ${bazelVendorDeps}/vendor_dir vendor_dir
# pin all deps to avoid re-fetch attempts by Bazel
rm vendor_dir/VENDOR.bazel
find vendor_dir -mindepth 1 -maxdepth 1 -type d -printf "pin(\"@@%P\")\n" > vendor_dir/VENDOR.bazel
'')
# keep preBuildPhase always defined as it is listed in preBuildPhases
+ ''
true
'';
buildPhase = ''
runHook preBuild
export HOME=$(mktemp -d)
${bazelPreBuild}
${bazel}/bin/bazel ${
lib.escapeShellArgs (
lib.optional (serverJavabase != null) "--server_javabase=${serverJavabase}"
++ [ "--batch" ]
++ startupArgs
)
} ${command} ${
lib.escapeShellArgs (
lib.optional (registry != null) "--registry=file://${registry}"
++ lib.optional (bazelRepoCache != null) "--repository_cache=repo_cache"
++ lib.optional (bazelVendorDeps != null) "--vendor_dir=vendor_dir"
++ commandArgs
++ targets
)
}
${bazelPostBuild}
runHook postBuild
'';
}
// args
)

View File

@@ -0,0 +1,164 @@
{
callPackage,
gnugrep,
lib,
autoPatchelfHook,
stdenv,
}:
{
name,
src,
sourceRoot ? null,
version ? null,
targets,
bazel,
startupArgs ? [ ],
commandArgs ? [ ],
env ? { },
serverJavabase ? null,
registry ? null,
bazelRepoCacheFOD ? {
outputHash = null;
outputHashAlgo = "sha256";
},
bazelVendorDepsFOD ? {
outputHash = null;
outputHashAlgo = "sha256";
},
installPhase,
buildInputs ? [ ],
nativeBuildInputs ? [ ],
autoPatchelfIgnoreMissingDeps ? null,
}:
let
# FOD produced by `bazel fetch`
# Repo cache contains content-addressed external Bazel dependencies without any patching
# Potentially this can be nixified via --experimental_repository_resolved_file
# (Note: file itself isn't reproducible because it has lots of extra info and order
# isn't stable too. Parsing it into nix fetch* commands isn't trivial but might be possible)
bazelRepoCache =
if bazelRepoCacheFOD.outputHash == null then
null
else
(callPackage ./bazelDerivation.nix { } {
name = "bazelRepoCache";
inherit (bazelRepoCacheFOD) outputHash outputHashAlgo;
inherit
src
version
sourceRoot
env
buildInputs
nativeBuildInputs
;
inherit registry;
inherit
bazel
targets
startupArgs
serverJavabase
;
command = "fetch";
outputHashMode = "recursive";
commandArgs = [ "--repository_cache=repo_cache" ] ++ commandArgs;
bazelPreBuild = ''
mkdir repo_cache
'';
installPhase = ''
mkdir -p $out/repo_cache
cp -r --reflink=auto repo_cache/* $out/repo_cache
'';
});
# Stage1: FOD produced by `bazel vendor`, Stage2: eventual patchelf or other tuning
# Vendor deps contains unpacked&patches external dependencies, this may need Nix-specific
# patching to address things like
# - broken symlinks
# - symlinks or other references to absolute nix store paths which isn't allowed for FOD
# - autoPatchelf for externally-fetched binaries
#
# Either repo cache or vendor deps should be enough to build a given package
bazelVendorDeps =
if bazelVendorDepsFOD.outputHash == null then
null
else
(
let
stage1 = callPackage ./bazelDerivation.nix { } {
name = "bazelVendorDepsStage1";
inherit (bazelVendorDepsFOD) outputHash outputHashAlgo;
inherit
src
version
sourceRoot
env
buildInputs
nativeBuildInputs
;
inherit registry;
inherit
bazel
targets
startupArgs
serverJavabase
;
dontFixup = true;
command = "vendor";
outputHashMode = "recursive";
commandArgs = [ "--vendor_dir=vendor_dir" ] ++ commandArgs;
bazelPreBuild = ''
mkdir vendor_dir
'';
bazelPostBuild = ''
# remove symlinks that point to locations under bazel_src/
find vendor_dir -type l -lname "$HOME/*" -exec rm '{}' \;
# remove symlinks to temp build directory on darwin
find vendor_dir -type l -lname "/private/var/tmp/*" -exec rm '{}' \;
# remove broken symlinks
find vendor_dir -xtype l -exec rm '{}' \;
# remove .marker files referencing NIX_STORE as those references aren't allowed in FOD
(${gnugrep}/bin/grep -rI "$NIX_STORE/" vendor_dir --files-with-matches --include="*.marker" --null || true) \
| xargs -0 --no-run-if-empty rm
'';
installPhase = ''
mkdir -p $out/vendor_dir
cp -r --reflink=auto vendor_dir/* $out/vendor_dir
'';
};
in
stdenv.mkDerivation {
name = "bazelVendorDeps";
buildInputs = lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook ++ buildInputs;
inherit autoPatchelfIgnoreMissingDeps;
src = stage1;
installPhase = ''
cp -r . $out
'';
}
);
package = callPackage ./bazelDerivation.nix { } {
inherit
name
src
version
sourceRoot
env
buildInputs
nativeBuildInputs
;
inherit registry bazelRepoCache bazelVendorDeps;
inherit
bazel
targets
startupArgs
serverJavabase
commandArgs
;
inherit installPhase;
command = "build";
};
in
package // { passthru = { inherit bazelRepoCache bazelVendorDeps; }; }

View File

@@ -0,0 +1,24 @@
{
stdenv,
}:
{
# If there's a need to patch external dependencies managed by Bazel
# one option is to configure patches on Bazel level. Bazel doesn't
# allow patches to be in absolute paths so this helper will produce
# sources patch that adds given file to given location
addFilePatch =
{
path,
file,
}:
stdenv.mkDerivation {
name = "add_file.patch";
dontUnpack = true;
buildPhase = ''
mkdir -p $(dirname "${path}")
cp ${file} "${path}"
diff -u /dev/null "${path}" >result.patch || true # diff exit code is non-zero if there's a diff
'';
installPhase = ''cp result.patch $out'';
};
}