From 66cf79f28218d47f076826001198b849366504de Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 5 Nov 2022 23:53:41 +0200 Subject: [PATCH] lib,doc: remove obvious usages of toString on paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It gives a warning on the lazy-trees branch of Nix (NixOS/nix#6530) one of these was also giving me an error (the one in lib/trivial probably) ``` $ nix build warning: applying 'toString' to path '/home/artturin/nixgits/my-nixpkgs/nixos/modules/installer/sd-card/sd -image-aarch64.nix' and then accessing it is deprecated, at /home/artturin/nixgits/my-nixpkgs/lib/modules. nix:349:99 warning: applying 'toString' to path '/home/artturin/nixgits/my-nixpkgs/.git' and then accessing it is dep recated, at /home/artturin/nixgits/my-nixpkgs/lib/sources.nix:35:32 warning: applying 'toString' to path '/home/artturin/nixgits/my-nixpkgs/nixos/modules/system/etc/etc.nix' and then accessing it is deprecated, at «stdin»:0 warning: applying 'toString' to path '/home/artturin/nixgits/my-nixpkgs/nixos/modules/system/etc/etc-activ ation.nix' and then accessing it is deprecated, at «stdin»:0 warning: applying 'toString' to path '/home/artturin/nixgits/my-nixpkgs/nixos/modules/installer/sd-card/sd -image-aarch64.nix' and then accessing it is deprecated, at «stdin»:0 error: cannot decode virtual path '/nix/store/virtual0000000000000000000000005-source' (use '--show-trace' to show detailed location information) ``` --- doc/doc-support/lib-function-locations.nix | 2 +- lib/sources.nix | 10 +++++----- lib/trivial.nix | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/doc-support/lib-function-locations.nix b/doc/doc-support/lib-function-locations.nix index 68edd2709854..ac4da88052da 100644 --- a/doc/doc-support/lib-function-locations.nix +++ b/doc/doc-support/lib-function-locations.nix @@ -38,7 +38,7 @@ let substr = builtins.substring prefixLen filenameLen filename; in substr; - removeNixpkgs = removeFilenamePrefix (builtins.toString pkgs.path); + removeNixpkgs = removeFilenamePrefix pkgs.path; liblocations = builtins.filter diff --git a/lib/sources.nix b/lib/sources.nix index cec395c9bb18..b7fb71bd0b0b 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -140,7 +140,7 @@ let origSrc = if isFiltered then src.origSrc else src; in lib.cleanSourceWith { filter = (path: type: - let relPath = lib.removePrefix (toString origSrc + "/") (toString path); + let relPath = lib.removePrefix (origSrc + "/") (path); in lib.any (re: match re relPath != null) regexes); inherit src; }; @@ -175,12 +175,12 @@ let */ commitIdFromGitRepo = let readCommitFromFile = file: path: - let fileName = toString path + "/" + file; - packedRefsName = toString path + "/packed-refs"; + let fileName = path + "/" + file; + packedRefsName = path + "/packed-refs"; absolutePath = base: path: if lib.hasPrefix "/" path then path - else toString (/. + "${base}/${path}"); + else /. + "${base}/${path}"; in if pathIsRegularFile path # Resolve git worktrees. See gitrepository-layout(5) then @@ -226,7 +226,7 @@ let pathHasContext = builtins.hasContext or (lib.hasPrefix storeDir); - canCleanSource = src: src ? _isLibCleanSourceWith || !(pathHasContext (toString src)); + canCleanSource = src: src ? _isLibCleanSourceWith || !(pathHasContext src); # -------------------------------------------------------------------------- # # Internal functions diff --git a/lib/trivial.nix b/lib/trivial.nix index 5d4fad8266bc..8f2023caaf8e 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -213,8 +213,8 @@ rec { # Default value to return if revision can not be determined default: let - revisionFile = "${toString ./..}/.git-revision"; - gitRepo = "${toString ./..}/.git"; + revisionFile = ./.. + "/.git-revision"; + gitRepo = ./.. + "/.git"; in if lib.pathIsGitRepo gitRepo then lib.commitIdFromGitRepo gitRepo else if lib.pathExists revisionFile then lib.fileContents revisionFile