# SPDX-FileCopyrightText: 2024 Ryan Cao # # SPDX-License-Identifier: GPL-3.0-only { lib, stdenv, rustPlatform, darwin, nix-filter, installShellFiles, pkg-config, self, enableLTO ? true, enableOptimizeSize ? false, }: let year = builtins.substring 0 4 self.lastModifiedDate; month = builtins.substring 4 2 self.lastModifiedDate; day = builtins.substring 6 2 self.lastModifiedDate; in rustPlatform.buildRustPackage rec { pname = passthru.cargoToml.package.name; version = passthru.cargoToml.package.version + "-unstable-${year}-${month}-${day}"; strictDeps = true; src = nix-filter.lib.filter { root = self; include = [ "src" "build.rs" "Cargo.lock" "Cargo.toml" ]; }; cargoLock = { lockFile = ../Cargo.lock; }; buildInputs = lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.CoreFoundation darwin.apple_sdk.frameworks.Security darwin.apple_sdk.frameworks.IOKit darwin.libiconv ]; nativeBuildInputs = [ installShellFiles ] ++ lib.optionals stdenv.isDarwin [ pkg-config ]; env = lib.optionalAttrs enableLTO { CARGO_PROFILE_RELEASE_LTO = "fat"; CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "1"; } // lib.optionalAttrs enableOptimizeSize { CARGO_PROFILE_RELEASE_OPT_LEVEL = "z"; CARGO_PROFILE_RELEASE_PANIC = "abort"; CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "1"; CARGO_PROFILE_RELEASE_STRIP = "symbols"; }; doCheck = false; preBuild = '' export COMPLETIONS_OUT_DIR="$TMPDIR/completions" ''; postInstall = '' installShellCompletion --cmd ${pname} \ --bash "$TMPDIR/completions/${pname}.bash" \ --zsh "$TMPDIR/completions/_${pname}" \ --fish "$TMPDIR/completions/${pname}.fish" ''; passthru = { cargoToml = lib.importTOML ../Cargo.toml; }; meta = with lib; { description = "SPDX license generator"; maintainers = with maintainers; [ ryanccn ]; license = licenses.gpl3Only; mainProgram = "spdx-gen"; }; }