Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions doc/hooks/zig.section.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# zig.hook {#zig-hook}
# Zig {#zig}

[Zig](https://ziglang.org/) is a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software.

In Nixpkgs, `zig.hook` overrides the default build, check and install phases.
In Nixpkgs, `zig` overrides the default build, check and install phases.

## Example code snippet {#zig-hook-example-code-snippet}
## Example code snippet {#zig-example-code-snippet}

```nix
{
Expand All @@ -16,7 +16,7 @@ In Nixpkgs, `zig.hook` overrides the default build, check and install phases.
stdenv.mkDerivation {
# . . .

nativeBuildInputs = [ zig.hook ];
nativeBuildInputs = [ zig ];

zigBuildFlags = [ "-Dman-pages=true" ];

Expand All @@ -26,11 +26,11 @@ stdenv.mkDerivation {
}
```

## Variables controlling zig.hook {#zig-hook-variables-controlling}
## Variables controlling zig {#zig-variables-controlling}

### `zig.hook` Exclusive Variables {#zig-hook-exclusive-variables}
### `zig` Exclusive Variables {#zig-exclusive-variables}

The variables below are exclusive to `zig.hook`.
The variables below are exclusive to `zig`.

#### `dontUseZigBuild` {#dont-use-zig-build}

Expand All @@ -44,19 +44,23 @@ Disables using `zigCheckPhase`.

Disables using `zigInstallPhase`.

### Similar variables {#zig-hook-similar-variables}
#### `dontSetZigDefaultFlags` {#dont-set-zig-default-flags}

Disables using a set of default flags when performing zig builds.

### Similar variables {#zig-similar-variables}

The following variables are similar to their `stdenv.mkDerivation` counterparts.

| `zig.hook` Variable | `stdenv.mkDerivation` Counterpart |
| `zig` Variable | `stdenv.mkDerivation` Counterpart |
|---------------------|-----------------------------------|
| `zigBuildFlags` | `buildFlags` |
| `zigCheckFlags` | `checkFlags` |
| `zigInstallFlags` | `installFlags` |

### Variables honored by zig.hook {#zig-hook-variables-honored}
### Variables honored by zig {#zig-variables-honored}

The following variables commonly used by `stdenv.mkDerivation` are honored by `zig.hook`.
The following variables commonly used by `stdenv.mkDerivation` are honored by `zig`.

- `prefixKey`
- `dontAddPrefix`
21 changes: 15 additions & 6 deletions doc/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -2713,16 +2713,20 @@
"waf-hook-honored-variables": [
"index.html#waf-hook-honored-variables"
],
"zig-hook": [
"zig": [
"index.html#zig",
"index.html#zig-hook"
],
"zig-hook-example-code-snippet": [
"zig-example-code-snippet": [
"index.html#zig-example-code-snippet",
"index.html#zig-hook-example-code-snippet"
],
"zig-hook-variables-controlling": [
"zig-variables-controlling": [
"index.html#zig-variables-controlling",
"index.html#zig-hook-variables-controlling"
],
"zig-hook-exclusive-variables": [
"zig-exclusive-variables": [
"index.html#zig-exclusive-variables",
"index.html#zig-hook-exclusive-variables"
],
"dont-use-zig-build": [
Expand All @@ -2734,10 +2738,15 @@
"dont-use-zig-install": [
"index.html#dont-use-zig-install"
],
"zig-hook-similar-variables": [
"dont-set-zig-default-flags": [
"index.html#dont-set-zig-default-flags"
],
"zig-similar-variables": [
"index.html#zig-similar-variables",
"index.html#zig-hook-similar-variables"
],
"zig-hook-variables-honored": [
"zig-variables-honored": [
"index.html#zig-variables-honored",
"index.html#zig-hook-variables-honored"
],
"xcbuildhook": [
Expand Down
15 changes: 7 additions & 8 deletions pkgs/by-name/fl/flow-control/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
callPackage,
}:

let
zig_hook = zig_0_15.hook.overrideAttrs {
zig_default_flags = "-Dcpu=baseline -Doptimize=ReleaseSafe --color off";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "flow-control";
version = "0.6.0";
Expand All @@ -29,12 +24,16 @@ stdenv.mkDerivation (finalAttrs: {
} $ZIG_GLOBAL_CACHE_DIR/p
'';

nativeBuildInputs = [
zig_hook
];
nativeBuildInputs = [ zig_0_15 ];

passthru.updateScript = ./update.sh;

dontSetZigDefaultFlags = true;
zigBuildFlags = [
"-Dcpu=baseline"
"-Doptimize=ReleaseSafe"
];

env.VERSION = finalAttrs.version;

meta = {
Expand Down
12 changes: 5 additions & 7 deletions pkgs/by-name/gh/ghostty/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@
# https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/PACKAGING.md#build-options
optimizeLevel ? "ReleaseFast",
}:
let
zig = zig_0_14;

zig_hook = zig.hook.overrideAttrs {
zig_default_flags = "-Dcpu=baseline -Doptimize=${optimizeLevel} --color off";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty";
version = "1.2.3";
Expand Down Expand Up @@ -66,7 +60,7 @@ stdenv.mkDerivation (finalAttrs: {
pandoc
pkg-config
removeReferencesTo
zig_hook
zig_0_14

# GTK frontend
glib # Required for `glib-compile-schemas`
Expand All @@ -93,10 +87,14 @@ stdenv.mkDerivation (finalAttrs: {
harfbuzz
];

dontSetZigDefaultFlags = true;

zigBuildFlags = [
"--system"
"${finalAttrs.deps}"
"-Dversion-string=${finalAttrs.version}"
"-Dcpu=baseline"
"-Doptimize=${optimizeLevel}"
]
++ lib.mapAttrsToList (name: package: "-fsys=${name} --search-prefix ${lib.getLib package}") {
inherit glslang;
Expand Down
7 changes: 4 additions & 3 deletions pkgs/by-name/ro/roc/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ rustPlatform.buildRustPackage {
hash = "sha256-pPnOM4hpbAkGCV47aw5eHbpOujjFtJa3v/3/D8gybO8=";
};

dontUseZigBuild = true;
dontUseZigCheck = true;
dontUseZigInstall = true;

nativeBuildInputs = [
cmake
zig_0_13
Expand All @@ -53,9 +57,6 @@ rustPlatform.buildRustPackage {

cargoHash = "sha256-wJViSHcezoIchWe4Py9j+9U+YJUA5ja/x94UipuWO2g=";

# prevents zig AccessDenied error github.com/ziglang/zig/issues/6810
XDG_CACHE_HOME = "xdg_cache";

preBuild =
let
llvmVersion = builtins.splitVersion llvmPackages.release_version;
Expand Down
12 changes: 5 additions & 7 deletions pkgs/by-name/zf/zf/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
callPackage,
}:

let
zig = zig_0_15;
zig_hook = zig.hook.overrideAttrs {
zig_default_flags = "-Dcpu=baseline -Doptimize=ReleaseFast --color off";
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "zf";
upstreamVersion = "0.10.3";
Expand All @@ -29,16 +23,20 @@ stdenv.mkDerivation (finalAttrs: {

nativeBuildInputs = [
installShellFiles
zig_hook
zig_0_15
];

deps = callPackage ./deps.nix {
name = "${finalAttrs.pname}-cache-${finalAttrs.version}";
};

dontSetZigDefaultFlags = true;

zigBuildFlags = [
"--system"
"${finalAttrs.deps}"
"-Dcpu=baseline"
"-Doptimize=ReleaseFast"
];

postInstall = ''
Expand Down
40 changes: 37 additions & 3 deletions pkgs/development/compilers/zig/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
cmake,
llvmPackages,
xcbuild,
targetPackages,
libxml2,
ninja,
zlib,
Expand Down Expand Up @@ -126,17 +125,52 @@ stdenv.mkDerivation (finalAttrs: {

passthru = import ./passthru.nix {
inherit
lib
stdenv
callPackage
wrapCCWith
wrapBintoolsWith
overrideCC
targetPackages
;
zig = finalAttrs.finalPackage;
};

env = {
# This zig_default_optimize_flag 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_cpu_flag = "-Dcpu=baseline";

zig_default_optimize_flag =
if lib.versionAtLeast finalAttrs.version "0.12" then
"--release=safe"
else if lib.versionAtLeast finalAttrs.version "0.11" then
"-Doptimize=ReleaseSafe"
else
"-Drelease-safe=true";
};

setupHook = ./setup-hook.sh;

# while xcrun is already included in the darwin stdenv, Zig also needs
# xcode-select (provided by xcbuild) for SDK detection
propagatedNativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ];

meta = {
description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
homepage = "https://ziglang.org/";
Expand Down
60 changes: 0 additions & 60 deletions pkgs/development/compilers/zig/hook.nix

This file was deleted.

6 changes: 3 additions & 3 deletions pkgs/development/compilers/zig/passthru.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
lib,
stdenv,
zig,
callPackage,
wrapCCWith,
wrapBintoolsWith,
overrideCC,
targetPackages,
}:
{
hook = callPackage ./hook.nix { inherit zig; };
# Provided for backward compatibility, as the `zig` derivation now sets
# setupHook.
hook = zig;

bintools-unwrapped = callPackage ./bintools.nix { inherit zig; };
bintools = wrapBintoolsWith { bintools = zig.bintools-unwrapped; };
Expand Down
Loading
Loading