From 235013cf37a7ef61d817af1e4c6115b295293bc4 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 3 Jun 2026 22:34:12 +0200 Subject: [PATCH] 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 --- lib/sources.nix | 4 ++-- nixos/modules/services/hardware/fwupd.nix | 2 +- .../replace-vars/replace-vars-with.nix | 2 +- .../rust/build-rust-crate/test/rcgen-crates.nix | 2 +- pkgs/build-support/substitute/substitute.nix | 2 +- .../development/compilers/llvm/common/default.nix | 15 ++++++--------- pkgs/kde/plasma/breeze-plymouth/default.nix | 2 +- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/sources.nix b/lib/sources.nix index 43a374c16e73..81b8a8c77178 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -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 diff --git a/nixos/modules/services/hardware/fwupd.nix b/nixos/modules/services/hardware/fwupd.nix index 1c059bf39e64..91e1afd1067e 100644 --- a/nixos/modules/services/hardware/fwupd.nix +++ b/nixos/modules/services/hardware/fwupd.nix @@ -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); diff --git a/pkgs/build-support/replace-vars/replace-vars-with.nix b/pkgs/build-support/replace-vars/replace-vars-with.nix index c863c6fb617f..abbb9a1cc1a0 100644 --- a/pkgs/build-support/replace-vars/replace-vars-with.nix +++ b/pkgs/build-support/replace-vars/replace-vars-with.nix @@ -122,7 +122,7 @@ in stdenvNoCC.mkDerivation ( { - name = baseNameOf (toString src); + name = baseNameOf src; } // optionalAttrs // forcedAttrs diff --git a/pkgs/build-support/rust/build-rust-crate/test/rcgen-crates.nix b/pkgs/build-support/rust/build-rust-crate/test/rcgen-crates.nix index 804308ed216f..563500ed0092 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/rcgen-crates.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/rcgen-crates.nix @@ -4347,7 +4347,7 @@ rec { sourceFilter = name: type: let - baseName = baseNameOf (toString name); + baseName = baseNameOf name; in !( # Filter out git diff --git a/pkgs/build-support/substitute/substitute.nix b/pkgs/build-support/substitute/substitute.nix index 431a97c9b1ba..050e259f4eb1 100644 --- a/pkgs/build-support/substitute/substitute.nix +++ b/pkgs/build-support/substitute/substitute.nix @@ -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 " ")) diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 2a88fecc0b6e..cd15cd6f36a5 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -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); }; }; diff --git a/pkgs/kde/plasma/breeze-plymouth/default.nix b/pkgs/kde/plasma/breeze-plymouth/default.nix index d85dd1861a10..ccb7c6d9d3f0 100644 --- a/pkgs/kde/plasma/breeze-plymouth/default.nix +++ b/pkgs/kde/plasma/breeze-plymouth/default.nix @@ -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