configuration.nix/scripts/default.nix
Jalil David Salamé Messina d4997ba0c1
Some checks failed
/ check (push) Successful in 8s
/ check-renovaterc (push) Successful in 3s
/ build-packages (push) Failing after 1s
/ build-vm (push) Has been skipped
/ report-size (push) Has been skipped
refactor: clean up scripts
Tidy up the script logic and deduplicate it a bit.
2025-05-16 19:05:08 +02:00

48 lines
1.5 KiB
Nix

{ lib, ... }:
let
# Clean the package source leaving only the relevant rust files
cleanRustSrc =
pname: src:
lib.cleanSourceWith {
inherit 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_str = toString orig_path;
base = baseNameOf path_str;
parentDir = baseNameOf (dirOf path_str);
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;
};
# callPackage but for my rust Packages
callRustPackage =
pkgs: pname: nixSrc:
pkgs.callPackage nixSrc { cleanRustSrc = cleanRustSrc pname; };
packages = {
jpassmenu = ./jpassmenu/package.nix;
audiomenu = ./audiomenu/package.nix;
};
in
{
# Add scripts to overlay
flake.overlays.scripts = _final: prev: builtins.mapAttrs (callRustPackage prev);
# Add scripts to packages
perSystem =
{ pkgs, ... }:
{
packages = builtins.mapAttrs (callRustPackage pkgs);
};
}