试图从 /nix/store 中删除一个包,现在系统出现错误,如何解决?

Tried to delete a package from /nix/store now system has errors, how to fix?

error: opening file '/nix/store/4h464mkqfipf04jgz4jp3bx56sdn6av0-python3.7-somepackage-1.0.0.drv': No such file or directory

我手动删除了一些文件以试图删除包。但是 nix-shell 不再有效并给我上面的消息。如何解决 nix 中的问题?我想完全删除软件包并重新安装。

此外,当我 运行 以下命令时:

~/sources/integration_test >>> nix-env -u python3.7-somepackagesomepackage-1.0.0
error: selector 'python3.7-somepackages-1.0.0' matches no derivations

尝试运行

 nix-store --verify --check-contents --repair

来自联机帮助页:

OPERATION --VERIFY
   Synopsis
       nix-store --verify [--check-contents] [--repair]

   Description
       The operation --verify verifies the internal consistency of the Nix database, and the
       consistency between the Nix database and the Nix store. Any inconsistencies
       encountered are automatically repaired. Inconsistencies are generally the result of
       the Nix store or database being modified by non-Nix tools, or of bugs in Nix itself.

       This operation has the following options:

       --check-contents
           Checks that the contents of every valid store path has not been altered by
           computing a SHA-256 hash of the contents and comparing it with the hash stored in
           the Nix database at build time. Paths that have been modified are printed out.
           For large stores, --check-contents is obviously quite slow.

       --repair
           If any valid path is missing from the store, or (if --check-contents is given)
           the contents of a valid path has been modified, then try to repair the path by
           redownloading it. See nix-store --repair-path for details.

注意。 我建议您自己使用 man nix-store 阅读联机帮助页,以确保在 运行 之前这是您想要的。

NB.2 由于操作的性质,需要检查很多——这个操作需要一段时间。对于我的 11 GiB /nix/store,这个 运行 为 4m13s。


附录。 将来,当你想从 nix 商店手动删除包时,使用

nix-store --delete /nix/store/[what you want to delete]

相反。