From de57db2293d1a0d474dd141e095f8675cbf08e15 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 3 Jun 2025 17:22:33 -0700 Subject: [PATCH 01/13] treewide: set meta.mainProgram for buildGraalvmNativeImage users --- pkgs/by-name/cl/clj-kondo/package.nix | 1 + pkgs/by-name/cl/clojure-lsp/package.nix | 1 + pkgs/by-name/je/jet/package.nix | 1 + pkgs/by-name/sc/scala-update/package.nix | 1 + 4 files changed, 4 insertions(+) diff --git a/pkgs/by-name/cl/clj-kondo/package.nix b/pkgs/by-name/cl/clj-kondo/package.nix index f2d772b9fd66..1649ccada122 100644 --- a/pkgs/by-name/cl/clj-kondo/package.nix +++ b/pkgs/by-name/cl/clj-kondo/package.nix @@ -31,5 +31,6 @@ buildGraalvmNativeImage rec { jlesquembre bandresen ]; + mainProgram = "clj-kondo"; }; } diff --git a/pkgs/by-name/cl/clojure-lsp/package.nix b/pkgs/by-name/cl/clojure-lsp/package.nix index 695ada8c5491..f8e266560628 100644 --- a/pkgs/by-name/cl/clojure-lsp/package.nix +++ b/pkgs/by-name/cl/clojure-lsp/package.nix @@ -80,5 +80,6 @@ buildGraalvmNativeImage rec { sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; license = lib.licenses.mit; maintainers = [ lib.maintainers.ericdallo ]; + mainProgram = "clojure-lsp"; }; } diff --git a/pkgs/by-name/je/jet/package.nix b/pkgs/by-name/je/jet/package.nix index de4c48c353ae..6358674e40a4 100644 --- a/pkgs/by-name/je/jet/package.nix +++ b/pkgs/by-name/je/jet/package.nix @@ -34,5 +34,6 @@ buildGraalvmNativeImage rec { sourceProvenance = with sourceTypes; [ binaryBytecode ]; license = licenses.epl10; maintainers = with maintainers; [ ericdallo ]; + mainProgram = "jet"; }; } diff --git a/pkgs/by-name/sc/scala-update/package.nix b/pkgs/by-name/sc/scala-update/package.nix index 451447617cb7..849dcc6c327d 100644 --- a/pkgs/by-name/sc/scala-update/package.nix +++ b/pkgs/by-name/sc/scala-update/package.nix @@ -52,5 +52,6 @@ buildGraalvmNativeImage { homepage = "https://github.com/kitlangton/scala-update"; license = licenses.asl20; maintainers = [ maintainers.rtimush ]; + mainProgram = "scala-update"; }; } From 4d134f63fdebb45b9f723c99f635617c8acf50e9 Mon Sep 17 00:00:00 2001 From: Benjamin Sparks Date: Tue, 3 Jun 2025 18:57:45 +0200 Subject: [PATCH 02/13] buildGraalvmNativeImage: use lib.extendMkDerivation Co-authored-by: Philip Taron --- .../build-graalvm-native-image/default.nix | 170 ++++++++++-------- pkgs/top-level/all-packages.nix | 5 +- 2 files changed, 92 insertions(+), 83 deletions(-) diff --git a/pkgs/build-support/build-graalvm-native-image/default.nix b/pkgs/build-support/build-graalvm-native-image/default.nix index e1e4df52f02a..fc7bf7741601 100644 --- a/pkgs/build-support/build-graalvm-native-image/default.nix +++ b/pkgs/build-support/build-graalvm-native-image/default.nix @@ -2,95 +2,107 @@ lib, stdenv, glibcLocales, - # The GraalVM derivation to use - graalvmDrv, removeReferencesTo, - executable ? args.pname, - # JAR used as input for GraalVM derivation, defaults to src - jar ? args.src, - dontUnpack ? (jar == args.src), - # Default native-image arguments. You probably don't want to set this, - # except in special cases. In most cases, use extraNativeBuildArgs instead - nativeImageBuildArgs ? [ - (lib.optionalString stdenv.hostPlatform.isDarwin "-H:-CheckToolchain") - (lib.optionalString ( - stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 - ) "-H:PageSize=64K") - "-H:Name=${executable}" - "-march=compatibility" - "--verbose" - ], - # Extra arguments to be passed to the native-image - extraNativeImageBuildArgs ? [ ], - # XMX size of GraalVM during build - graalvmXmx ? "-J-Xmx6g", - meta ? { }, - LC_ALL ? "en_US.UTF-8", - ... -}@args: + graalvmPackages, +}: -let - extraArgs = builtins.removeAttrs args [ - "lib" - "stdenv" - "glibcLocales" - "jar" - "dontUnpack" - "LC_ALL" - "meta" - "buildPhase" - "nativeBuildInputs" - "installPhase" - "postInstall" +lib.extendMkDerivation { + constructDrv = stdenv.mkDerivation; + + excludeDrvArgNames = [ + "executable" + "extraNativeImageBuildArgs" + "graalvmDrv" + "graalvmXmx" + "nativeImageBuildArgs" ]; -in -stdenv.mkDerivation ( - { - inherit dontUnpack jar; - env = { inherit LC_ALL; }; + extendDrvArgs = + finalAttrs: + { + dontUnpack ? true, + strictDeps ? true, + __structuredAttrs ? true, - nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ - graalvmDrv - glibcLocales - removeReferencesTo - ]; + # The GraalVM derivation to use + graalvmDrv ? graalvmPackages.graalvm-ce, - nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ]; + executable ? finalAttrs.meta.mainProgram, - buildPhase = - args.buildPhase or '' - runHook preBuild + # Default native-image arguments. You probably don't want to set this, + # except in special cases. In most cases, use extraNativeBuildArgs instead + nativeImageBuildArgs ? [ + (lib.optionalString stdenv.hostPlatform.isDarwin "-H:-CheckToolchain") + (lib.optionalString ( + stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 + ) "-H:PageSize=64K") + "-H:Name=${executable}" + "-march=compatibility" + "--verbose" + ], - native-image -jar "$jar" ''${nativeImageBuildArgs[@]} + # Extra arguments to be passed to the native-image + extraNativeImageBuildArgs ? [ ], - runHook postBuild + # XMX size of GraalVM during build + graalvmXmx ? "-J-Xmx6g", + + env ? { }, + meta ? { }, + passthru ? { }, + ... + }@args: + { + env = { + LC_ALL = "en_US.UTF-8"; + } // env; + + inherit dontUnpack strictDeps __structuredAttrs; + + nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ + graalvmDrv + glibcLocales + removeReferencesTo + ]; + + # `nativeBuildInputs` does not allow `graalvmDrv`'s propagatedBuildInput to reach here this package. + # As its `propagatedBuildInputs` is required for the build process with `native-image`, we must add it here as well. + buildInputs = [ graalvmDrv ]; + + nativeImageArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ]; + + buildPhase = + args.buildPhase or '' + runHook preBuild + + native-image -jar "$src" ''${nativeImageArgs[@]} + + runHook postBuild + ''; + + installPhase = + args.installPhase or '' + runHook preInstall + + install -Dm755 ${executable} -t $out/bin + + runHook postInstall + ''; + + postInstall = '' + remove-references-to -t ${graalvmDrv} $out/bin/${executable} + ${args.postInstall or ""} ''; - installPhase = - args.installPhase or '' - runHook preInstall + disallowedReferences = [ graalvmDrv ]; - install -Dm755 ${executable} -t $out/bin + passthru = { + inherit graalvmDrv; + } // passthru; - runHook postInstall - ''; - - postInstall = '' - remove-references-to -t ${graalvmDrv} $out/bin/${executable} - ${args.postInstall or ""} - ''; - - disallowedReferences = [ graalvmDrv ]; - - passthru = { inherit graalvmDrv; }; - - meta = { - # default to graalvm's platforms - platforms = graalvmDrv.meta.platforms; - # default to executable name - mainProgram = executable; - } // meta; - } - // extraArgs -) + meta = { + # default to graalvm's platforms + inherit (graalvmDrv.meta) platforms; + } // meta; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 899a667a781e..a8730f478569 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5747,10 +5747,7 @@ with pkgs; openjdk_headless = jdk_headless; graalvmPackages = recurseIntoAttrs (callPackage ../development/compilers/graalvm { }); - buildGraalvmNativeImage = - (callPackage ../build-support/build-graalvm-native-image { - graalvmDrv = graalvmPackages.graalvm-ce; - }).override; + buildGraalvmNativeImage = callPackage ../build-support/build-graalvm-native-image { }; openshot-qt = libsForQt5.callPackage ../applications/video/openshot-qt { }; From 0f068090001d7f850f6266480146f682d7973ea1 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 3 Jun 2025 17:34:48 -0700 Subject: [PATCH 03/13] certificate-ripper: refactor to finalAttrs style --- .../by-name/ce/certificate-ripper/package.nix | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pkgs/by-name/ce/certificate-ripper/package.nix b/pkgs/by-name/ce/certificate-ripper/package.nix index 97e43c693096..ece2a2fa1186 100644 --- a/pkgs/by-name/ce/certificate-ripper/package.nix +++ b/pkgs/by-name/ce/certificate-ripper/package.nix @@ -5,18 +5,18 @@ buildGraalvmNativeImage, }: -let +buildGraalvmNativeImage (finalAttrs: { pname = "certificate-ripper"; version = "2.4.1"; - jar = maven.buildMavenPackage { - pname = "${pname}-jar"; - inherit version; + src = maven.buildMavenPackage { + pname = "certificate-ripper-jar"; + inherit (finalAttrs) version; src = fetchFromGitHub { owner = "Hakky54"; repo = "certificate-ripper"; - tag = version; + tag = finalAttrs.version; hash = "sha256-qQ5BHH+DT1sGNDGzSbclqc6+byBxyP16qvm3k9E/Yks="; }; @@ -46,13 +46,6 @@ let install -Dm644 target/crip.jar $out ''; }; -in -buildGraalvmNativeImage { - inherit pname version; - - src = jar; - - executable = "crip"; # Copied from pom.xml extraNativeImageBuildArgs = [ @@ -62,10 +55,11 @@ buildGraalvmNativeImage { ]; meta = { - changelog = "https://github.com/Hakky54/certificate-ripper/releases/tag/${jar.src.tag}"; + changelog = "https://github.com/Hakky54/certificate-ripper/releases/tag/${finalAttrs.version}"; description = "CLI tool to extract server certificates"; homepage = "https://github.com/Hakky54/certificate-ripper"; license = lib.licenses.asl20; maintainers = with lib.maintainers; [ tomasajt ]; + mainProgram = "crip"; }; -} +}) From 9fbc73c29934441173dbcf1930dc246c114e569d Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 3 Jun 2025 17:36:35 -0700 Subject: [PATCH 04/13] clj-kondo: refactor to finalAttrs style --- pkgs/by-name/cl/clj-kondo/package.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/cl/clj-kondo/package.nix b/pkgs/by-name/cl/clj-kondo/package.nix index 1649ccada122..de4c204c81e8 100644 --- a/pkgs/by-name/cl/clj-kondo/package.nix +++ b/pkgs/by-name/cl/clj-kondo/package.nix @@ -1,21 +1,18 @@ { lib, buildGraalvmNativeImage, - graalvmPackages, fetchurl, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "clj-kondo"; version = "2025.06.05"; src = fetchurl { - url = "https://github.com/clj-kondo/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar"; + url = "https://github.com/clj-kondo/clj-kondo/releases/download/v${finalAttrs.version}/clj-kondo-${finalAttrs.version}-standalone.jar"; sha256 = "sha256-jmQFiL8MFIuMrHPSxW27E7yZIGf+k8J5nFVXgNGIKoM="; }; - graalvmDrv = graalvmPackages.graalvm-ce; - extraNativeImageBuildArgs = [ "-H:+ReportExceptionStackTraces" "--no-fallback" @@ -26,11 +23,11 @@ buildGraalvmNativeImage rec { homepage = "https://github.com/clj-kondo/clj-kondo"; sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; license = lib.licenses.epl10; - changelog = "https://github.com/clj-kondo/clj-kondo/blob/v${version}/CHANGELOG.md"; + changelog = "https://github.com/clj-kondo/clj-kondo/blob/v${finalAttrs.version}/CHANGELOG.md"; maintainers = with lib.maintainers; [ jlesquembre bandresen ]; mainProgram = "clj-kondo"; }; -} +}) From c6180d044df563c92834805c7e8882ec358b78f7 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 08:56:48 -0700 Subject: [PATCH 05/13] cljfmt: refactor to finalAttrs style --- pkgs/by-name/cl/cljfmt/package.nix | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/cl/cljfmt/package.nix b/pkgs/by-name/cl/cljfmt/package.nix index eee267c6bdef..ccc7cac8f6b8 100644 --- a/pkgs/by-name/cl/cljfmt/package.nix +++ b/pkgs/by-name/cl/cljfmt/package.nix @@ -4,15 +4,14 @@ fetchurl, nix-update-script, testers, - cljfmt, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "cljfmt"; version = "0.13.1"; src = fetchurl { - url = "https://github.com/weavejester/cljfmt/releases/download/${version}/cljfmt-${version}-standalone.jar"; + url = "https://github.com/weavejester/cljfmt/releases/download/${finalAttrs.version}/cljfmt-${finalAttrs.version}-standalone.jar"; hash = "sha256-Dj1g6hMzRhqm0pJggODVFgEkayB2Wdh3d0z6RglHbgY="; }; @@ -28,8 +27,8 @@ buildGraalvmNativeImage rec { passthru.updateScript = nix-update-script { }; passthru.tests.version = testers.testVersion { - inherit version; - package = cljfmt; + inherit (finalAttrs) version; + package = finalAttrs.finalPackage; command = "cljfmt --version"; }; @@ -39,7 +38,7 @@ buildGraalvmNativeImage rec { homepage = "https://github.com/weavejester/cljfmt"; sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; license = lib.licenses.epl10; - changelog = "https://github.com/weavejester/cljfmt/blob/${version}/CHANGELOG.md"; + changelog = "https://github.com/weavejester/cljfmt/blob/${finalAttrs.version}/CHANGELOG.md"; maintainers = with lib.maintainers; [ sg-qwt ]; }; -} +}) From 85238bccd05092b1e7f82acfd86068ba6df685eb Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:02:03 -0700 Subject: [PATCH 06/13] cljstyle: refactor to finalAttrs style --- pkgs/by-name/cl/cljstyle/package.nix | 34 ++++++++++++---------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/pkgs/by-name/cl/cljstyle/package.nix b/pkgs/by-name/cl/cljstyle/package.nix index f27f1bd57957..9685a24151bd 100644 --- a/pkgs/by-name/cl/cljstyle/package.nix +++ b/pkgs/by-name/cl/cljstyle/package.nix @@ -3,50 +3,44 @@ buildGraalvmNativeImage, fetchMavenArtifact, fetchurl, - graalvmPackages, versionCheckHook, }: -let +buildGraalvmNativeImage (finalAttrs: { pname = "cljstyle"; version = "0.17.642"; - # must be on classpath to build native image - graal-build-time = fetchMavenArtifact { - repos = [ "https://repo.clojars.org/" ]; - groupId = "com.github.clj-easy"; - artifactId = "graal-build-time"; - version = "1.0.5"; - hash = "sha256-M6/U27a5n/QGuUzGmo8KphVnNa2K+LFajP5coZiFXoY="; - }; -in -buildGraalvmNativeImage { - inherit pname version; - src = fetchurl { - url = "https://github.com/greglook/${pname}/releases/download/${version}/${pname}-${version}.jar"; + url = "https://github.com/greglook/cljstyle/releases/download/${finalAttrs.version}/cljstyle-${finalAttrs.version}.jar"; hash = "sha256-AkCuTZeDXbNBuwPZEMhYGF/oOGIKq5zVDwL8xwnj+mE="; }; - graalvmDrv = graalvmPackages.graalvm-ce; - extraNativeImageBuildArgs = [ "-H:+ReportExceptionStackTraces" "--no-fallback" - "-cp ${graal-build-time.passthru.jar}" + "-cp ${finalAttrs.finalPackage.passthru.graal-build-time.passthru.jar}" ]; doInstallCheck = true; nativeInstallCheckInputs = [ versionCheckHook ]; versionCheckProgramArg = [ "version" ]; + # must be on classpath to build native image + passthru.graal-build-time = fetchMavenArtifact { + repos = [ "https://repo.clojars.org/" ]; + groupId = "com.github.clj-easy"; + artifactId = "graal-build-time"; + version = "1.0.5"; + hash = "sha256-M6/U27a5n/QGuUzGmo8KphVnNa2K+LFajP5coZiFXoY="; + }; + meta = { description = "Tool for formatting Clojure code"; homepage = "https://github.com/greglook/cljstyle"; sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; license = lib.licenses.epl10; - changelog = "https://github.com/greglook/cljstyle/blob/${version}/CHANGELOG.md"; + changelog = "https://github.com/greglook/cljstyle/blob/${finalAttrs.version}/CHANGELOG.md"; maintainers = with lib.maintainers; [ psyclyx ]; mainProgram = "cljstyle"; }; -} +}) From 52ad747899555030d36f7f8750a33bd81f3b699e Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:05:42 -0700 Subject: [PATCH 07/13] clojure-lsp: refactor to finalAttrs style Also rewrite the update script to reflect that src is just a jar --- pkgs/by-name/cl/clojure-lsp/package.nix | 65 +++++++++++-------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/pkgs/by-name/cl/clojure-lsp/package.nix b/pkgs/by-name/cl/clojure-lsp/package.nix index f8e266560628..0ea8d752ba88 100644 --- a/pkgs/by-name/cl/clojure-lsp/package.nix +++ b/pkgs/by-name/cl/clojure-lsp/package.nix @@ -1,27 +1,20 @@ { lib, + stdenvNoCC, buildGraalvmNativeImage, fetchurl, fetchFromGitHub, writeScript, testers, - clojure-lsp, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "clojure-lsp"; - version = "2025.03.27-20.21.36"; + version = "2025.05.27-13.56.57"; - src = fetchFromGitHub { - owner = "clojure-lsp"; - repo = "clojure-lsp"; - rev = version; - hash = "sha256-xS/WVTJFCdktYxBvey855PW5Heqlx4EhpDAMHQ5Bj5M="; - }; - - jar = fetchurl { - url = "https://github.com/clojure-lsp/clojure-lsp/releases/download/${version}/clojure-lsp-standalone.jar"; - hash = "sha256-g8jX+41gojvoJHV/xMcP+4ROc9LewCUTuDTQcpHQ6+E="; + src = fetchurl { + url = "https://github.com/clojure-lsp/clojure-lsp/releases/download/${finalAttrs.version}/clojure-lsp-standalone.jar"; + hash = "sha256-CIly8eufuI/ENgiamKfhnFe+0dssDKEl4MYDJf4Sm/k="; }; extraNativeImageBuildArgs = [ @@ -33,22 +26,18 @@ buildGraalvmNativeImage rec { ]; doCheck = true; - checkPhase = - '' - runHook preCheck + checkPhase = '' + runHook preCheck - export HOME="$(mktemp -d)" - ./clojure-lsp --version | fgrep -q '${version}' - '' - # TODO: fix classpath issue per https://github.com/NixOS/nixpkgs/pull/153770 - #${babashka}/bin/bb integration-test ./clojure-lsp - + '' - runHook postCheck - ''; + export HOME="$(mktemp -d)" + ./clojure-lsp --version | fgrep -q '${finalAttrs.version}' + + runHook postCheck + ''; passthru.tests.version = testers.testVersion { - inherit version; - package = clojure-lsp; + inherit (finalAttrs) version; + package = finalAttrs.finalPackage; command = "clojure-lsp --version"; }; @@ -57,29 +46,33 @@ buildGraalvmNativeImage rec { #!nix-shell -i bash -p curl common-updater-scripts gnused jq nix set -eu -o pipefail + source "${stdenvNoCC}/setup" - latest_version=$(curl -s https://api.github.com/repos/clojure-lsp/clojure-lsp/releases/latest | jq --raw-output .tag_name) + old_version="$(nix-instantiate --strict --json --eval -A clojure-lsp.version | jq -r .)" + latest_version="$(curl -s https://api.github.com/repos/clojure-lsp/clojure-lsp/releases/latest | jq -r .tag_name)" - old_jar_hash=$(nix-instantiate --eval --strict -A "clojure-lsp.jar.drvAttrs.outputHash" | tr -d '"' | sed -re 's|[+]|\\&|g') + if [[ $latest_version == $old_version ]]; then + echo "Already at latest version $old_version" + exit 0 + fi - curl -o clojure-lsp-standalone.jar -sL https://github.com/clojure-lsp/clojure-lsp/releases/download/$latest_version/clojure-lsp-standalone.jar - new_jar_hash=$(nix-hash --flat --type sha256 clojure-lsp-standalone.jar | sed -re 's|[+]|\\&|g') + old_jar_hash="$(nix-instantiate --strict --json --eval -A clojure-lsp.jar.drvAttrs.outputHash | jq -r .)" + + curl -o clojure-lsp-standalone.jar -sL "https://github.com/clojure-lsp/clojure-lsp/releases/download/$latest_version/clojure-lsp-standalone.jar" + new_jar_hash="$(nix-hash --flat --type sha256 clojure-lsp-standalone.jar | xargs -n1 nix hash convert --hash-algo sha256)" rm -f clojure-lsp-standalone.jar - nixFile=$(nix-instantiate --eval --strict -A "clojure-lsp.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/') - - sed -i "$nixFile" -re "s|\"$old_jar_hash\"|\"$new_jar_hash\"|" - update-source-version clojure-lsp "$latest_version" + update-source-version clojure-lsp "$latest_version" "$new_jar_hash" ''; meta = { description = "Language Server Protocol (LSP) for Clojure"; homepage = "https://github.com/clojure-lsp/clojure-lsp"; - changelog = "https://github.com/clojure-lsp/clojure-lsp/releases/tag/${version}"; + changelog = "https://github.com/clojure-lsp/clojure-lsp/releases/tag/${finalAttrs.version}"; sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; license = lib.licenses.mit; maintainers = [ lib.maintainers.ericdallo ]; mainProgram = "clojure-lsp"; }; -} +}) From f8164fc556359ab915e84e9cbb09e086ff8a238b Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:08:31 -0700 Subject: [PATCH 08/13] cq: refactor to finalAttrs style --- pkgs/by-name/cq/cq/package.nix | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/cq/cq/package.nix b/pkgs/by-name/cq/cq/package.nix index 406a874b8748..d0b44ed69dfd 100644 --- a/pkgs/by-name/cq/cq/package.nix +++ b/pkgs/by-name/cq/cq/package.nix @@ -6,42 +6,39 @@ graalvmPackages, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "cq"; version = "2024.06.24-12.10"; # we need both src (the prebuild jar) src = fetchurl { - url = "https://github.com/markus-wa/cq/releases/download/${version}/cq.jar"; + url = "https://github.com/markus-wa/cq/releases/download/${finalAttrs.version}/cq.jar"; hash = "sha256-iULV+j/AuGVYPYhbOTQTKd3n+VZhWQYBRE6cRiaa1/M="; }; # and build-src (for the native-image build process) - build-src = fetchFromGitHub { + passthru.build-src = fetchFromGitHub { owner = "markus-wa"; repo = "cq"; - rev = version; + tag = finalAttrs.version; hash = "sha256-yjAC2obipdmh+JlHzVUTMtTXN2VKe4WKkyJyu2Q93c8="; }; - graalvmDrv = graalvmPackages.graalvm-ce; - - executable = "cq"; - # copied verbatim from the upstream build script https://github.com/markus-wa/cq/blob/main/package/build-native.sh#L5 extraNativeImageBuildArgs = [ "--report-unsupported-elements-at-runtime" "--initialize-at-build-time" "--no-server" - "-H:ReflectionConfigurationFiles=${build-src}/package/reflection-config.json" + "-H:ReflectionConfigurationFiles=${finalAttrs.finalPackage.build-src}/package/reflection-config.json" ]; meta = { description = "Clojure Query: A Command-line Data Processor for JSON, YAML, EDN, XML and more"; homepage = "https://github.com/markus-wa/cq"; - changelog = "https://github.com/markus-wa/cq/releases/releases/tag/${version}"; + changelog = "https://github.com/markus-wa/cq/releases/releases/tag/${finalAttrs.version}"; license = lib.licenses.epl20; maintainers = with lib.maintainers; [ farcaller ]; platforms = lib.platforms.unix; + mainProgram = "cq"; }; -} +}) From b823450524f99651eb6b0d1069a19ea4212a0fd0 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:10:46 -0700 Subject: [PATCH 09/13] jet: refactor to finalAttrs style --- pkgs/by-name/je/jet/package.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/je/jet/package.nix b/pkgs/by-name/je/jet/package.nix index 6358674e40a4..05acfa309648 100644 --- a/pkgs/by-name/je/jet/package.nix +++ b/pkgs/by-name/je/jet/package.nix @@ -3,15 +3,14 @@ buildGraalvmNativeImage, fetchurl, testers, - jet, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "jet"; version = "0.7.27"; src = fetchurl { - url = "https://github.com/borkdude/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar"; + url = "https://github.com/borkdude/jet/releases/download/v${finalAttrs.version}/jet-${finalAttrs.version}-standalone.jar"; sha256 = "sha256-250/1DBNCXlU1b4jjLUUOXI+uSbOyPXtBN1JJRpdmFc="; }; @@ -23,17 +22,17 @@ buildGraalvmNativeImage rec { ]; passthru.tests.version = testers.testVersion { - inherit version; - package = jet; + inherit (finalAttrs) version; + package = finalAttrs.finalPackage; command = "jet --version"; }; - meta = with lib; { + meta = { description = "CLI to transform between JSON, EDN, YAML and Transit, powered with a minimal query language"; homepage = "https://github.com/borkdude/jet"; - sourceProvenance = with sourceTypes; [ binaryBytecode ]; - license = licenses.epl10; - maintainers = with maintainers; [ ericdallo ]; + sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; + license = lib.licenses.epl10; + maintainers = with lib.maintainers; [ ericdallo ]; mainProgram = "jet"; }; -} +}) From 49b7a8f17fb8943fc43826cfe0cc167fac10dd45 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:18:01 -0700 Subject: [PATCH 10/13] scala-update: refactor to finalAttrs style --- pkgs/by-name/sc/scala-update/package.nix | 55 ++++++++++++------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/pkgs/by-name/sc/scala-update/package.nix b/pkgs/by-name/sc/scala-update/package.nix index 849dcc6c327d..015972f48009 100644 --- a/pkgs/by-name/sc/scala-update/package.nix +++ b/pkgs/by-name/sc/scala-update/package.nix @@ -1,33 +1,17 @@ { lib, - stdenv, + stdenvNoCC, coursier, buildGraalvmNativeImage, }: -let - baseName = "scala-update"; +buildGraalvmNativeImage (finalAttrs: { + pname = "scala-update"; version = "0.2.2"; - deps = stdenv.mkDerivation { - name = "${baseName}-deps-${version}"; - buildCommand = '' - export COURSIER_CACHE=$(pwd) - ${coursier}/bin/cs fetch io.github.kitlangton:scala-update_2.13:${version} > deps - mkdir -p $out/share/java - cp $(< deps) $out/share/java/ - ''; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; - outputHash = "kNnFzzHn+rFq4taqRYjBYaDax0MHW+vIoSFVN3wxA8M="; - }; -in -buildGraalvmNativeImage { - pname = baseName; - inherit version; - buildInputs = [ deps ]; + buildInputs = [ finalAttrs.finalPackage.passthru.deps ]; - src = "${deps}/share/java/${baseName}_2.13-${version}.jar"; + src = "${finalAttrs.finalPackage.passthru.deps}/share/java/scala-update_2.13-${finalAttrs.version}.jar"; extraNativeImageBuildArgs = [ "--no-fallback" @@ -38,20 +22,37 @@ buildGraalvmNativeImage { buildPhase = '' runHook preBuild - native-image ''${nativeImageBuildArgs[@]} -cp $(JARS=("${deps}/share/java"/*.jar); IFS=:; echo "''${JARS[*]}") + native-image ''${nativeImageArgs[@]} -cp $(JARS=("${finalAttrs.finalPackage.passthru.deps}/share/java"/*.jar); IFS=:; echo "''${JARS[*]}") runHook postBuild ''; installCheckPhase = '' - $out/bin/${baseName} --version | grep -q "${version}" + runHook preInstallCheck + + $out/bin/scala-update --version | grep -q "${finalAttrs.version}" + + runHook postInstallCheck ''; - meta = with lib; { + passthru.deps = stdenvNoCC.mkDerivation { + name = "scala-update-deps-${finalAttrs.version}"; + buildCommand = '' + export COURSIER_CACHE=$(pwd) + ${lib.getExe coursier} fetch io.github.kitlangton:scala-update_2.13:${finalAttrs.version} > deps + mkdir -p $out/share/java + cp $(< deps) $out/share/java/ + ''; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = "kNnFzzHn+rFq4taqRYjBYaDax0MHW+vIoSFVN3wxA8M="; + }; + + meta = { description = "Update your Scala dependencies interactively"; homepage = "https://github.com/kitlangton/scala-update"; - license = licenses.asl20; - maintainers = [ maintainers.rtimush ]; + license = lib.licenses.asl20; + maintainers = [ lib.maintainers.rtimush ]; mainProgram = "scala-update"; }; -} +}) From ac0bbfc54358bd8adebe21690864c92ee57e193b Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:20:55 -0700 Subject: [PATCH 11/13] yamlscript: refactor to finalAttrs style --- pkgs/by-name/ya/yamlscript/package.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/ya/yamlscript/package.nix b/pkgs/by-name/ya/yamlscript/package.nix index bc8a22a94442..b4b9c1f361d1 100644 --- a/pkgs/by-name/ya/yamlscript/package.nix +++ b/pkgs/by-name/ya/yamlscript/package.nix @@ -4,17 +4,15 @@ fetchurl, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "yamlscript"; version = "0.1.96"; src = fetchurl { - url = "https://github.com/yaml/yamlscript/releases/download/${version}/yamlscript.cli-${version}-standalone.jar"; + url = "https://github.com/yaml/yamlscript/releases/download/${finalAttrs.version}/yamlscript.cli-${finalAttrs.version}-standalone.jar"; hash = "sha256-nwqZhGOtNEJ0qzOTFdHFWBSyt4hmLhn6nhdCz2jyUbg="; }; - executable = "ys"; - extraNativeImageBuildArgs = [ "--native-image-info" "--no-fallback" @@ -30,15 +28,19 @@ buildGraalvmNativeImage rec { doInstallCheck = true; installCheckPhase = '' - $out/bin/ys -e 'say: (+ 1 2)' | fgrep 3 + runHook preInstallCheck + + $out/bin/ys -e 'say: (+ 1 2)' | fgrep 3 + + runHook postInstallCheck ''; - meta = with lib; { + meta = { description = "Programming in YAML"; homepage = "https://github.com/yaml/yamlscript"; - sourceProvenance = with sourceTypes; [ binaryBytecode ]; - license = licenses.mit; + sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; + license = lib.licenses.mit; mainProgram = "ys"; - maintainers = with maintainers; [ sgo ]; + maintainers = with lib.maintainers; [ sgo ]; }; -} +}) From 9a73deb300463e6bf0084c9c57fae10dbfe0033a Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:23:07 -0700 Subject: [PATCH 12/13] zprint: refactor to finalAttrs style --- pkgs/by-name/zp/zprint/package.nix | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/zp/zprint/package.nix b/pkgs/by-name/zp/zprint/package.nix index 39e105697bbf..0cc607d2af0f 100644 --- a/pkgs/by-name/zp/zprint/package.nix +++ b/pkgs/by-name/zp/zprint/package.nix @@ -3,15 +3,14 @@ buildGraalvmNativeImage, fetchurl, testers, - zprint, }: -buildGraalvmNativeImage rec { +buildGraalvmNativeImage (finalAttrs: { pname = "zprint"; version = "1.3.0"; src = fetchurl { - url = "https://github.com/kkinnear/${pname}/releases/download/${version}/${pname}-filter-${version}"; + url = "https://github.com/kkinnear/zprint/releases/download/${finalAttrs.version}/zprint-filter-${finalAttrs.version}"; sha256 = "sha256-0ogZkC8j+ja0aWvFgNhygof4GZ78aqQA75lRxYfu6do="; }; @@ -25,12 +24,12 @@ buildGraalvmNativeImage rec { ]; passthru.tests.version = testers.testVersion { - inherit version; - package = zprint; + inherit (finalAttrs) version; + package = finalAttrs.finalPackage; command = "zprint --version"; }; - meta = with lib; { + meta = { description = "Clojure/EDN source code formatter and pretty printer"; longDescription = '' Library and command line tool providing a variety of pretty printing capabilities @@ -38,8 +37,8 @@ buildGraalvmNativeImage rec { As such, it supports a number of major source code formatting approaches ''; homepage = "https://github.com/kkinnear/zprint"; - license = licenses.mit; - maintainers = with maintainers; [ stelcodes ]; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ stelcodes ]; mainProgram = "zprint"; }; -} +}) From f5eb7b94bc0e0d3369cfa4e86a6dff51a79919c8 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 4 Jun 2025 09:28:12 -0700 Subject: [PATCH 13/13] babashka-unwrapped: refactor to finalAttrs style --- .../interpreters/babashka/default.nix | 209 +++++++++--------- 1 file changed, 103 insertions(+), 106 deletions(-) diff --git a/pkgs/development/interpreters/babashka/default.nix b/pkgs/development/interpreters/babashka/default.nix index fb3cbec7ca5a..3ce4fdace727 100644 --- a/pkgs/development/interpreters/babashka/default.nix +++ b/pkgs/development/interpreters/babashka/default.nix @@ -1,116 +1,113 @@ { lib, buildGraalvmNativeImage, - graalvmPackages, fetchurl, writeScript, installShellFiles, }: -let - babashka-unwrapped = buildGraalvmNativeImage rec { - pname = "babashka-unwrapped"; - version = "1.12.200"; +buildGraalvmNativeImage (finalAttrs: { + pname = "babashka-unwrapped"; + version = "1.12.200"; - src = fetchurl { - url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar"; - sha256 = "sha256-hxcoVUaL19RM56fG8oxSKQwPHXDzaoSdCdHXSTXQ9fI="; - }; - - graalvmDrv = graalvmPackages.graalvm-ce; - - executable = "bb"; - - nativeBuildInputs = [ installShellFiles ]; - - extraNativeImageBuildArgs = [ - "-H:+ReportExceptionStackTraces" - "--no-fallback" - "--native-image-info" - "--enable-preview" - ]; - - doInstallCheck = true; - - installCheckPhase = '' - $out/bin/bb --version | fgrep '${version}' - $out/bin/bb '(+ 1 2)' | fgrep '3' - $out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | fgrep '[1 2]' - $out/bin/bb '(prn "bépo àê")' | fgrep 'bépo àê' - $out/bin/bb '(:out (babashka.process/sh "echo" "ä"))' | fgrep 'ä' - $out/bin/bb '(into-array [:f])' - ''; - - postInstall = '' - installShellCompletion --cmd bb --bash ${./completions/bb.bash} - installShellCompletion --cmd bb --zsh ${./completions/bb.zsh} - installShellCompletion --cmd bb --fish ${./completions/bb.fish} - ''; - - passthru.updateScript = writeScript "update-babashka" '' - #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl common-updater-scripts jq libarchive - - set -euo pipefail - shopt -s inherit_errexit - - latest_version="$(curl \ - ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ - -fsL "https://api.github.com/repos/babashka/babashka/releases/latest" \ - | jq -r '.tag_name')" - - if [ "$(update-source-version babashka-unwrapped "''${latest_version/v/}" --print-changes)" = "[]" ]; then - # no need to update babashka.clojure-tools when babashka-unwrapped wasn't updated - exit 0 - fi - - clojure_tools_version=$(curl \ - -fsL \ - "https://github.com/babashka/babashka/releases/download/''${latest_version}/babashka-''${latest_version/v/}-standalone.jar" \ - | bsdtar -qxOf - borkdude/deps.clj \ - | ${babashka-unwrapped}/bin/bb -I -o -e "(or (some->> *input* (filter #(= '(def version) (take 2 %))) first last last last) (throw (ex-info \"Couldn't find expected '(def version ...)' form in 'borkdude/deps.clj'.\" {})))") - - update-source-version babashka.clojure-tools "$clojure_tools_version" \ - --file="pkgs/development/interpreters/babashka/clojure-tools.nix" - ''; - - meta = with lib; { - description = "Clojure babushka for the grey areas of Bash"; - longDescription = '' - The main idea behind babashka is to leverage Clojure in places where you - would be using bash otherwise. - - As one user described it: - - I’m quite at home in Bash most of the time, but there’s a substantial - grey area of things that are too complicated to be simple in bash, but - too simple to be worth writing a clj/s script for. Babashka really - seems to hit the sweet spot for those cases. - - Goals: - - - Low latency Clojure scripting alternative to JVM Clojure. - - Easy installation: grab the self-contained binary and run. No JVM needed. - - Familiarity and portability: - - Scripts should be compatible with JVM Clojure as much as possible - - Scripts should be platform-independent as much as possible. Babashka - offers support for linux, macOS and Windows. - - Allow interop with commonly used classes like java.io.File and System - - Multi-threading support (pmap, future, core.async) - - Batteries included (tools.cli, cheshire, ...) - - Library support via popular tools like the clojure CLI - ''; - homepage = "https://github.com/babashka/babashka"; - changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md"; - sourceProvenance = with sourceTypes; [ binaryBytecode ]; - license = licenses.epl10; - maintainers = with maintainers; [ - bandresen - bhougland - DerGuteMoritz - jlesquembre - ]; - }; + src = fetchurl { + url = "https://github.com/babashka/babashka/releases/download/v${finalAttrs.version}/babashka-${finalAttrs.version}-standalone.jar"; + sha256 = "sha256-hxcoVUaL19RM56fG8oxSKQwPHXDzaoSdCdHXSTXQ9fI="; }; -in -babashka-unwrapped + + nativeBuildInputs = [ installShellFiles ]; + + extraNativeImageBuildArgs = [ + "-H:+ReportExceptionStackTraces" + "--no-fallback" + "--native-image-info" + "--enable-preview" + ]; + + doInstallCheck = true; + + installCheckPhase = '' + runHook preInstallCheck + + $out/bin/bb --version | fgrep '${finalAttrs.version}' + $out/bin/bb '(+ 1 2)' | fgrep '3' + $out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | fgrep '[1 2]' + $out/bin/bb '(prn "bépo àê")' | fgrep 'bépo àê' + $out/bin/bb '(:out (babashka.process/sh "echo" "ä"))' | fgrep 'ä' + $out/bin/bb '(into-array [:f])' + + runHook postInstallCheck + ''; + + postInstall = '' + installShellCompletion --cmd bb --bash ${./completions/bb.bash} + installShellCompletion --cmd bb --zsh ${./completions/bb.zsh} + installShellCompletion --cmd bb --fish ${./completions/bb.fish} + ''; + + passthru.updateScript = writeScript "update-babashka" '' + #!/usr/bin/env nix-shell + #!nix-shell -i bash -p curl common-updater-scripts jq libarchive + + set -euo pipefail + shopt -s inherit_errexit + + latest_version="$(curl \ + ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ + -fsL "https://api.github.com/repos/babashka/babashka/releases/latest" \ + | jq -r '.tag_name')" + + if [ "$(update-source-version babashka-unwrapped "''${latest_version/v/}" --print-changes)" = "[]" ]; then + # no need to update babashka.clojure-tools when babashka-unwrapped wasn't updated + exit 0 + fi + + clojure_tools_version=$(curl \ + -fsL \ + "https://github.com/babashka/babashka/releases/download/''${latest_version}/babashka-''${latest_version/v/}-standalone.jar" \ + | bsdtar -qxOf - borkdude/deps.clj \ + | ${lib.getExe finalAttrs.finalPackage} -I -o -e "(or (some->> *input* (filter #(= '(def version) (take 2 %))) first last last last) (throw (ex-info \"Couldn't find expected '(def version ...)' form in 'borkdude/deps.clj'.\" {})))") + + update-source-version babashka.clojure-tools "$clojure_tools_version" \ + --file="pkgs/development/interpreters/babashka/clojure-tools.nix" + ''; + + meta = { + description = "Clojure babushka for the grey areas of Bash"; + longDescription = '' + The main idea behind babashka is to leverage Clojure in places where you + would be using bash otherwise. + + As one user described it: + + I’m quite at home in Bash most of the time, but there’s a substantial + grey area of things that are too complicated to be simple in bash, but + too simple to be worth writing a clj/s script for. Babashka really + seems to hit the sweet spot for those cases. + + Goals: + + - Low latency Clojure scripting alternative to JVM Clojure. + - Easy installation: grab the self-contained binary and run. No JVM needed. + - Familiarity and portability: + - Scripts should be compatible with JVM Clojure as much as possible + - Scripts should be platform-independent as much as possible. Babashka + offers support for linux, macOS and Windows. + - Allow interop with commonly used classes like java.io.File and System + - Multi-threading support (pmap, future, core.async) + - Batteries included (tools.cli, cheshire, ...) + - Library support via popular tools like the clojure CLI + ''; + homepage = "https://github.com/babashka/babashka"; + changelog = "https://github.com/babashka/babashka/blob/v${finalAttrs.version}/CHANGELOG.md"; + sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; + license = lib.licenses.epl10; + mainProgram = "bb"; + maintainers = with lib.maintainers; [ + bandresen + bhougland + DerGuteMoritz + jlesquembre + ]; + }; +})