# How can I delete sensitive information copied into \`/nix/store\` by flake?

**URL:** https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782
**Category:** Help
**Created:** [November 9, 2024, 3:32pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782 "2024-11-09T15:32:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![phaeseeKe5Ee](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@phaeseeKe5Ee](https://discourse.nixos.org/u/phaeseeKe5Ee)
#### Post date: [November 9, 2024, 3:32pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/1 "2024-11-09T15:32:48Z")

</div>

I use `flake.nix` and `nix-direnv` in a directory to write some latex documents in it, which contains some secret information, say `mysecret.tex`. I use flake because I think it was a good idea to make texlive and essential software portable so that I can also build the latex documents easily in some random machine with nix flake.

However I came across this issue [Copy local flakes to the store lazily · Issue #3121 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/3121), and this [Is it possible to make a flake that has no source tree? - #6 by rnhmjoj](https://discourse.nixos.org/t/is-it-possible-to-make-a-flake-that-has-no-source-tree/16037/6), seems the flake copy the whole directory into `/nix/store`, and now I have multiple `/nix/store/somerandomhash-source` folders that contains `mysecret.tex` (I find it by `find /nix/store -maxdepth 2 -iname 'mysecret.tex'`).

I am glad that I haven’t run the flake in the machine that I do not own.

How can I remove all of the corresponding `/nix/store/somerandomhash-source` directiories containing the sensitive information from nix store with the correct way? Thanks!

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 9, 2024, 3:37pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/2 "2024-11-09T15:37:40Z")

</div>

Run `nix store delete [path]`.  
If that gives you an error, run `nix-store --query --roots [path]` to figure out what depends on it (I don’t know the nix3 equivalent command and am too lazy to figure it out.)

---

<div class="post-metadata">

### Author: ![phaeseeKe5Ee](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@phaeseeKe5Ee](https://discourse.nixos.org/u/phaeseeKe5Ee)
#### Post date: [November 9, 2024, 3:50pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/3 "2024-11-09T15:50:17Z")

</div>

Thank, so I have to use some software like `find` to find the corresponding `somerandomhash-source` in `/nix/store` and delete it with `nix store delete /nix/store/somehash-source` one by one?

Ya I found 2 directiories unable to be deleted and remove the corresponding `.direnv` and I can delete it now.

Thank you so much!

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 9, 2024, 3:58pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/4 "2024-11-09T15:58:07Z")

</div>

You don’t have to delete it manually, the next garbage collection would catch anything that doesn’t have a gc root (and if something does have a gc root, you’d find it with the query command and delete the root like you just did).

Or to put it another way, the `nix store delete` command will only let you delete paths that would get gc’d anyway.

---

<div class="post-metadata">

### Author: ![callahad](https://discourse.nixos.org/user_avatar/discourse.nixos.org/callahad/32/999_2.png) [@callahad](https://discourse.nixos.org/u/callahad)
#### Post date: [November 9, 2024, 5:36pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/5 "2024-11-09T17:36:01Z")

</div>

And just to make the implicit explicit for future readers: [nix-direnv](https://github.com/nix-community/nix-direnv) _does_ add its shell derivations to the user’s gcroots

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [November 9, 2024, 8:36pm UTC](https://discourse.nixos.org/t/how-can-i-delete-sensitive-information-copied-into-nix-store-by-flake/55782/6 "2024-11-09T20:36:53Z")

</div>

Well they’re using flakes, even plain ol’ direnv will (incidentally) create a gc root for those:

> <https://github.com/direnv/direnv/blob/aa761e3944cf47751596b2082f2a3c9d33c5aeba/stdlib.sh#L1316-L1322>
