Misterio77 / nix-starter-configs

Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need!
Creative Commons Zero v1.0 Universal
2.25k stars 120 forks source link

Rebuilding with custom packages fails #54

Open Kmetran opened 8 months ago

Kmetran commented 8 months ago

I wrote a simple shell script using writeShellApplication in a file called default.nix, inside a folder called custompackage in the pkgs folder, and then added it to pkgs/default.nix like this: custompackage = pkgs.callPackage ./custompackage {};

After that, I tried adding it to environment.systemPackages or home.packages, but either way, rebuilding fails with: attribute 'callPackage' missing

I'm using the standard template, and it does build if pkgs/default.nix has no package.

Kmetran commented 8 months ago

This is off topic so sorry in advance :smile:, but how could I use an overlay that I added in overlays in a custom package in pkgs?

proglottis commented 8 months ago

I just ran into this exact error message. The secret sauce for me was changing the function declaration in pkgs/default.nix from

pkgs: {

To

{pkgs, ...}: {
vakili commented 8 months ago

Thanks @proglottis, I had the same issue and this fixed it.

arthsmn commented 6 months ago

Can anyone explain why this is the case? And if this will ever be added to the repository, because without it the overlay doesn't work.

voidzero commented 6 months ago

Thank you, this helped me too.

I'm sure when @Misterio77 returns he'll give it a look.

bcyran commented 4 months ago

@proglottis Thank you so much for this. I spent too much time trying to figure it out and I didn't make even a step in the right direction. Nix is so hard :cry:

m3tam3re commented 4 months ago

That also solved it for me. But I would really like know why.

LateNightIceCream commented 2 months ago

This is because in this line in overlays/default.nix

additions = final: _prev: import ../pkgs { pkgs = final; };

we call our function defined in pkgs/default.nix with an attribute set as an argument in which the value pkgs equals final.

However, looking at our function definition

pkgs : {
  ...
}

our single argument will become pkgs = { pkgs = final; }. So then pkgs.callPackage would have to be pkgs.pkgs.callPackage. And indeed this would work.

Changing this as @proglottis suggested works because we are changing the function definition to receive as an argument a set with a certain attribute requirement (pkgs). We can then reference this attribute directly.

Another way to fix this is to keep pkgs/default.nix the same and instead change the function call in overlays/default.nix:

additions = final: _prev: import ../pkgs final;

or if we really only want to pass pkgs (which is probably what is intended here):

additions = final: _prev: import ../pkgs final.pkgs;