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,38 @@
{
lib,
stdenv,
zig,
runCommand,
makeWrapper,
coreutils,
}:
let
targetPrefix = lib.optionalString (
stdenv.hostPlatform != stdenv.targetPlatform
) "${stdenv.targetPlatform.config}-";
in
runCommand "zig-bintools-${zig.version}"
{
pname = "zig-bintools";
inherit (zig) version meta;
nativeBuildInputs = [ makeWrapper ];
passthru = {
isZig = true;
inherit targetPrefix;
};
inherit zig;
}
''
mkdir -p $out/bin
for tool in ar objcopy ranlib ld.lld; do
makeWrapper "$zig/bin/zig" "$out/bin/$tool" \
--add-flags "$tool" \
--suffix PATH : "${lib.makeBinPath [ coreutils ]}" \
--run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)"
done
ln -s $out/bin/ld.lld $out/bin/ld
''

View File

@@ -0,0 +1,44 @@
{
lib,
runCommand,
zig,
stdenv,
makeWrapper,
coreutils,
}:
let
targetPrefix = lib.optionalString (
stdenv.hostPlatform != stdenv.targetPlatform
) "${stdenv.targetPlatform.config}-";
in
runCommand "zig-cc-${zig.version}"
{
pname = "zig-cc";
inherit (zig) version;
nativeBuildInputs = [ makeWrapper ];
passthru = {
isZig = true;
inherit targetPrefix;
};
inherit zig;
meta = zig.meta // {
mainProgram = "${targetPrefix}clang";
};
}
''
mkdir -p $out/bin
for tool in cc c++ ld.lld; do
makeWrapper "$zig/bin/zig" "$out/bin/$tool" \
--add-flags "$tool" \
--suffix PATH : "${lib.makeBinPath [ coreutils ]}" \
--run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)"
done
ln -s $out/bin/c++ $out/bin/clang++
ln -s $out/bin/cc $out/bin/clang
ln -s $out/bin/ld.lld $out/bin/ld
''

View File

@@ -0,0 +1,39 @@
{
lib,
callPackage,
llvmPackages_18,
llvmPackages_19,
llvmPackages_20,
zigVersions ? { },
}:
let
versions = {
"0.13.0" = {
llvmPackages = llvmPackages_18;
hash = "sha256-5qSiTq+UWGOwjDVZMIrAt2cDKHkyNPBSAEjpRQUByFM=";
};
"0.14.1" = {
llvmPackages = llvmPackages_19;
hash = "sha256-DhVJIY/z12PJZdb5j4dnCRb7k1CmeQVOnayYRP8azDI=";
};
"0.15.1" = {
llvmPackages = llvmPackages_20;
hash = "sha256-RFbJYeTHj/aNjWSsG+HHtmOL1VY4dpvJjbx04OhF4bI=";
};
}
// zigVersions;
mkPackage =
{
version,
hash,
llvmPackages,
}@args:
callPackage ./generic.nix args;
zigPackages = lib.mapAttrs' (
version: args:
lib.nameValuePair (lib.versions.majorMinor version) (mkPackage (args // { inherit version; }))
) versions;
in
zigPackages

View File

@@ -0,0 +1,32 @@
{
lib,
zig,
runCommand,
}:
{
pname,
version,
name ? "${pname}-${version}",
src,
hash ? lib.fakeHash,
}@args:
runCommand "${name}-zig-deps"
{
inherit (args) src;
nativeBuildInputs = [ zig ];
outputHashAlgo = null;
outputHashMode = "recursive";
outputHash = hash;
}
''
export ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
runHook unpackPhase
cd $sourceRoot
zig build --fetch
mv $ZIG_GLOBAL_CACHE_DIR/p $out
''

View File

@@ -0,0 +1,153 @@
{
lib,
stdenv,
fetchFromGitHub,
cmake,
llvmPackages,
xcbuild,
targetPackages,
libxml2,
ninja,
zlib,
coreutils,
callPackage,
version,
hash,
overrideCC,
wrapCCWith,
wrapBintoolsWith,
...
}@args:
stdenv.mkDerivation (finalAttrs: {
pname = "zig";
inherit version;
src = fetchFromGitHub {
owner = "ziglang";
repo = "zig";
rev = finalAttrs.version;
inherit hash;
};
patches = args.patches or [ ];
nativeBuildInputs = [
cmake
(lib.getDev llvmPackages.llvm.dev)
ninja
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# provides xcode-select, which is required for SDK detection
xcbuild
];
buildInputs = [
libxml2
zlib
]
++ (with llvmPackages; [
libclang
lld
llvm
]);
cmakeFlags = [
# file RPATH_CHANGE could not write new RPATH
(lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
# ensure determinism in the compiler build
(lib.cmakeFeature "ZIG_TARGET_MCPU" "baseline")
# always link against static build of LLVM
(lib.cmakeBool "ZIG_STATIC_LLVM" true)
];
outputs = [
"out"
"doc"
];
strictDeps = true;
# On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build,
# which parses /System/Library/CoreServices/SystemVersion.plist and
# /System/Library/CoreServices/.SystemVersionPlatform.plist to determine the
# OS version. This causes the build to fail during stage 3 with
# OSVersionDetectionFail when the sandbox is enabled.
__impureHostDeps = lib.optionals stdenv.hostPlatform.isDarwin [
"/System/Library/CoreServices/.SystemVersionPlatform.plist"
];
preBuild = ''
export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache";
'';
postPatch =
# Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
# work in Nix's sandbox. Use env from our coreutils instead.
''
substituteInPlace lib/std/zig/system.zig \
--replace-fail "/usr/bin/env" "${lib.getExe' coreutils "env"}"
''
# Zig tries to access xcrun and xcode-select at the absolute system path to query the macOS SDK
# location, which does not work in the darwin sandbox.
# Upstream issue: https://github.com/ziglang/zig/issues/22600
# Note that while this fix is already merged upstream and will be included in 0.14+,
# we can't fetchpatch the upstream commit as it won't cleanly apply on older versions,
# so we substitute the paths instead.
+ lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder finalAttrs.version "0.14") ''
substituteInPlace lib/std/zig/system/darwin.zig \
--replace-fail /usr/bin/xcrun xcrun \
--replace-fail /usr/bin/xcode-select xcode-select
'';
postBuild =
if lib.versionAtLeast finalAttrs.version "0.14" then
''
stage3/bin/zig build langref --zig-lib-dir $(pwd)/stage3/lib/zig
''
else
''
stage3/bin/zig build langref
'';
postInstall = ''
install -Dm444 ../zig-out/doc/langref.html -t $doc/share/doc/zig-${finalAttrs.version}/html
'';
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
$out/bin/zig test --cache-dir "$TMPDIR/zig-test-cache" -I $src/test $src/test/behavior.zig
runHook postInstallCheck
'';
passthru = import ./passthru.nix {
inherit
lib
stdenv
callPackage
wrapCCWith
wrapBintoolsWith
overrideCC
targetPackages
;
zig = finalAttrs.finalPackage;
};
meta = {
description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
homepage = "https://ziglang.org/";
changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ andrewrk ];
teams = [ lib.teams.zig ];
mainProgram = "zig";
platforms = lib.platforms.unix;
# Zig 0.15.1 fails some tests on x86_64-darwin thus we mark it broken
# see https://github.com/ziglang/zig/issues/24974
broken =
stdenv.hostPlatform.system == "x86_64-darwin" && lib.versionAtLeast finalAttrs.version "0.15";
};
})

View File

@@ -0,0 +1,62 @@
{
lib,
makeSetupHook,
zig,
stdenv,
xcbuild,
}:
makeSetupHook {
name = "zig-hook";
propagatedBuildInputs = [
zig
]
# while xcrun is already included in the darwin stdenv, Zig also needs
# xcode-select (provided by xcbuild) for SDK detection
++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ];
substitutions = {
# This zig_default_flags below is meant to avoid CPU feature impurity in
# Nixpkgs. However, this flagset is "unstable": it is specifically meant to
# be controlled by the upstream development team - being up to that team
# exposing or not that flags to the outside (especially the package manager
# teams).
# Because of this hurdle, @andrewrk from Zig Software Foundation proposed
# some solutions for this issue. Hopefully they will be implemented in
# future releases of Zig. When this happens, this flagset should be
# revisited accordingly.
# Below are some useful links describing the discovery process of this 'bug'
# in Nixpkgs:
# https://github.com/NixOS/nixpkgs/issues/169461
# https://github.com/NixOS/nixpkgs/issues/185644
# https://github.com/NixOS/nixpkgs/pull/197046
# https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485
# https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653
zig_default_flags =
let
releaseType =
if lib.versionAtLeast zig.version "0.12" then
"--release=safe"
else if lib.versionAtLeast zig.version "0.11" then
"-Doptimize=ReleaseSafe"
else
"-Drelease-safe=true";
in
[
"-Dcpu=baseline"
releaseType
];
};
passthru = { inherit zig; };
meta = {
description = "Setup hook for using the Zig compiler in Nixpkgs";
inherit (zig.meta) maintainers platforms broken;
};
} ./setup-hook.sh

View File

@@ -0,0 +1,34 @@
{
lib,
stdenv,
zig,
callPackage,
wrapCCWith,
wrapBintoolsWith,
overrideCC,
targetPackages,
}:
{
hook = callPackage ./hook.nix { inherit zig; };
bintools-unwrapped = callPackage ./bintools.nix { inherit zig; };
bintools = wrapBintoolsWith { bintools = zig.bintools-unwrapped; };
cc-unwrapped = callPackage ./cc.nix { inherit zig; };
cc = wrapCCWith {
cc = zig.cc-unwrapped;
bintools = zig.bintools;
extraPackages = [ ];
nixSupport.cc-cflags = [
"-target"
"${stdenv.targetPlatform.system}-${stdenv.targetPlatform.parsed.abi.name}"
]
++ lib.optional (
stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.isStatic or false)
) "-Wl,-dynamic-linker=${targetPackages.stdenv.cc.bintools.dynamicLinker}";
};
stdenv = overrideCC stdenv zig.cc;
fetchDeps = callPackage ./fetcher.nix { inherit zig; };
}

View File

@@ -0,0 +1,96 @@
# shellcheck shell=bash
# shellcheck disable=SC2034
readonly zigDefaultFlagsArray=(@zig_default_flags@)
function zigSetGlobalCacheDir {
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
export ZIG_GLOBAL_CACHE_DIR
}
function zigBuildPhase {
runHook preBuild
local buildCores=1
# Parallel building is enabled by default.
if [ "${enableParallelBuilding-1}" ]; then
buildCores="$NIX_BUILD_CORES"
fi
local flagsArray=(
"-j$buildCores"
)
concatTo flagsArray zigDefaultFlagsArray \
zigBuildFlags zigBuildFlagsArray
echoCmd 'zig build flags' "${flagsArray[@]}"
TERM=dumb zig build "${flagsArray[@]}" --verbose
runHook postBuild
}
function zigCheckPhase {
runHook preCheck
local buildCores=1
# Parallel building is enabled by default.
if [ "${enableParallelChecking-1}" ]; then
buildCores="$NIX_BUILD_CORES"
fi
local flagsArray=(
"-j$buildCores"
)
concatTo flagsArray zigDefaultFlagsArray \
zigCheckFlags zigCheckFlagsArray
echoCmd 'zig check flags' "${flagsArray[@]}"
TERM=dumb zig build test "${flagsArray[@]}" --verbose
runHook postCheck
}
function zigInstallPhase {
runHook preInstall
local buildCores=1
# Parallel building is enabled by default.
if [ "${enableParallelInstalling-1}" ]; then
buildCores="$NIX_BUILD_CORES"
fi
local flagsArray=(
"-j$buildCores"
)
concatTo flagsArray zigDefaultFlagsArray \
zigBuildFlags zigBuildFlagsArray \
zigInstallFlags zigInstallFlagsArray
if [ -z "${dontAddPrefix-}" ]; then
# Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/`
flagsArray+=("${prefixKey:---prefix}" "$prefix")
fi
echoCmd 'zig install flags' "${flagsArray[@]}"
TERM=dumb zig build install "${flagsArray[@]}" --verbose
runHook postInstall
}
# shellcheck disable=SC2154
addEnvHooks "$targetOffset" zigSetGlobalCacheDir
if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=zigBuildPhase
fi
if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=zigCheckPhase
fi
if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=zigInstallPhase
fi