hello everyone, i’m new to nix , setup nix-darwin on my MBP for a while .
my question is fail on a simple expression, map an attribute set to a value list, here is a minimal case
here is the error
nix-repl> with import <nixpkgs> ; let v = builtins.attrValues { x="A";} ; in typeOf v
error: value is a function while a set was expected
at «none»:0: (source not available)
i just wonder why there v is treat as function, it should be a list value while let
already make it as value
remove typeOf , it runs ok
nix-repl> with import <nixpkgs> ; builtins.attrValues { x="A";}
[ "A" ]
is there something i misunderstood about the nix type system , how to make a lazy value eval in purpose
typeOf is in builtins
, you need to access it with builtins.typeOf
The error message is because you used with import <nixpkgs>;
, but it should be with import <nixpkgs> { };
2 Likes
thank you for helping me to solve the problem.
lack of supporting for nix lang’s package name importing in both vs code and vim, make is really hard scripting.
Anyway , it works now
Your original problem was because you wrote with import <nixpkgs>;
and not with import <nixpkgs> {};
. The with
keyword needs to be followed by a set, but import <nixpkgs>
is a function; apply that function with the argument {}
and you’ll get a set that you can use with the with
keyword.
But yea, the other problem is that typeOf
is in builtins
, not in import <nixpkgs> {}
.