refactor: clean up scripts
Some checks failed
/ check (push) Failing after 8s
/ check-renovaterc (push) Successful in 2s
/ build-packages (push) Has been skipped
/ build-vm (push) Has been skipped
/ report-size (push) Has been skipped

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 a12b2ba881
Signed by: jalil
GPG key ID: F016B9E770737A0B
3 changed files with 39 additions and 72 deletions

View file

@ -1,31 +1,9 @@
{ 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;