Skip to content

Comments

Nix repl flakes#6233

Merged
thufschmitt merged 20 commits intoNixOS:masterfrom
flox:nix-repl-flakes
Jun 29, 2022
Merged

Nix repl flakes#6233
thufschmitt merged 20 commits intoNixOS:masterfrom
flox:nix-repl-flakes

Conversation

@tomberek
Copy link
Contributor

@tomberek tomberek commented Mar 11, 2022

Based on: #5824

Add ability to nix repl to utilize installables syntax.

TODO: more tests

Fixes #5824

@tomberek tomberek requested a review from Ericson2314 March 11, 2022 18:55
@Ericson2314
Copy link
Member

n.b. nix repl fooDir barDir bazDir might also have a different interpretation with this? That does make it a bigger breaking change.

I think we should consider this:

  1. Deprecated features, the opposite of experimental features
  2. an "old nix repl syntax" deprecated feature
  3. Two different CmdRepl, nix v1-repl, nix v2-repl and we vary which one nix repl is using the deprecated feature.

nix v2-repl would require the "nix command" unstable feature so we are free to refine it.


for (auto & [i,what] : getValues()) {
notice("Loading Installable '%1%'...", what);
addAttrsToScope(*i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this effectively merges the attributes of multiple installables?

I don't like that "loadables" are loaded into the global scope anyway. It makes discovering which attributes exist harder than it should.

Perhaps flakes and installables could be put in a binding that's derived from the installable name?

# nix repl nixpkgs
Loading Installable 'flake:nixpkgs#'...
Added 1 variable.

nix-repl> nixpkgs.legacyPackages.x86_64-linux.emacs.name
"emacs-27.1"

nix-repl> nixpkgs.<TAB>
<UX delight ensues as all top-level flake attrs are listed>

Also interesting

# nix repl . .#inputs.nixpkgs
Added 2 variables

nix-repl> foo.<TAB>

nix-repl> nixpkgs.lib.concatStringsSep ":" ["testing" "it"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with this is that flakes don't have an obvious name, so it's not entirely straightforward what the top-level attribute name (e.g. nixpkgs) should be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I pulled foo out of thin air.
Most flake refs have a somewhat straightforward candidate for a name.
Using dirname $PWD for . has produced mixed success in the past though.

Maybe the attribute name should be provided by the user.

nix repl --bind foo . --bind nixpkgs .#inputs.nixpkgs

or

nix repl foo=. nixpkgs=.#inputs.nixpkgs

Adding a bare flake or installable to the top-level scope seems ok-ish as long as there's only one. Or maybe it should default to flake= for a flake and a name derived from the installable otherwise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have the previous behavior of multiple --files to worry about.

I wouldn't mind if it just made an array called args, hah! Then don't have to worry about names, and :a can put whatever one likes at the top level.

@tomberek
Copy link
Contributor Author

tomberek commented Apr 7, 2022

Suggestions from NixUX:

  • more docs
  • more tests
  • improve error message for legacy usage nix repl '<nixpkgs>' (or use --file?)

Fixes: #5824

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of small stylistic comments, but nothing really serious.

I’m a bit more concerned about the unexpect{ed,able} backwards-compatibility breakage. Maybe that could be eased by

  1. Gating the change behind an xp feature flag (if possible making the non-experimental behavior just a layer on top of the new one, otherwise by just brutally duplicating everything)
  2. Adding a flag --file to the “legacy” codepath (that would essentially be a no-op but allows a common interface between both versions)
  3. Warn about usages of nix repl foo.nix, suggest using --file
  4. After one (or two) releases, switch the default to the new behavior and remove the old codepath

Also (somewhat related to the above), --file apparently doesn’t auto-call functions properly anymore, so nix repl --file '<nixpkgs>' fails with error: value is a function while a set was expected

Timothy DeHerrera and others added 5 commits May 18, 2022 21:20
If experimental feature "flakes" is enabled, args passed to `nix repl`
will now be considered flake refs and imported using the existing
`:load-flake` machinery.

In addition, `:load-flake` now supports loading flake fragments.
repl: search installable with findAlongAttrPath
repl: refactor handling of args
repl: temp
Co-authored-by: Théophane Hufschmitt <[email protected]>
@tomberek tomberek requested a review from thufschmitt May 19, 2022 05:03
@thufschmitt
Copy link
Member

@tomberek I’ve added some tests in thufschmitt@1b00dcb if you want to cherry-pick that

Théophane Hufschmitt and others added 3 commits May 20, 2022 07:42
- Test that without the XP feature things work as before
- Test that with or without the XP feature `--file file` works
- Test that with XP feature passing a flakeref works
- Test `:reload` with a flake
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping through my annoying reviews. Except for the small test failure, that’s looking good now!

Co-authored-by: Théophane Hufschmitt <[email protected]>
@tomberek tomberek force-pushed the nix-repl-flakes branch 3 times, most recently from cbabcf7 to 36ce1fb Compare June 2, 2022 20:38
@tomberek
Copy link
Contributor Author

tomberek commented Jun 2, 2022

@bburdette my rebase caused me to interact a bit with your refactor. Please let me know if I've incorrectly resolved something.

@bburdette
Copy link
Contributor

@tomberek as far as I can tell its fine.

@tomberek tomberek requested a review from thufschmitt June 14, 2022 21:24
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh sorry, I though I had it already merged.

I have a couple suggestions for the non-code side, and there's a merge conflict, but looks good otherwise 👍

@thufschmitt
Copy link
Member

@tomberek think you can have a look at the failing test?

@tomberek tomberek requested a review from thufschmitt June 25, 2022 15:25
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

The hardcoded ca-derivations xp feature in the test is a bit annoying, but that'll do for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

9 participants