使用nix profile install安装软件时与home-manager冲突求助
Nix Profile安装软件包与Home-Manager冲突的解决方案
使用nix profile install安装软件包时,Flake部署的Home-Manager会触发文件冲突,具体操作及报错信息如下:
❯ hello 程序'hello'不在您的PATH中。它由多个软件包提供。 您可以通过输入以下命令之一在临时shell中使用它: nix-shell -p fltk nix-shell -p fltk14 nix-shell -p haskellPackages.hello nix-shell -p hello nix-shell -p mbedtls ~ ❯ nix profile install nixpkgs#hello error: 现有软件包已提供以下文件: /nix/store/gwyaapg12wpj2gd5chyllg3dmrgq811h-home-manager-path/share/bash-completion/completions/home-manager 这是新软件包中产生冲突的文件: /nix/store/kfmgvy3vky5s2jcvn7ih354i11l0asmz-home-manager-2021-03-21/share/bash-completion/completions/home-manager 要移除现有软件包,请执行: nix profile remove /nix/store/gwyaapg12wpj2gd5chyllg3dmrgq811h-home-manager-path 也可以通过设置不同优先级来同时安装新软件包。 冲突软件包的优先级均为5。 要优先使用新软件包,请执行: nix profile install /nix/store/kfmgvy3vky5s2jcvn7ih354i11l0asmz-home-manager-2021-03-21 --priority 4 要优先使用现有软件包,请执行: nix profile install /nix/store/kfmgvy3vky5s2jcvn7ih354i11l0asmz-home-manager-2021-03-21 --priority 6
解决方法
方法1:移除冲突的现有包
直接执行报错提示的命令,删除提供重复补全文件的home-manager-path:
nix profile remove /nix/store/gwyaapg12wpj2gd5chyllg3dmrgq811h-home-manager-path
执行完成后,重新运行安装命令即可:
nix profile install nixpkgs#hello
方法2:调整包优先级保留两个包
若需同时保留相关包,可通过修改优先级解决冲突:
- 优先使用新的Home-Manager包:
nix profile install /nix/store/kfmgvy3vky5s2jcvn7ih354i11l0asmz-home-manager-2021-03-21 --priority 4
- 优先使用现有的
home-manager-path:
nix profile install /nix/store/kfmgvy3vky5s2jcvn7ih354i11l0asmz-home-manager-2021-03-21 --priority 6
额外建议
通过Flake管理Home-Manager时,建议优先在Home-Manager配置文件中添加软件包(例如将hello加入home.packages列表),再执行home-manager switch应用配置,这样能从根源避免此类文件冲突问题。
内容的提问来源于stack exchange,提问作者thepandaatemyface
相关产品推荐
相关产品推荐

