求教个darwin下nix home-manager的问题

Hi,

我在macos下安装home-manager的时候发现swtich错误。是这两行的原因 https://github.com/ztlevi/nix-dotfiles/blob/3323897abecdca6cf933173820068d2348a2b883/options.nix#L66-L68. 我如果把这两行去掉,是能够build的,但奇怪的是,我在nixos下是能正常switch的。

我试了home-manager master 和20.03的channel都不行,有没有大佬帮忙看下是什么问题。下面贴了错误信息。

我安装home-manager的流程在这边https://github.com/ztlevi/nix-dotfiles/blob/darwin/Makefile#L87-L92

building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: while evaluating the attribute 'config.system.build.toplevel' at undefined position:
while evaluating 'g' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:276:19, called from undefined position:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:98:72, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:279:20:
while evaluating the attribute 'value' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:471:9:
while evaluating the option `system.build':
while evaluating the attribute 'mergedValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:503:5:
while evaluating 'merge' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:328:20, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:505:59:
while evaluating 'filterAttrs' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:124:23, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:35:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:29, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:18:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:51, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:62:
while evaluating the attribute 'toplevel' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:344:7:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:86, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:344:15:
while evaluating the attribute 'optionalValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:515:5:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:497:9:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:596:7:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:28, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:17:
while evaluating definitions from `/nix/store/j0r69hhvjml9c64868wmp0q2p3g9fyfr-darwin/darwin/modules/system':
while evaluating 'dischargeProperties' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:555:25, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:484:137:
while evaluating the attribute 'value' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:333:60:
while evaluating 'throwAssertions' at /nix/store/j0r69hhvjml9c64868wmp0q2p3g9fyfr-darwin/darwin/modules/system/default.nix:13:21, called from /nix/store/j0r69hhvjml9c64868wmp0q2p3g9fyfr-darwin/darwin/modules/system/default.nix:73:29:
while evaluating anonymous function at /nix/store/j0r69hhvjml9c64868wmp0q2p3g9fyfr-darwin/darwin/modules/system/default.nix:11:50, called from undefined position:
while evaluating the attribute 'assertion' at /Users/ztlevi/.nix-defexpr/channels/home-manager/nix-darwin/default.nix:82:32:
while evaluating the attribute 'assertion' at /Users/ztlevi/.nix-defexpr/channels/home-manager/modules/home-environment.nix:398:9:
while evaluating the attribute 'home.username' at undefined position:
while evaluating 'g' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:276:19, called from undefined position:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:98:72, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:279:20:
while evaluating the attribute 'value' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:471:9:
while evaluating the option `home-manager.users.ztlevi.home.username':
while evaluating the attribute 'mergedValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:503:5:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:497:9:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:596:7:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:28, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:17:
while evaluating definitions from `/Users/ztlevi/.nix-defexpr/channels/home-manager/nix-darwin':
while evaluating 'dischargeProperties' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:555:25, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:484:137:
while evaluating the attribute 'value' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:338:44:
while evaluating the attribute 'users.users.ztlevi.name' at undefined position:
while evaluating 'g' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:276:19, called from undefined position:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:98:72, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:279:20:
while evaluating the attribute 'value' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:471:9:
while evaluating the option `users.users':
while evaluating the attribute 'mergedValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:503:5:
while evaluating 'merge' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:328:20, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:505:59:
while evaluating 'filterAttrs' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:124:23, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:35:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:29, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:18:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:51, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:125:62:
while evaluating the attribute 'ztlevi' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:344:7:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:329:86, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/attrsets.nix:344:15:
while evaluating the attribute 'optionalValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:515:5:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:497:9:
while evaluating the attribute 'values' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:596:7:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:28, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:483:17:
while evaluating definitions from `/Users/ztlevi/.dotfiles/options.nix':
while evaluating 'dischargeProperties' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:555:25, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:484:137:
while evaluating the attribute 'condition' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:639:14:
while evaluating 'isType' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/types.nix:14:18, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:711:11:
while evaluating the attribute 'my.user' at undefined position:
while evaluating anonymous function at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:364:37, called from undefined position:
while evaluating the attribute 'matchedOptions' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:352:15:
while evaluating 'evalOptionValue' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:442:31, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:352:32:
while evaluating the attribute 'type.deprecationMessage' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:631:21:
while evaluating 'f' at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:620:11, called from /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:631:28:
value is a function while a set was expected, at /nix/store/7vy4n87yx9qriqryy2kznsjhcq8gmmj6-nixpkgs-21.03pre245942.89281dd1dfe/nixpkgs/lib/modules.nix:623:12
make: *** [mac_switch] Error 1

你为啥问nix的问题在emacs论坛,这个提示已经很清楚了。 evaluating the attribute ‘values’ 不对value is a function while a set was expected 查看对应的nixpkgs channel lib要求。那nixos可能nixpkgs channel lib是不同版本的。

因为在nix论坛问了没什么回复。。。

我找到问题了,是options.my.users的定义不对。估计是nixpkgs-unstable的定义和stable版本的定义不一样。

解决了这个问题以后又报错,说

building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: The option `my.packages' is used but not defined.
(use '--show-trace' to show detailed location information)
make: *** [Makefile:84: switch] Error 1
make: Leaving directory '/Users/ztlevi/.dotfiles'

是这行的问题,但我明明在上面的optiolns里面定义了啊。https://github.com/ztlevi/nix-dotfiles/blob/darwin/options.nix#L69

求教是什么问题啊?

这个意思说你没set 已经说的很明白了。mkoption后要有default set 到你de listof package 你可以设置 default = [];就好 packages = mkOption { type = with types; listOf package; default = []; };

谢谢,估计是新版本默认得设置了 :joy:

楼主,请问下在Mac上安装Nix 可以替代homebrew吗,准备入坑nix。有没必要卸载brew?

homebrew 要留着 cask(除了cask,一无是处

多谢,刚装好nix,看来得看一遍手册才行。brew跟nix 功能重叠,准备卸了,留着cask安装gui应用。