Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot collect garbage: store path contains illegal character '!' #5176

Closed
Mindavi opened this issue Aug 25, 2021 · 12 comments · Fixed by #5203
Closed

Cannot collect garbage: store path contains illegal character '!' #5176

Mindavi opened this issue Aug 25, 2021 · 12 comments · Fixed by #5203
Labels

Comments

@Mindavi
Copy link
Contributor

Mindavi commented Aug 25, 2021

Describe the bug

I'm running nix unstable and I cannot do a garbage collection anymore, because my store contains a path with an 'illegal' character.

error: store path 'bbnr9kxadkp6bbq059ir25bxpvkgfl1p-gssdp-aarch64-unknown-linux-gnu-1.2.3.drv!bin' contains illegal character '!'

Steps To Reproduce

  1. Not sure how to make those paths, but I guess it might be related to content-addressed derivations?

What I tried:

  • sudo nix-collect-garbage --older-than 15d
  • sudo nix-store --delete
  • sudo nix store delete (doesn't work because path 'is not a flake')

Expected behavior

I can still do a garbage collection, even if it's just to remove the illegal directories.

nix-env --version output

nix-env (Nix) 2.4pre20210802_47e96bb

Additional context

Some experimental features are enabled, which may have caused this issue or be related to it:

experimental-features = nix-command flakes ca-derivations ca-references
@Mindavi Mindavi added the bug label Aug 25, 2021
@claymager
Copy link

claymager commented Sep 1, 2021

I also have this.

My store contans about 50 lockfiles similar to the following:

'053nji2kvh8yhdyai52gacri3ij1mpbl-gdb-10.2.drv!out.lock'
'0fdnrfwb8c5jxnbacmflwx2185y3bkzl-x265-3.4.drv!out.lock'
'27bm9li7y4wcyizm1c5xin1md5f7r6kn-llvm-7.1.0.drv!dev.lock'
'27bm9li7y4wcyizm1c5xin1md5f7r6kn-llvm-7.1.0.drv!lib.lock'
'27bm9li7y4wcyizm1c5xin1md5f7r6kn-llvm-7.1.0.drv!out.lock'
'27bm9li7y4wcyizm1c5xin1md5f7r6kn-llvm-7.1.0.drv!python.lock'

They appeared roughly when I started experimenting with content-addressing.

$ nix-store --gc --print-dead fails for me with the same error, as do a few others.

$ nix optimise-store succeeds, though.

@Mindavi
Copy link
Contributor Author

Mindavi commented Sep 1, 2021

I applied this patch for now, but it's just a bandaid. It probably won't really hurt, but tread carefully.

Alternatively, remount the nix store with sudo mount -o remount,rw /nix/store/ and removing the offending folders. Note that that will only help for those files, and it might confuse the database.

diff --git a/src/libstore/path.cc b/src/libstore/path.cc
index e642abcd5..0e584ef33 100644
--- a/src/libstore/path.cc
+++ b/src/libstore/path.cc
@@ -12,7 +12,7 @@ static void checkName(std::string_view path, std::string_view name)
         if (!((c >= '0' && c <= '9')
                 || (c >= 'a' && c <= 'z')
                 || (c >= 'A' && c <= 'Z')
-                || c == '+' || c == '-' || c == '.' || c == '_' || c == '?' || c == '='))
+                || c == '+' || c == '-' || c == '.' || c == '_' || c == '?' || c == '=' || c == '!'))
             throw BadStorePath("store path '%s' contains illegal character '%s'", path, c);
 }

And then in configuration.nix something like this:

  nix = {
    package = pkgs.nixUnstable.overrideAttrs (oldAttrs: {
      patches = (oldAttrs.patches or []) ++ [
        ./nix-store-path-illegal.patch
      ];
    });
  };

also cc @regnat since this is probably related to content-addressed deriviations.

@thufschmitt
Copy link
Member

I’ve recently hit that too. That’s apparently due to 8707773 . I’ll add a patch quickly to fix it

(and in the meantime, it should be safe to remove them manually as they are just transient files that don’t go in the database at all)

thufschmitt added a commit that referenced this issue Sep 2, 2021
Store paths are only allowed to contain a limited subset of the
alphabet, which doesn’t include `!`. So don’t create lockfiles that
contain this `!` character as that would otherwise confuse (and break)
the gc.

Fix #5176
@thufschmitt
Copy link
Member

I’ve opened a fix at #5203 to stop creating these invalid lockfiles (you’d still have to manually remove the existing ones)

@nrdxp
Copy link

nrdxp commented Jan 8, 2024

Just a heads up, I hit this recently but not with a lock file, but with an a derivation named /nix/store/pjsj82aaw0q2rx1qzci6rrlggzd9f1il-all-attrs-eval-under-tryEval.drv, which has a reference to a path q7375xm60a582561sq84mxyx13j79cjb-.version which is illegal because of the .. The path also doesn't actually exist in on the file-system so not sure where it comes form. This path does exist in the db and it has several references so removing manually has proved to be a pain. I am currently building a patched nix to temporarily remove the . as an invalid character and hopefully it will just work when I attempt to remove it.

No idea how I got this path on my system in the first place, but just thought it might be worth at least reporting since this is a bit different than the OP.

@thufschmitt
Copy link
Member

@nrdxp your issue seems to be an instance of #9624 rather than that one (although the fact that the path doesn't exist on the filesystem is quite weird)

@xlambein
Copy link

I had the same issue. In case anyone else is faced with this: deleting the file from the store manually is a bad idea. Instead the correct solution is to patch Nix with the patch from above, and delete the store path with nix-store --delete PATH.

@PlumpMath
Copy link

If an error occurs in NixOS,

even with the command nix-store --delete PATH, it can't be resolved, can't be deleted, and file permission issues can't be solved either.

It seems like a reinstallation might be necessary.

@MartinLoeper
Copy link

I encountered the same error with the store path containing a dot: /nix/store/wk4ylz2adn2i5hrhc6rq7bsllfazs5nw-.streamdeck_ui.json

Someone knowing why this is happening?

@PlumpMath
Copy link

I encountered the same error with the store path containing a dot: /nix/store/wk4ylz2adn2i5hrhc6rq7bsllfazs5nw-.streamdeck_ui.json

Someone knowing why this is happening?

In my case, this happened when I created a file starting with dot in nix in the home folder.
I don't know why it can't be erased during garbage collection.

@thufschmitt
Copy link
Member

@PlumpMath @MartinLoeper : your issue seems to be #9095 . It got reverted in #9867, but somehow never backported to 2.18 (which I assume you're running on?).

I'm backporting it locally (there was a small merge conflict, I'm just checking that everything works fine) and I'll open a PR for the backport

@PlumpMath
Copy link

PlumpMath commented Apr 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants