nix: modernize package; add version check hook
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I599dbc1e6d9a7a438eb44d765c3101076a6a6964
This commit is contained in:
parent
3ccae8f125
commit
e1c8ecf0b6
1 changed files with 24 additions and 3 deletions
|
|
@ -2,10 +2,12 @@
|
||||||
lib,
|
lib,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
stdenv,
|
stdenv,
|
||||||
|
installShellFiles,
|
||||||
|
versionCheckHook,
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage (finalAttrs: {
|
rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
pname = "eh";
|
pname = "eh";
|
||||||
version = (builtins.fromTOML (builtins.readFile ../Cargo.toml)).workspace.package.version;
|
version = (lib.importTOML ../Cargo.toml).workspace.package.version;
|
||||||
|
|
||||||
src = let
|
src = let
|
||||||
fs = lib.fileset;
|
fs = lib.fileset;
|
||||||
|
|
@ -24,16 +26,35 @@ rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
|
|
||||||
# xtask doesn't support passing --targe
|
# xtask doesn't support passing --targe
|
||||||
# but nix hooks expect the folder structure from when it's set
|
# but nix hooks expect the folder structure from when it's set
|
||||||
env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.cargoShortTarget;
|
|
||||||
cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock";
|
cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock";
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
|
# xtask doesn't support passing --target
|
||||||
|
# but nix hooks expect the folder structure from when it's set
|
||||||
|
env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.cargoShortTarget;
|
||||||
|
|
||||||
|
nativeInstallCheckInputs = [versionCheckHook];
|
||||||
|
versionCheckProgram = "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}";
|
||||||
|
versionCheckProgramArg = "--version";
|
||||||
|
doInstallCheck = true;
|
||||||
|
|
||||||
|
strictDeps = true;
|
||||||
|
|
||||||
|
nativeBuildInputs = [installShellFiles];
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
# Install required files with the 'dist' task
|
# Install required files with the 'dist' task
|
||||||
$out/bin/xtask multicall \
|
$out/bin/xtask multicall \
|
||||||
--bin-dir $out/bin \
|
--bin-dir $out/bin \
|
||||||
--main-binary $out/bin/eh
|
--main-binary $out/bin/eh
|
||||||
|
|
||||||
|
# Generate shell completions and install them.
|
||||||
|
for shell in bash zsh fish; do
|
||||||
|
$out/bin/xtask completions $shell
|
||||||
|
done
|
||||||
|
|
||||||
|
installShellCompletion completions/*
|
||||||
|
|
||||||
# The xtask output has been built as a part of the build phase. If
|
# The xtask output has been built as a part of the build phase. If
|
||||||
# we don't remove it, it'll be linked in $out/bin alongside the actual
|
# we don't remove it, it'll be linked in $out/bin alongside the actual
|
||||||
# binary and populate $PATH with a dedicated 'xtask' command. Remove.
|
# binary and populate $PATH with a dedicated 'xtask' command. Remove.
|
||||||
|
|
@ -42,7 +63,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Ergonomic Nix CLI helper";
|
description = "Ergonomic Nix CLI helper";
|
||||||
maintainers = with lib.licenses; [NotAShelf];
|
maintainers = with lib.maintainers; [NotAShelf];
|
||||||
license = lib.licenses.mpl20;
|
license = lib.licenses.mpl20;
|
||||||
mainProgram = "eh";
|
mainProgram = "eh";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue