stash/nix/package.nix
NotAShelf 4d58cae50d
nix: add platforms to meta; allow overriding symlink behaviour
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib6e44abd86bd0e58f290b456680a97236a6a6964
2026-02-26 09:12:27 +03:00

71 lines
2.1 KiB
Nix

{
lib,
craneLib,
stdenv,
mold,
versionCheckHook,
createSymlinks ? true,
}: let
pname = "stash";
version = (lib.importTOML ../Cargo.toml).package.version;
src = let
fs = lib.fileset;
s = ../.;
in
fs.toSource {
root = s;
fileset = fs.unions [
(fs.fileFilter (file: builtins.any file.hasExt ["rs"]) (s + /src))
(s + /Cargo.lock)
(s + /Cargo.toml)
(s + /build.rs)
];
};
cargoArtifacts = craneLib.buildDepsOnly {
name = "${pname}-deps";
strictDeps = true;
inherit src;
};
in
craneLib.buildPackage {
inherit pname src version cargoArtifacts;
strictDeps = true;
# Since Crane doesn't have a good way of enforcing that our symlinks
# generated by the build wrapper are correctly linked, we should link
# them *manually*. The postInstallCheck phase that follows will check
# to verify if all of those links are in place.
postInstall = lib.optionalString createSymlinks ''
mkdir -p $out
for bin in stash-copy stash-paste wl-copy wl-paste; do
ln -sf $out/bin/stash $out/bin/$bin
done
'';
nativeInstallCheckInputs = [versionCheckHook];
doInstallCheck = true;
# After the version check, let's see if all binaries are linked correctly.
# We could probably add a check phase to get the versions of each.
postInstallCheck = lib.optionalString createSymlinks ''
for bin in stash stash-copy stash-paste wl-copy wl-paste; do
[ -x "$out/bin/$bin" ] || { echo "$bin missing"; exit 1; }
done
'';
env = lib.optionalAttrs (stdenv.isLinux && !stdenv.hostPlatform.isAarch) {
CARGO_LINKER = "clang";
CARGO_RUSTFLAGS = "-Clink-arg=-fuse-ld=${mold}/bin/mold";
};
meta = {
description = "Wayland clipboard manager with fast persistent history and multi-media support";
homepage = "https://github.com/notashelf/stash";
license = lib.licenses.mpl20;
maintainers = [lib.maintainers.NotAShelf];
mainProgram = "stash";
platforms = lib.platforms.linux;
};
}