treewide: drop unnecessary toString calls

Scope:
- Combination of
  - Textual matches of "baseNameOf (toString"
  - Redundant toString calls I've found with my latest
    "lazy paths" nix branch as they force lazy fetches into
    the store. More info and new PR soon.
- Only cases I believe are worthwhile or easily determined

I've determined the validity by
- testing llvmPackages instantiation
- figuring out which types can pass into any particular
  toString call - "human fuzzy type checker"

Behavior considerations by type:

- `path`: converted back to a string *without* context
  `baseNameOf` does not copy things to the store on its own,
  equivalent to its behavior for string inputs
- `null`: converted to `""` -> may be valid input!
  ok if "" would not have been acceptable anyway
- `string` itself: passed through identically -> trivial
- `attrset` with `outPath`: same coercion as built into
  the `baseNameOf` function -> trivial
- other atomic types: generally not sensible inputs to
  `baseNameOf` -> fuzzy but true
This commit is contained in:
Robert Hensing 2026-06-03 22:34:12 +02:00
commit 235013cf37
7 changed files with 13 additions and 16 deletions

View file

@ -43,7 +43,7 @@ let
cleanSourceFilter =
name: type:
let
baseName = baseNameOf (toString name);
baseName = baseNameOf name;
in
!(
# Filter out version control software files/directories
@ -270,7 +270,7 @@ let
filter =
name: type:
let
base = baseNameOf (toString name);
base = baseNameOf name;
in
type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
in

View file

@ -35,7 +35,7 @@ let
lib.listToAttrs (map mkEtcFile cfg.package.filesInstalledToEtc);
extraTrustedKeys =
let
mkName = p: "pki/fwupd/${baseNameOf (toString p)}";
mkName = p: "pki/fwupd/${baseNameOf p}";
mkEtcFile = p: lib.nameValuePair (mkName p) { source = p; };
in
lib.listToAttrs (map mkEtcFile cfg.extraTrustedKeys);

View file

@ -122,7 +122,7 @@ in
stdenvNoCC.mkDerivation (
{
name = baseNameOf (toString src);
name = baseNameOf src;
}
// optionalAttrs
// forcedAttrs

View file

@ -4347,7 +4347,7 @@ rec {
sourceFilter =
name: type:
let
baseName = baseNameOf (toString name);
baseName = baseNameOf name;
in
!(
# Filter out git

View file

@ -29,7 +29,7 @@
args:
let
name = if args ? name then args.name else baseNameOf (toString args.src);
name = args.name or (baseNameOf args.src);
deprecationReplacement = lib.pipe args.replacements [
lib.toList
(map (lib.splitString " "))

View file

@ -71,7 +71,7 @@ let
;
src = monorepoSrc;
versionDir =
(toString ../.) + "/${if (gitRelease != null) then "git" else lib.versions.major release_version}";
../. + "/${if (gitRelease != null) then "git" else lib.versions.major release_version}";
getVersionFile =
p:
builtins.path {
@ -95,15 +95,12 @@ let
matchBefore && matchAfter;
patchDir =
toString
(
if constraints == null then
{ path = metadata.versionDir; }
else
(lib.findFirst matchConstraint { path = metadata.versionDir; } constraints)
).path;
if constraints == null then
metadata.versionDir
else
(lib.findFirst matchConstraint { path = metadata.versionDir; } constraints).path;
in
"${patchDir}/${p}";
patchDir + ("/" + p);
};
};

View file

@ -26,7 +26,7 @@ let
];
resolvedLogoName =
if (logoFile != null && logoName == null) then
lib.strings.removeSuffix ".png" (baseNameOf (toString logoFile))
lib.strings.removeSuffix ".png" (baseNameOf logoFile)
else
logoName;
in