Files
roowho2/nix/package.nix
h7x4 f9e60b0f03
All checks were successful
Build and test / check (push) Successful in 1m10s
Build and test / build (push) Successful in 1m35s
Build and test / test (push) Successful in 2m47s
Build and test / docs (push) Successful in 3m1s
nix: build with crane
2026-02-12 11:41:08 +09:00

97 lines
2.3 KiB
Nix

{
lib
, rustPlatform
, stdenv
, buildPackages
, installShellFiles
, versionCheckHook
, systemdLibs
, cargoToml
, cargoLock
, src
, useCrane ? false
, craneLib ? null
}:
let
mainProgram = "roowhod";
buildFunction = if useCrane then craneLib.buildPackage else rustPlatform.buildRustPackage;
pnameCraneSuffix = lib.optionalString useCrane "-crane";
pname = "${cargoToml.package.name}${pnameCraneSuffix}";
rustPlatformArgs = {
buildType = "releaselto";
buildFeatures = lib.optionals stdenv.hostPlatform.isLinux [
"systemd"
];
cargoLock.lockFile = cargoLock;
doCheck = true;
useNextest = true;
nativeCheckInputs = [
versionCheckHook
];
cargoCheckFeatures = lib.optionals stdenv.hostPlatform.isLinux [
"systemd"
];
};
craneArgs = {
cargoLock = cargoLock;
cargoExtraArgs = lib.escapeShellArgs [ "--features" (lib.concatStringsSep "," (
lib.optionals stdenv.hostPlatform.isLinux [
"systemd"
]
)) ];
cargoArtifacts = craneLib.buildDepsOnly {
inherit pname;
inherit (cargoToml.package) version;
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
(craneLib.fileset.cargoTomlAndLock ../.)
];
};
cargoLock = cargoLock;
};
};
in
buildFunction ({
inherit pname;
inherit (cargoToml.package) version;
inherit src;
RUSTFLAGS = "-Zhigher-ranked-assumptions";
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
systemdLibs
];
nativeBuildInputs = [ installShellFiles ];
postInstall = let
emulator = stdenv.hostPlatform.emulator buildPackages;
installShellCompletions = lib.mapCartesianProduct ({ shell, command }: ''
(
export PATH="$out/bin:$PATH"
"${emulator}" "${command}" --completions=${shell} > "$TMP/${command}.${shell}"
)
installShellCompletion "--${shell}" --cmd "${command}" "$TMP/${command}.${shell}"
'') {
shell = [ "bash" "zsh" "fish" ];
command = [ "rwho" "ruptime" "finger" ];
};
in lib.concatStringsSep "\n" installShellCompletions;
meta = with lib; {
license = licenses.bsdOriginalUC;
platforms = platforms.linux ++ platforms.darwin;
inherit mainProgram;
};
}
//
(if useCrane then craneArgs else rustPlatformArgs)
)