{ lib, craneLib, stdenv, mold, versionCheckHook, useMold ? stdenv.isLinux, 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) ]; }; 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 useMold { 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; }; }