refactor: clean up scripts
Tidy up the script logic and deduplicate it a bit.
This commit is contained in:
parent
3977e8d50e
commit
dc5e219bc3
3 changed files with 47 additions and 72 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue