1# Pitfalls
2
3"There are pitfalls in this language???!??!?"
4
5*-- The uninitiated*
6
7## importing nixpkgs with an empty attrset
8
9ever had this in your flake.nix
10
11```nix
12{
13 outputs = { nixpkgs, ... }@inputs: let
14 pkgs = import nixpkgs {};
15 lib = nixpkgs.lib;
16 in {
17 # ...
18 };
19}
20```
21
22... and got fucked with this?
23```shell
24error:
25 … while checking flake output 'nixosConfigurations'
26
27 at /nix/store/lz2ra1180qfffmpwg41jpyg1z602qdgx-source/flake.nix:50:5:
28
29 49| in {
30 50| nixosConfigurations = {
31 | ^
32 51| koumakan = (import ./systems/koumakan { inherit pkgs lib inputs; });
33
34 … while checking the NixOS configuration 'nixosConfigurations.koumakan'
35
36 at /nix/store/lz2ra1180qfffmpwg41jpyg1z602qdgx-source/flake.nix:51:7:
37
38 50| nixosConfigurations = {
39 51| koumakan = (import ./systems/koumakan { inherit pkgs lib inputs; });
40 | ^
41 52| };
42
43 (stack trace truncated; use '--show-trace' to show the full trace)
44
45 error: attribute 'currentSystem' missing
46
47 at /nix/store/5c0k827yjq7j24qaq8l2fcnsxp7nv8v1-source/pkgs/top-level/impure.nix:17:43:
48
49 16| # (build, in GNU Autotools parlance) platform.
50 17| localSystem ? { system = args.system or builtins.currentSystem; }
51 | ^
52 18|
53```
54
55just don't!!!11 remove the pkgs definition. (note that this only applies to `pkgs = import nixpkgs {};`)
56
57explanation
58
59> you shouldn't ever really import nixpkgs with an empty attrset either
60>
61> that causes it to fall back on guessing your system using `builtins.currentSystem`,
62> which is impure and so not allowed in pure evaluation mode
63>
64> —- @getchoo