From c10ea61e0eade6bf7c92427c2e1c6ba93b80c0de Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Wed, 5 Jul 2023 11:22:03 -0600 Subject: [PATCH 1/8] Initial buildZigPackage Co-authored-by: figsoda Co-authored-by: Anderson Torres Co-authored-by: roberth Co-authored-by: fortuneteller2k --- .../zig/build-zig-package/default.nix | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pkgs/build-support/zig/build-zig-package/default.nix diff --git a/pkgs/build-support/zig/build-zig-package/default.nix b/pkgs/build-support/zig/build-zig-package/default.nix new file mode 100644 index 00000000000000..032c2d92b72755 --- /dev/null +++ b/pkgs/build-support/zig/build-zig-package/default.nix @@ -0,0 +1,44 @@ +{ lib, stdenv, zig }: +argsFun: + +let + wrapDerivation = f: + stdenv.mkDerivation (finalAttrs: + f (lib.toFunction argsFun finalAttrs) + ); +in +wrapDerivation ( + { strictDeps ? true + , nativeBuildInputs ? [ ] + , meta ? { } + , ... + }@attrs: + + attrs // { + inherit strictDeps; + nativeBuildInputs = [ zig ] ++ nativeBuildInputs; + + buildPhase = attrs.buildPhase or '' + runHook preBuild + export ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) + zig build -Drelease-safe -Dcpu=baseline $zigBuildFlags + runHook postBuild + ''; + + checkPhase = attrs.checkPhase or '' + runHook preCheck + zig build test + runHook postCheck + ''; + + installPhase = attrs.installPhase or '' + runHook preInstall + zig build -Drelease-safe -Dcpu=baseline $zigBuildFlags --prefix $out install + runHook postInstall + ''; + + meta = { + inherit (zig.meta) platforms; + } // meta; + } +) From c23473b24b8445bb6adb09dc9674606e8e49fc68 Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Wed, 5 Jul 2023 21:51:28 -0600 Subject: [PATCH 2/8] colorstorm: Init at v2.0.0 Co-authored-by: Anderson Torres Co-authored-by: figsoda --- pkgs/applications/misc/colorstorm/default.nix | 20 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 pkgs/applications/misc/colorstorm/default.nix diff --git a/pkgs/applications/misc/colorstorm/default.nix b/pkgs/applications/misc/colorstorm/default.nix new file mode 100644 index 00000000000000..2b661f232cd9c3 --- /dev/null +++ b/pkgs/applications/misc/colorstorm/default.nix @@ -0,0 +1,20 @@ +{ lib, fetchFromGitHub, zig_0_9 }: + +zig_0_9.buildZigPackage rec { + pname = "colorstorm"; + version = "2.0.0"; + + src = fetchFromGitHub { + owner = "benbusby"; + repo = "colorstorm"; + rev = "v${version}"; + hash = "sha256-6+P+QQpP1jxsydqhVrZkjl1gaqNcx4kS2994hOBhtu8="; + }; + + meta = { + description = "A color theme generator for editors and terminal emulators"; + homepage = "https://github.com/benbusby/colorstorm"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d2ab93d3987b3a..cc6ce74d87ec4c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -485,6 +485,8 @@ with pkgs; colorpicker = callPackage ../tools/misc/colorpicker { }; + colorstorm = callPackage ../applications/misc/colorstorm { }; + comedilib = callPackage ../development/libraries/comedilib { }; commix = callPackage ../tools/security/commix { }; From 142f6c3b3424e78d1675f19598017c095eda122a Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Thu, 6 Jul 2023 13:42:33 -0600 Subject: [PATCH 3/8] linuxwave: update to use buildZigPackage --- pkgs/tools/audio/linuxwave/default.nix | 31 ++------------------------ 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/pkgs/tools/audio/linuxwave/default.nix b/pkgs/tools/audio/linuxwave/default.nix index 0b8bcc6ca331c2..b662121e250ceb 100644 --- a/pkgs/tools/audio/linuxwave/default.nix +++ b/pkgs/tools/audio/linuxwave/default.nix @@ -5,7 +5,7 @@ , zig }: -stdenv.mkDerivation rec { +zig.buildZigPackage rec { pname = "linuxwave"; version = "0.1.4"; @@ -19,37 +19,10 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ installShellFiles - zig ]; - postConfigure = '' - export XDG_CACHE_HOME=$(mktemp -d) - ''; - - buildPhase = '' - runHook preBuild - - zig build -Drelease-safe -Dcpu=baseline - - runHook postBuild - ''; - - checkPhase = '' - runHook preCheck - - zig build test - - runHook postCheck - ''; - - installPhase = '' - runHook preInstall - - zig build -Drelease-safe -Dcpu=baseline --prefix $out install - + postInstall = '' installManPage man/linuxwave.1 - - runHook postInstall ''; meta = with lib; { From 27f970771e29ea6db3a276e5779f53f2424b1d7c Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Thu, 6 Jul 2023 17:42:38 -0600 Subject: [PATCH 4/8] river: update to use buildZigPackage Co-authored-by: figsoda --- .../window-managers/river/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/window-managers/river/default.nix b/pkgs/applications/window-managers/river/default.nix index 439030f34da3c9..3c04f76d3d7348 100644 --- a/pkgs/applications/window-managers/river/default.nix +++ b/pkgs/applications/window-managers/river/default.nix @@ -1,5 +1,4 @@ { lib -, stdenv , fetchFromGitHub , zig , wayland @@ -18,7 +17,7 @@ , xwaylandSupport ? true }: -stdenv.mkDerivation rec { +zig.buildZigPackage rec { pname = "river"; version = "0.2.4"; @@ -30,7 +29,7 @@ stdenv.mkDerivation rec { fetchSubmodules = true; }; - nativeBuildInputs = [ zig wayland xwayland scdoc pkg-config ]; + nativeBuildInputs = [ wayland xwayland scdoc pkg-config ]; buildInputs = [ wayland-protocols @@ -44,16 +43,16 @@ stdenv.mkDerivation rec { ] ++ lib.optional xwaylandSupport libX11; dontConfigure = true; + strictDeps = false; # This needs to be disabled for the build to work. preBuild = '' export HOME=$TMPDIR ''; - installPhase = '' - runHook preInstall - zig build -Drelease-safe -Dcpu=baseline ${lib.optionalString xwaylandSupport "-Dxwayland"} -Dman-pages --prefix $out install + zigBuildFlags = [ "-Dman-pages" ] ++ lib.optional xwaylandSupport "-Dxwayland"; + + postInstall = '' install contrib/river.desktop -Dt $out/share/wayland-sessions - runHook postInstall ''; /* Builder patch install dir into river to get default config @@ -62,7 +61,7 @@ stdenv.mkDerivation rec { */ installFlags = [ "DESTDIR=$(out)" ]; - passthru.providedSessions = ["river"]; + passthru.providedSessions = [ "river" ]; meta = with lib; { changelog = "https://github.com/ifreund/river/releases/tag/v${version}"; From 547e6121657c936cf7de8a7d1bb411646b18f867 Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Thu, 6 Jul 2023 19:04:04 -0600 Subject: [PATCH 5/8] ncdu: update to use buildZigPackage --- pkgs/tools/misc/ncdu/default.nix | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pkgs/tools/misc/ncdu/default.nix b/pkgs/tools/misc/ncdu/default.nix index d535061cde6441..4d03735625fa67 100644 --- a/pkgs/tools/misc/ncdu/default.nix +++ b/pkgs/tools/misc/ncdu/default.nix @@ -1,6 +1,6 @@ { lib, stdenv, fetchurl, zig, ncurses }: -stdenv.mkDerivation rec { +zig.buildZigPackage rec { pname = "ncdu"; version = "2.2.2"; @@ -9,19 +9,8 @@ stdenv.mkDerivation rec { hash = "sha256-kNkgAk51Ixi0aXds5X4Ds8cC1JMprZglruqzbDur+ZM="; }; - XDG_CACHE_HOME="Cache"; # FIXME This should be set in stdenv - - nativeBuildInputs = [ - zig - ]; - buildInputs = [ ncurses ]; - PREFIX = placeholder "out"; - - # Avoid CPU feature impurity, see https://github.com/NixOS/nixpkgs/issues/169461 - ZIG_FLAGS = "-Drelease-safe -Dcpu=baseline"; - meta = with lib; { description = "Disk usage analyzer with an ncurses interface"; homepage = "https://dev.yorhel.nl/ncdu"; From b4a3df9c7be23ba516eadf53de7176ea82d8045c Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Thu, 6 Jul 2023 19:08:30 -0600 Subject: [PATCH 6/8] waylock: update to use buildZigPackage --- pkgs/applications/misc/waylock/default.nix | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pkgs/applications/misc/waylock/default.nix b/pkgs/applications/misc/waylock/default.nix index 499f1b44db4fb8..f8bc5f0d4a0b4b 100644 --- a/pkgs/applications/misc/waylock/default.nix +++ b/pkgs/applications/misc/waylock/default.nix @@ -9,7 +9,8 @@ , libxkbcommon , pam }: -stdenv.mkDerivation rec { + +zig.buildZigPackage rec { pname = "waylock"; version = "0.6.2"; @@ -21,7 +22,7 @@ stdenv.mkDerivation rec { fetchSubmodules = true; }; - nativeBuildInputs = [ zig wayland scdoc pkg-config ]; + nativeBuildInputs = [ wayland scdoc pkg-config ]; buildInputs = [ wayland-protocols @@ -30,16 +31,9 @@ stdenv.mkDerivation rec { ]; dontConfigure = true; + strictDeps = false; - preBuild = '' - export HOME=$TMPDIR - ''; - - installPhase = '' - runHook preInstall - zig build -Drelease-safe -Dman-pages -Dcpu=baseline --prefix $out install - runHook postInstall - ''; + zigBuildFlags = [ "-Dman-pages" ]; meta = with lib; { homepage = "https://github.com/ifreund/waylock"; From 277aa4934ea65154b60ae5384a492c702e3db01b Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Fri, 7 Jul 2023 10:55:21 -0600 Subject: [PATCH 7/8] Documentation for buildZigPackage Co-authored-by: Anderson Torres --- doc/languages-frameworks/index.md | 1 + doc/languages-frameworks/zig.section.md | 35 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 doc/languages-frameworks/zig.section.md diff --git a/doc/languages-frameworks/index.md b/doc/languages-frameworks/index.md index cdbf08f1791bf7..4d5a159cac2610 100644 --- a/doc/languages-frameworks/index.md +++ b/doc/languages-frameworks/index.md @@ -42,4 +42,5 @@ swift.section.md texlive.section.md titanium.section.md vim.section.md +zig.section.md ``` diff --git a/doc/languages-frameworks/zig.section.md b/doc/languages-frameworks/zig.section.md new file mode 100644 index 00000000000000..3e04f8764cb7c4 --- /dev/null +++ b/doc/languages-frameworks/zig.section.md @@ -0,0 +1,35 @@ +# Zig {#zig} + +## Overview {#zig-overview} + +The Zig compiler and a builder function are available in Nixpkgs. + +## Zig program packages in Nixpkgs {#zig-program-packages-in-nixpkgs} + +Zig programs can be built using `buildZigPackage`. This builder function is available under any Zig compiler version. + +The following example shows a Zig program. It uses Zig 0.9. +`buildZigPackage` *always* uses `-Drelease-safe -Dcpu=baseline` flags. + +```nix +{ lib, fetchFromGitHub, zig_0_9 }: + +zig_0_9.buildZigPackage rec { + pname = "colorstorm"; + version = "2.0.0"; + + src = fetchFromGitHub { + owner = "benbusby"; + repo = "colorstorm"; + rev = "v${version}"; + hash = "sha256-6+P+QQpP1jxsydqhVrZkjl1gaqNcx4kS2994hOBhtu8="; + }; +} +``` + +## `buildZigPackage` parameters {#buildzigpackage-parameters} + +All parameters from `stdenv.mkDerivation` function are still supported. The +following are specific to `buildZigPackage`: + +* `zigBuildFlags`: A list of strings holding the build flags passed to Zig compiler. By default it is empty. From a31e2342b4feed0775d64533ba4bbe0f321f8245 Mon Sep 17 00:00:00 2001 From: IogaMaster Date: Sat, 8 Jul 2023 21:13:20 -0600 Subject: [PATCH 8/8] Add zig passthru to use buildZigPackage --- pkgs/development/compilers/zig/0.10.nix | 5 +++++ pkgs/development/compilers/zig/0.9.1.nix | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pkgs/development/compilers/zig/0.10.nix b/pkgs/development/compilers/zig/0.10.nix index 784cae916e3464..e6faae637f9237 100644 --- a/pkgs/development/compilers/zig/0.10.nix +++ b/pkgs/development/compilers/zig/0.10.nix @@ -81,6 +81,11 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstallCheck ''; + passthru.buildZigPackage = import ../../../build-support/zig/build-zig-package/default.nix { + inherit lib stdenv; + zig = finalAttrs.finalPackage; + }; + meta = { homepage = "https://ziglang.org/"; description = diff --git a/pkgs/development/compilers/zig/0.9.1.nix b/pkgs/development/compilers/zig/0.9.1.nix index 908d9a49cd6c1f..45e8e4360029b5 100644 --- a/pkgs/development/compilers/zig/0.9.1.nix +++ b/pkgs/development/compilers/zig/0.9.1.nix @@ -74,6 +74,11 @@ stdenv.mkDerivation (finalAttrs: { runHook postCheck ''; + passthru.buildZigPackage = import ../../../build-support/zig/build-zig-package/default.nix { + inherit lib stdenv; + zig = finalAttrs.finalPackage; + }; + meta = { homepage = "https://ziglang.org/"; description =