Skip to content
Draft
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
5 changes: 1 addition & 4 deletions pkgs/shells/nushell/plugins/dbus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -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;
};
})
70 changes: 69 additions & 1 deletion pkgs/shells/nushell/plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
versionCheckHook,
nushell,
runCommand,
rustPlatform,
cargo,
cargo-edit,
jq,
semver-tool,
}:

lib.makeScope newScope (
Expand All @@ -15,14 +20,77 @@ 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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to pin the exact version with an =-sign before the version. https://docs.rs/semver/latest/semver/enum.Op.html

Also, if you want to debug the reproducibility of this, you can probably use -v and CARGO_LOG=upgrade=trace to figure out what cargo commands it's calling under the hood and what versions it's selecting. cargo itself isn't that deterministic in and of itself though...

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
'';
Comment on lines +67 to +82

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we have to conditionally copy cargo.toml? In this case it may silently continue after failing to copy Cargo.toml (however that may happen)

}
);

# add two checks:
# - `versionCheckhook`, checks wether it's a binary that is able to
# display its own version
# - A check which loads the plugin into the current version of nushell,
# 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 ];
Expand Down
5 changes: 1 addition & 4 deletions pkgs/shells/nushell/plugins/net.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];

Expand All @@ -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;
};
})
2 changes: 1 addition & 1 deletion pkgs/shells/nushell/plugins/units.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];

Expand Down
Loading