Skip to content

Cannot convert string to path #12407

Open
@yajo

Description

@yajo

Describe the bug

When you have a string that contains nix store info, it's impossible to convert it to a Path.

Steps To Reproduce

# flake.nix
{
  outputs = {
    self,
    nixpkgs,
  }: {
    packages.x86_64-linux.default = let
      absoluteNixpkgs = /. + nixpkgs;
    in
      assert builtins.isPath absoluteNixpkgs;
        nixpkgs.legacyPackages.x86_64-linux.runCommandLocal "test" ''
          true
        '';
  };
}

Now build it:

nix build --show-trace
error:
       … in the condition of the assert statement
         at /nix/store/v99q15bqy6lrm4wiqjwsp0ig9vl1g949-source/mrchef/nix/flake.nix:9:7:
            8|     in
            9|       assert builtins.isPath absoluteNixpkgs;
             |       ^
           10|         nixpkgs.legacyPackages.x86_64-linux.runCommandLocal "test" ''while calling the 'isPath' builtin
         at /nix/store/v99q15bqy6lrm4wiqjwsp0ig9vl1g949-source/mrchef/nix/flake.nix:9:14:
            8|     in
            9|       assert builtins.isPath absoluteNixpkgs;
             |              ^
           10|         nixpkgs.legacyPackages.x86_64-linux.runCommandLocal "test" ''

       error: a string that refers to a store path cannot be appended to a path
       at /nix/store/v99q15bqy6lrm4wiqjwsp0ig9vl1g949-source/mrchef/nix/flake.nix:7:28:
            6|     packages.x86_64-linux.default = let
            7|       absoluteNixpkgs = /. + nixpkgs;
             |                            ^
            8|     in

Expected behavior

I should be able to convert it to a path, and work with it from there onwards.

However, builtins.toPath returns a String, as shown in #1074. And the docs say to use this new method I'm using, but it also doesn't work as shown here.

Metadata

nix-env (Nix) 2.24.12

Additional context

I'm trying to use paths because they react appropriately directory traversal when concatenating with ../../ or similar stuff. These are however prohibited in other library functions in nixpkgs.lib.path.subpath, so I cannot just use strings.

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions