{ lib , rustPlatform , stdenv , buildPackages , installShellFiles , versionCheckHook , pkg-config , openssl , cargoToml , cargoLock , src , useCrane ? false , craneLib ? null }: let mainProgram = (lib.head cargoToml.bin).name; buildFunction = if useCrane then craneLib.buildPackage else rustPlatform.buildRustPackage; pnameCraneSuffix = lib.optionalString useCrane "-crane"; pname = "${cargoToml.package.name}${pnameCraneSuffix}"; rustPlatformArgs = { buildType = "release-lto"; cargoLock.lockFile = cargoLock; doCheck = true; useNextest = true; nativeCheckInputs = [ versionCheckHook ]; }; craneArgs = { cargoLock = cargoLock; cargoArtifacts = craneLib.buildDepsOnly { inherit pname; inherit (cargoToml.package) version; src = lib.fileset.toSource { root = ../.; fileset = lib.fileset.unions [ (craneLib.fileset.cargoTomlAndLock ../.) ]; }; nativeBuildInputs = [ pkg-config ]; buildInputs = [ openssl ]; cargoLock = cargoLock; }; }; in buildFunction ({ inherit pname; inherit (cargoToml.package) version; inherit src; nativeBuildInputs = [ installShellFiles pkg-config ]; buildInputs = [ openssl ]; postInstall = let emulatorAvailable = stdenv.hostPlatform.emulatorAvailable buildPackages; emulator = stdenv.hostPlatform.emulator buildPackages; in lib.optionalString emulatorAvailable '' installShellCompletion --cmd kagami \ --bash <(${emulator} $out/bin/kagami generate-completions --shell bash) \ --fish <(${emulator} $out/bin/kagami generate-completions --shell fish) \ --zsh <(${emulator} $out/bin/kagami generate-completions --shell zsh) ''; meta = with lib; { license = licenses.bsd3; platforms = platforms.unix ++ platforms.windows; inherit mainProgram; }; } // (if useCrane then craneArgs else rustPlatformArgs) )