refactor: clean up scripts
All checks were successful
/ check (push) Successful in 8s
/ check-renovaterc (push) Successful in 3s
/ build-packages (push) Successful in 14s
/ build-vm (push) Successful in 2s
/ report-size (push) Successful in 4s

Tidy up the script logic and deduplicate it a bit.
This commit is contained in:
Jalil David Salamé Messina 2025-05-16 19:03:09 +02:00
parent 3977e8d50e
commit dc5e219bc3
Signed by: jalil
GPG key ID: F016B9E770737A0B
3 changed files with 47 additions and 72 deletions

View file

@ -1,31 +1,13 @@
{ lib, rustPlatform }:
{
lib,
rustPlatform,
cleanRustSrc,
}:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
inherit (cargoToml.package) name version description;
pname = name;
src = lib.cleanSourceWith {
src = ./.;
name = "${pname}-source";
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
# no need to pull in crane for just this
filter =
orig_path: type:
let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Rust sources
".rs"
# TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml)
".toml"
];
isCargoLock = base == "Cargo.lock";
# .cargo/config.toml is captured above
isOldStyleCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
};
src = cleanRustSrc ./.;
in
rustPlatform.buildRustPackage {
inherit pname version src;