Can anyone explain this strange behaviour of nix interpreter?


#1

Hi. I recently found strange behaviour

% nix repl
Welcome to Nix version 2.1.3. Type :? for help.

nix-repl> a = import {}

nix-repl> b = import {}

nix-repl> a == b
false

but if

% nix repl
Welcome to Nix version 2.1.3. Type :? for help.

nix-repl> a = import {}

nix-repl> b = a

nix-repl> a == b
error: assertion failed at /nix/store/zkqn8mj44lp5ii8ck2jxp137y9w6d1g1-nixos-19.03pre159472.80738ed9dc0/nixos/pkgs/top-level/all-packages.nix:9202:12

this behavior is counter intuitive, can anyone explain what is going on here? The second one looks understandable, but why the first one returns just false and not trying to evaluate tree? As I understand first and second case must behave just identical.


#2

Are you loading something from $HOME? There’s a tilde in your post.
The imports themselves fail, but due to laziness it won’t fail until expressed.

I get a different set of errors:

error: cannot coerce a set to a string, at (string):1:2

which makes a lot more sense.


#3

I am running it on NixOS 19.03 and paths are loaded from NIX_PATH

% echo $NIX_PATH
/home/razor/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

The tildas are just result of inaccurate copy pasting from terminal, they are not relevant, my fault.