16

Is there any way to force removing a package from /nix/store/..

I am testing my expression for my package and want to make sure it will rebuild correctly.

The problem is if I build my package once, the next time I build it again it will use the cache.

I use this command to test my package

nix-shell -I nixpkgs=</path/to/repo> -p <package_name>

I don't want to use nix-collect-garbage because it remove lot of buildInputs too.

Looking for something like nix-cg <package_name>

schrodingerscatcuriosity
  • 12,087
  • 3
  • 29
  • 57
wizzup
  • 585
  • 1
  • 5
  • 12
  • 4
    while Vladimir is right, you can achive what you want with `--check` argument, for example, `nix-build '' -A hello --check` will rebuild `hello` even if it is available in cache – danbst May 16 '18 at 12:19
  • @danbst Exactly what I needed, thanks again! Was looking for a way to re-compile packages, and opened this thread because of an unrelated question. Pretty frustrating though that `--check` is not listed as an option under `nix-build` man page (nor under `nix-instantiate`'s), and only found it under `nix-store`'s by accident... (I guess that's why it works with `nix-shell` as well.) – toraritte Feb 10 '21 at 22:11

1 Answers1

18

nix-store --delete /path Note that the path might be alive and thus refused to be deleted without --ignore-liveness and root privileges.

Vladimír Čunát
  • 1,258
  • 7
  • 11
  • 1
    sudo nix-store --delete --ignore-liveness /nix/store/XXX – srghma Sep 09 '18 at 11:27
  • 7
    Careful with that! I just recursively deleted my entire system and had to recover from the install USB. – Jeff Jul 16 '19 at 03:28
  • This command borked my $HOME user profile symlinks to store, despite the package I was uninstalling was `android-studio` I thought was ok. – daparic Feb 26 '21 at 15:57
  • Looks like there may be a newer version: `nix store delete`: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-store-delete.html – Brian Dant Aug 25 '23 at 19:25