Convert libs to a fixed-point#27797
Conversation
|
Hmm, not quite sure I see the benefit here but no strong objections either. |
|
Yeah, the benefit is limited, but in cases of the function I mostly put it up in case someone else had a convincing reason :) |
lib/default.nix
Outdated
There was a problem hiding this comment.
Isn't this comment obsolete with this change?
There was a problem hiding this comment.
Oops leftover from when I was in the middle of the conversion. Fixed.
lib/modules.nix
Outdated
There was a problem hiding this comment.
The parentheses are unnecessary here.
lib/default.nix
Outdated
There was a problem hiding this comment.
Also, this (with lib; {}) doesn't make sense to me either.
There was a problem hiding this comment.
Oops leftover from when I was in the middle of the conversion. Fixed.
lib/default.nix
Outdated
There was a problem hiding this comment.
What's this with lib; {} for?
There was a problem hiding this comment.
Oops leftover from when I was in the middle of the conversion. Fixed.
4dc091b to
9a0e632
Compare
An example is
but the reality is that comment is impossible to accomplish with the current structure. |
|
@aszlig I added a commit where I tried your suggestion of moving the inherits to the bottom. |
aszlig
left a comment
There was a problem hiding this comment.
Okay, that at least makes it a bit easier on the eyes :-)
|
👍 after clarification on IRC what this PR actually improves:
|
|
On IRC, @edolstra said that the massive list of inherits is ugly, but probably unavoidable due to the lack of laziness in Unless there is further feedback, I'm planning on merging this later today or tomorrow. |
LnL7
left a comment
There was a problem hiding this comment.
Since this makes the functions exposed in lib explicit now should we add a deprecation notice to the functions that obviously don't belong there?
Ericson2314
left a comment
There was a problem hiding this comment.
Ah, I was hoping somebody would remove the extra imports eventually! Besides the other benefits, this should speed up evaluation a bit.
|
@fpletz what sort of docs and changelog would you like to see? |
|
@grahamc I haven't looked at the manuals yet but this change at least deserves a paragraph in the nixpkgs manual. We should also mention this in the NixOS 17.09 release notes. |
|
I suppose I'm having a hard time writing the docs because not much has changed. Maybe:
|
|
I've used the following to verify the same attributes are being exported on lib: unfortunately this isn't recursive, looks like I have more testing to do: on types. |
This does break the API of being able to import any lib file and get its libs, however I'm not sure people did this. I made this while exploring being able to swap out docFn with a stub in NixOS#2305, to avoid functor performance problems. I don't know if that is going to move forward (or if it is a problem or not,) but after doing all this work figured I'd put it up anyway :) Two notable advantages to this approach: 1. when a lib inherits another lib's functions, it doesn't automatically get put in to the scope of lib 2. when a lib implements a new obscure functions, it doesn't automatically get put in to the scope of lib Using the test script (later in this commit) I got the following diff on the API: + diff master fixed-lib 11764a11765,11766 > .types.defaultFunctor > .types.defaultTypeMerge 11774a11777,11778 > .types.isOptionType > .types.isType 11781a11786 > .types.mkOptionType 11788a11794 > .types.setType 11795a11802 > .types.types This means that this commit _adds_ to the API, however I can't find a way to fix these last remaining discrepancies. At least none are _removed_. Test script (run with nix-repl in the PATH): #!/bin/sh set -eux repl() { suff=${1:-} echo "(import ./lib)$suff" \ | nix-repl 2>&1 } attrs_to_check() { repl "${1:-}" \ | tr ';' $'\n' \ | grep "\.\.\." \ | cut -d' ' -f2 \ | sed -e "s/^/${1:-}./" \ | sort } summ() { repl "${1:-}" \ | tr ' ' $'\n' \ | sort \ | uniq } deep_summ() { suff="${1:-}" depth="${2:-4}" depth=$((depth - 1)) summ "$suff" for attr in $(attrs_to_check "$suff" | grep -v "types.types"); do if [ $depth -eq 0 ]; then summ "$attr" | sed -e "s/^/$attr./" else deep_summ "$attr" "$depth" | sed -e "s/^/$attr./" fi done } ( cd nixpkgs #git add . #git commit -m "Auto-commit, sorry" || true git checkout fixed-lib deep_summ > ../fixed-lib git checkout master deep_summ > ../master ) if diff master fixed-lib; then echo "SHALLOW MATCH!" fi ( cd nixpkgs git checkout fixed-lib repl .types )
|
An update, and good news! Using the test script (later in this commenet) I got the following diff This means that this commit adds to the API, however I can't find a The test script recursively explores attribute keys (with crude loop prevention) and produces the same diff for 10 recursions (though the pasted script does 4). Test script (run with nix-repl in the PATH): |
|
Heads up: I'm planning on merging this on Tuesday unless someone asks me not to :) |
|
Final warning: I'll be merging this in between 12 and 24 hours. |
This does break the API of being able to import any lib file and get
its libs, however I'm not sure people did this.
I made this while exploring being able to swap out docFn with a stub
in #2305, to avoid functor performance problems. I don't know if that
is going to move forward (or if it is a problem or not,) but after
doing all this work figured I'd put it up anyway :)
Two notable advantages to this approach:
automatically get put in to the scope of lib
automatically get put in to the scope of lib
Things done
Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.
(nix.useSandbox on NixOS,
or option
build-use-sandboxinnix.confon non-NixOS)
nix-shell -p nox --run "nox-review wip"./result/bin/)