Flakes error `error: attribute 'outPath' missing`

Hey there!

I am trying to set up a Flakes-based system to build an image for a Raspberry Pi Zero W. This is my first time using Nix Flakes so I’m learning as I go, but I ran into an error I cannot seem to solve on my own.

Running nix build .#nixosConfigurations.zigbee2mqtt.config.system.build.sdImage in my git repository with my source files, I get

error: attribute 'outPath' missing

       at /nix/store/p2mbs4mixfskbhp3wf045pi2ssd263ai-source/nixos/modules/services/misc/nix-daemon.nix:542:27:

          541|                 ({ type = "path";
          542|                    path = config.flake.outPath;
             |                           ^
          543|                  } // lib.filterAttrs
(use '--show-trace' to show detailed location information)

I tried including --show-trace but unfortunately it doesn’t help me in pinning down the problem (the stack traces are amazing though, albeit a bit too detailed sometimes :smiley:). It seems to have something to do with the Flake registry, but I’m not using anything custom there. Hence I turn to you! I’ve uploaded my files to a gist here: https://gist.github.com/Hjdskes/632f9ef8c0ca37bb82e6e9072539bc32

Who can tell me what I am doing wrong? :slight_smile:

This is caused by this line

nix.registry.nixpkgs.flake = pkgs;

Move that into your flake.nix and do something like:

modules = [ 
({...}: { nix.registry.nixpkgs.flake = nixpkgs; })

Amazing, thanks for the quick reply @tomberek! Would you happen to have a link to more details? I’m curious to read more about that particular module snippet and why it’s needed.

It’s basically a type error, or rather using the wrong object. The “pkgs” attribute available as the argument in your configuration.nix is not the nixpkgs flake attrset, but a pkgs attrset.