nix-starter-configs icon indicating copy to clipboard operation
nix-starter-configs copied to clipboard

Rebuilding with custom packages fails

Open Kmetran opened this issue 1 year ago • 8 comments

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 avatar Nov 12 '23 22:11 Kmetran

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?

Kmetran avatar Nov 15 '23 20:11 Kmetran

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, ...}: {

proglottis avatar Nov 22 '23 00:11 proglottis

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

vakili avatar Nov 26 '23 22:11 vakili

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.

arthsmn avatar Jan 04 '24 15:01 arthsmn

Thank you, this helped me too.

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

voidzero avatar Jan 22 '24 20:01 voidzero

@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:

bcyran avatar Mar 09 '24 09:03 bcyran

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

m3tam3re avatar Mar 23 '24 16:03 m3tam3re

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;

LateNightIceCream avatar Apr 25 '24 08:04 LateNightIceCream