diff --git a/pkgs/shells/nushell/plugins/dbus.nix b/pkgs/shells/nushell/plugins/dbus.nix index d989b61def66e..14fd578eb0199 100644 --- a/pkgs/shells/nushell/plugins/dbus.nix +++ b/pkgs/shells/nushell/plugins/dbus.nix @@ -19,7 +19,7 @@ rustPlatform.buildRustPackage (finalAttrs: { hash = "sha256-Ga+1zFwS/v+3iKVEz7TFmJjyBW/gq6leHeyH2vjawto="; }; - cargoHash = "sha256-7pD5LA1ytO7VqFnHwgf7vW9eS3olnZBgdsj+rmcHkbU="; + cargoHash = "sha256-/ViKfnC8PVffT0CP0rlN9SlOnFuZOb2U5qwtPZIdhDU="; nativeBuildInputs = [ pkg-config ] ++ lib.optionals stdenv.cc.isClang [ rustPlatform.bindgenHook ]; buildInputs = [ dbus ]; @@ -33,8 +33,5 @@ rustPlatform.buildRustPackage (finalAttrs: { license = lib.licenses.mit; maintainers = with lib.maintainers; [ aftix ]; platforms = lib.platforms.linux; - # "Plugin `dbus` is compiled for nushell version 0.101.0, which is not - # compatible with version 0.105.1" - broken = true; }; }) diff --git a/pkgs/shells/nushell/plugins/default.nix b/pkgs/shells/nushell/plugins/default.nix index b8424c75b3bfa..3caebe57ff072 100644 --- a/pkgs/shells/nushell/plugins/default.nix +++ b/pkgs/shells/nushell/plugins/default.nix @@ -6,6 +6,11 @@ versionCheckHook, nushell, runCommand, + rustPlatform, + cargo, + cargo-edit, + jq, + semver-tool, }: lib.makeScope newScope ( @@ -15,6 +20,69 @@ lib.makeScope newScope ( ( _n: p: let + withNushellVersionAutoPatch = p.overrideAttrs ( + final: prev: { + cargoDeps = + (rustPlatform.fetchCargoVendor ({ + inherit (prev) src; + name = "${prev.pname}-${prev.version}"; + hash = prev.cargoHash; + nativeBuildInputs = [ + cargo + cargo-edit + jq + semver-tool + ]; + + postPatch = '' + root_cargo_toml="$(cargo locate-project --workspace --message-format=plain)" + root_cargo_dir="$(dirname "$root_cargo_toml")" + + is_compatible() { + local name="$1" want="$2" + [ -f "$root_cargo_dir/Cargo.lock" ] || return 1 + + local locked="$( + cargo metadata --format-version=1 | \ + jq -r '.packages[] | select(.name=="$name") | .version' + )" || return 1 + [ -z "$locked" ] && return 1 + + case "$(semver diff "$want" "$locked")" in + major) return 1 ;; + minor) return 1 ;; + *) return 0 ;; + esac + } + + if is_compatible nu-plugin "${nushell.version}"; then + echo "nu-plugin is compatible, no patching needed" + else + cargo upgrade -p nu-plugin@${nushell.version} -p nu-protocol@${nushell.version} + cargo generate-lockfile + export NUSHELL_VERSION_UPGRADED=1 + fi + ''; + + postBuild = '' + if ! [ -z "''${NUSHELL_VERSION_UPGRADED}" ]; then + cp Cargo.toml $out/Cargo.toml + fi + ''; + })).overrideAttrs + (old: { + buildCommand = old.buildCommand + '' + cp $vendorStaging/Cargo.toml $out/Cargo.toml || true + ''; + }); + + postPatch = '' + cp ${final.cargoDeps}/Cargo.lock ./Cargo.lock + cp ${final.cargoDeps}/Cargo.toml ./Cargo.toml || true + ''; + } + ); + # add two checks: # - `versionCheckhook`, checks wether it's a binary that is able to # display its own version @@ -22,7 +90,7 @@ lib.makeScope newScope ( # to detect incompatibilities (plugins are compiled for very specific # versions of nushell). If this fails, either update the plugin or mark # as broken. - withChecks = p.overrideAttrs ( + withChecks = withNushellVersionAutoPatch.overrideAttrs ( final: _prev: { doInstallCheck = true; nativeInstallCheckInputs = [ versionCheckHook ]; diff --git a/pkgs/shells/nushell/plugins/net.nix b/pkgs/shells/nushell/plugins/net.nix index 93d5daf4c8c9e..f6fba179d0913 100644 --- a/pkgs/shells/nushell/plugins/net.nix +++ b/pkgs/shells/nushell/plugins/net.nix @@ -17,7 +17,7 @@ rustPlatform.buildRustPackage (finalAttrs: { hash = "sha256-HiNydU40FprxVmRRZtnXom2kFYI04mbeuGTq8+BMh7o="; }; - cargoHash = "sha256-tq0XqY2B7tC2ep8vH6T3nkAqxqhniqzYnhbkfB3SbHU="; + cargoHash = "sha256-ZIyWsA7WFX/NeSSEd8Nkp2tWehT/nih+FSs3UTs8jZo="; nativeBuildInputs = lib.optionals stdenv.cc.isClang [ rustPlatform.bindgenHook ]; @@ -32,8 +32,5 @@ rustPlatform.buildRustPackage (finalAttrs: { license = lib.licenses.mit; maintainers = with lib.maintainers; [ happysalada ]; mainProgram = "nu_plugin_net"; - # "Plugin `net` is compiled for nushell version 0.104.0, which is not - # compatible with version 0.105.1" - broken = true; }; }) diff --git a/pkgs/shells/nushell/plugins/units.nix b/pkgs/shells/nushell/plugins/units.nix index 542c26f223fd8..b6eae9dc3b9a7 100644 --- a/pkgs/shells/nushell/plugins/units.nix +++ b/pkgs/shells/nushell/plugins/units.nix @@ -18,7 +18,7 @@ rustPlatform.buildRustPackage (finalAttrs: { hash = "sha256-4donh0UlBbaEwgDxUECKTPWGLuAc9KUmrRty2Ob7ZMA="; }; - cargoHash = "sha256-MjalDrjJTAHay9zcPhA8br2tOkkIzE4etL+yF5MKetY="; + cargoHash = "sha256-8/ubL2s49y8mqXFJBs9gA0U889k8Bx6UfAy77jJx6TM="; nativeBuildInputs = [ pkg-config ] ++ lib.optionals stdenv.cc.isClang [ rustPlatform.bindgenHook ];