NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
11.47k stars 1.44k forks source link

nix repl repl-flake behaves differently than :lf #8059

Open sg-qwt opened 1 year ago

sg-qwt commented 1 year ago

Not sure of this is a bug or desired behavior of the new experimental repl-flake.

With repl-flake enabled and entered my nixos flake, when I run nix repl .#, only 5 variables added. In my previous workflow with :lf inside repl, I can see more variables added. Things like input etc are missing by nix repl .#

> nix repl .#
Welcome to Nix 2.13.3. Type :? for help.

Loading installable 'git+file:///home/me/nixos#'...
Added 5 variables.
nix-repl> :lf .#
Added 17 variables
asymmetric commented 1 year ago

Slightly related: is there a way to print defined variables?

mvnetbiz commented 1 year ago

what's added by nix repl .#

diff nothing.txt replflake.txt | grep \>
> devShells
> legacyPackages
> nixosConfigurations
> overlays
> packages

what's additionally loaded by :lf

diff replflake.txt lf.txt | grep \>
> _type
> inputs
> lastModified
> lastModifiedDate
> narHash
> outPath
> outputs
> sourceInfo
> submodules

The nix \<flake>#\<attribute> argument apparently only supports the output attributes, so maybe it would make sense to make all nix commands support these attributes too, not just the output attributes. For example, then you could run nix build .#inputs.nixpkgs.hello to build hello from the nixpkgs input of the flake.

mvnetbiz commented 1 year ago

This workaround loads all the same attributes as :lf with nix repl .#, but some commands show the "unknown" attributes


{
  outputs = { self, ... }: {
    inherit (self) _type inputs lastModified lastModifiedDate narHash outPath outputs sourceInfo submodules;
  };
}
thufschmitt commented 4 months ago

Discussed during the Nix maintainers meeting on 2024-02-26.

nixos-discourse commented 4 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-02-28-nix-team-meeting-129/40499/1

KiaraGrouwstra commented 3 months ago

@asymmetric:

Slightly related: is there a way to print defined variables?

you can use functions like trace (from builtins/lib).

@mvnetbiz:

what's additionally loaded by :lf

actually, lib differs between the two as well - for :lf it seems to also have stuff like lib.nixosSystem

thufschmitt commented 3 months ago

actually, lib differs between the two as well - for :lf it seems to also have stuff like lib.nixosSystem

Do you mean that nix repl nixpkgs doesn't give you lib.nixosSystem?

$ nix repl nixpkgs
Nix 2.21.0pre20240304_4388559
Type :? for help.
Loading installable 'flake:nixpkgs#'...
Added 5 variables.
nix-repl> lib.nixosSystem 
«lambda nixosSystem @ /nix/store/3i3rncs75fid9hwai5p2nvwc4ngdnia7-source/flake.nix:21:23»