为什么home-manager无法使用
$USER
中的Nix函数$HOME
读取环境变量builtins.getEnv
和~/.config/home-manager/home.nix
?
# Excerpt from ~/.config/home-manager/home.nix
...
# Home Manager needs a bit of information about you and the paths it should
# manage.
#home.username = "derek";
home.username = builtins.getEnv "USER";
home.homeDirectory = "/home/derek";
#home.homeDirectory = builtins.getEnv "HOME";
...
alpine-2:~$ home-manager switch
error:
… while evaluating a branch condition
at /nix/store/z6w242l49pbrdawkz5vdhfxh2mvsj36c-source/lib/lists.nix:57:9:
56| fold' = n:
57| if n == len
| ^
58| then nul
… while calling the 'length' builtin
at /nix/store/z6w242l49pbrdawkz5vdhfxh2mvsj36c-source/lib/lists.nix:55:13:
54| let
55| len = length list;
| ^
56| fold' = n:
(stack trace truncated; use '--show-trace' to show the full trace)
error:
Failed assertions:
- Username could not be determined
alpine-2:~$ echo $USER
derek
使用命令
home-manager switch --impure
,家庭管理器能够读取环境变量 $USER
和 $HOME
。 --impure
将 home-manager 置于“不纯”模式,这允许 Nix 表达式包含不尊重引用完整性的“不纯”函数引用(即,可能针对不同的输入值或环境返回不同的结果)。