Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to extended Nixpkg's lib #994

Merged
merged 1 commit into from
Jan 21, 2020
Merged

Switch to extended Nixpkg's lib #994

merged 1 commit into from
Jan 21, 2020

Conversation

rycee
Copy link
Member

@rycee rycee commented Jan 16, 2020

This change makes use of the extend function inside lib to inject a new hm field containing the Home Manager library functions. This simplifies use of the Home Manager library in the modules and reduces the risk of accidental infinite recursion.

@rycee rycee force-pushed the extended-stdlib branch 2 times, most recently from 4486d10 to 10c445f Compare January 16, 2020 23:02
@rycee
Copy link
Member Author

rycee commented Jan 16, 2020

@infinisil I gave the lib.extend function a try. I think it works pretty well 🙂

@infinisil
Copy link
Collaborator

infinisil commented Jan 16, 2020

Nice, another thing that might need changing here is the NixOS module. NixOS/nixpkgs#75031 introduced the submoduleWith type, which should allow you to change lib within submodules, e.g.

submoduleWith {
  modules = [ ... ];
  specialArgs.lib = extendedLib;
  # To be backwards compatible with `types.submodule`
  shorthandOnlyDefinesConfig = true;
}

@rycee
Copy link
Member Author

rycee commented Jan 18, 2020

@infinisil Yep, that does indeed seem to work just fine!

@kalbasit Are you using HM with nix-darwin master? If so, would you mind giving this branch a try to verify that it still works?

@infinisil
Copy link
Collaborator

Ah and I just realized that shorthandOnlyDefinesConfig = true; is not needed because home-manager doesn't have any top-level options named config or options.

@rycee
Copy link
Member Author

rycee commented Jan 19, 2020

@infinisil Yeah. I left the shorthandOnlyDefinesConfig attribute out from the call to submoduleWith, which as far as I an tell should default it to false. This shouldn't be a problem exactly because HM doesn't have these config and options variables, right?

I suppose it could cause difficulties for somebody who, for some strange reason, made their own module having options named config or options. I'll add a release note about this change where I note this caveat.

@rycee
Copy link
Member Author

rycee commented Jan 20, 2020

Added some release notes. Rendered:
release-notes

@rycee rycee force-pushed the extended-stdlib branch 2 times, most recently from 241af0b to f6dbcf0 Compare January 21, 2020 19:22
@kalbasit
Copy link
Collaborator

@kalbasit Are you using HM with nix-darwin master? If so, would you mind giving this branch a try to verify that it still works?

I'm getting an error building with the latest nix-darwin master, along with this branch. I have not changed anything in my configuration.

 λ  ./bin/shabka build --show-trace
[INFO] Building host athena
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
+ RELEASE=release-unstable
+ nix-build /Users/yl/code/personal/base/src/github.com/kalbasit/dotshabka/hosts/athena -A system --show-trace
error: while evaluating the attribute 'system' at /nix/store/lc20q0x27jklbwi263pch7da5wf4w8wy-nix-darwin-a14315c96edcedddab74af8353cfec3017a8157d/default.nix:29:3:
while evaluating the attribute 'config.system.build.toplevel' at undefined position:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:84:45, called from undefined position:
while evaluating the attribute 'value' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:379:9:
while evaluating the option `system.build':
while evaluating the attribute 'mergedValue' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:411:5:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:413:22, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:413:9:
while evaluating 'merge' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:292:20, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:416:12:
while evaluating 'filterAttrs' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:124:23, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:293:35:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:125:29, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:125:18:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:293:51, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:125:62:
while evaluating the attribute 'toplevel' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:344:7:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:293:86, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:344:15:
while evaluating the attribute 'optionalValue' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:424:5:
while evaluating the attribute 'values' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:405:9:
while evaluating the attribute 'values' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:505:7:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:391:28, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:391:17:
while evaluating 'dischargeProperties' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:464:25, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:392:62:
while evaluating the attribute 'value' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:297:60:
while evaluating 'throwAssertions' at /nix/store/lc20q0x27jklbwi263pch7da5wf4w8wy-nix-darwin-a14315c96edcedddab74af8353cfec3017a8157d/modules/system/default.nix:13:21, called from /nix/store/lc20q0x27jklbwi263pch7da5wf4w8wy-nix-darwin-a14315c96edcedddab74af8353cfec3017a8157d/modules/system/default.nix:73:29:
while evaluating the attribute 'assertions' at undefined position:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:84:45, called from undefined position:
while evaluating the attribute 'value' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:379:9:
while evaluating the option `assertions':
while evaluating the attribute 'mergedValue' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:411:5:
while evaluating the attribute 'values' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:405:9:
while evaluating the attribute 'values' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:505:7:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:391:28, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:391:17:
while evaluating 'dischargeProperties' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:464:25, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:392:62:
while evaluating 'dischargeProperties' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:464:25, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:470:11:
while evaluating the attribute 'content' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:549:14:
while evaluating 'flatten' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:137:13, called from /nix/store/ickwawx6a1h0jnn87id2hpc20wlbj7ba-home-manager-release-unstable-f6dbcf00bba7154d6e1c2aea92d8b48351243399/nix-darwin/default.nix:58:7:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:139:21, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:139:10:
while evaluating 'flatten' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:137:13, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:139:24:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:234:10, called from undefined position:
while evaluating anonymous function at /nix/store/ickwawx6a1h0jnn87id2hpc20wlbj7ba-home-manager-release-unstable-f6dbcf00bba7154d6e1c2aea92d8b48351243399/nix-darwin/default.nix:58:53, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/attrsets.nix:234:16:
while evaluating 'flip' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/trivial.nix:138:16, called from /nix/store/ickwawx6a1h0jnn87id2hpc20wlbj7ba-home-manager-release-unstable-f6dbcf00bba7154d6e1c2aea92d8b48351243399/nix-darwin/default.nix:59:9:
while evaluating the attribute 'yl' at undefined position:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:293:22, called from undefined position:
while evaluating the attribute 'value' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:425:27:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:413:22, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:413:9:
while evaluating 'merge' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/types.nix:441:22, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:416:12:
while evaluating the attribute 'config' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:96:25:
while evaluating 'yieldConfig' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:83:29, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:82:16:
while evaluating 'mergeModules' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:233:26, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:73:17:
while evaluating 'mergeModules'' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:237:36, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:234:5:
while evaluating 'flip' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/trivial.nix:138:16, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:280:6:
while evaluating 'byName' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:260:25, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:268:21:
while evaluating 'reverseList' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/lists.nix:393:17, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:73:38:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:167:37, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:68:19:
while evaluating 'filterModules' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:157:36, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:168:7:
while evaluating anonymous function at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:161:31, called from undefined position:
while evaluating 'loadModule' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:106:53, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:144:22:
while evaluating 'unifyModuleSyntax' at /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:172:34, called from /nix/store/aazr59pv1w56ysrn4gw2id3k81i7ykpn-nixpkgs-release-unstable-100012e55bc2a82fc680cba31a426ad38ead6fab/lib/modules.nix:108:11:
undefined variable 'extendedLib' at /nix/store/ickwawx6a1h0jnn87id2hpc20wlbj7ba-home-manager-release-unstable-f6dbcf00bba7154d6e1c2aea92d8b48351243399/nix-darwin/default.nix:10:27

@rycee
Copy link
Member Author

rycee commented Jan 21, 2020

@kalbasit Thanks! I force-pushed an update that I hope fixes this error.

This change makes use of the `extend` function inside `lib` to inject
a new `hm` field containing the Home Manager library functions. This
simplifies use of the Home Manager library in the modules and reduces
the risk of accidental infinite recursion.

PR #994
@kalbasit
Copy link
Collaborator

It seems to build fine now. I switched the system and things are looking the same as well.

@rycee
Copy link
Member Author

rycee commented Jan 21, 2020

@kalbasit Brilliant, I'll merge.

@rycee rycee merged commit 6e4b9af into master Jan 21, 2020
@rycee rycee deleted the extended-stdlib branch January 21, 2020 19:56
jorsn pushed a commit to jorsn/home-manager that referenced this pull request Apr 25, 2020
This change makes use of the `extend` function inside `lib` to inject
a new `hm` field containing the Home Manager library functions. This
simplifies use of the Home Manager library in the modules and reduces
the risk of accidental infinite recursion.

PR nix-community#994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants