How can I access unstable in a submodule?

I’m not sure what I’ve done wrong, cause this has worked before.

Somehow, in an imported nix file into configuration.nix, “unstable” is undefined.

building Nix...
building the system configuration...
error: undefined variable 'unstable'

       at /home/b0ef/ds/platform/conf/hydra.brogramming.nix:16:3:

           15|   #unstable.dotnet-sdk #
           16|   unstable.dotnet-sdk_7
             |   ^
           17|   #unstable.dotnetPackages.Nuget
(use '--show-trace' to show detailed location information)

The “unstable” variable is defined in configuration.nix, so why can’t the submodule see it? I’m pretty sure I didn’t have to do anything before to make it see it;)

You’re going to want to double-check that. Either it never worked as you described, or you had a with or a let or a function argument or something.

1 Like

ok, but how is it usually done?

I don’t know what you’re trying to do. If unstable is a version of Nixpkgs distinct from the main channel or flake that you’re using for the rest of your configuration, the usual way to incorporate it could be to create an overlay and not have your modules be aware of the distinction between stable and unstable at all. If unstable is some other sort of variable, you could define it in a file that the module imports, or you could create an option for it and reference it from config.

All I have is this configured in configuration.nix

  unstable = import (fetchTarball {config.allowUnfree = true;};

Then I have imported a file, like foo.nix

  imports =

, then I’m trying to use unstable inside foo.nix, like

  environment.systemPackages = with pkgs; [

Using unstable.hukarz inside configuration.nix works fine.

What you probably have in configuration.nix is a let-binding. The scope of that binding is the let-expression itself: everything from the initial let keyword to the expression following in. It doesn’t extend to other files. (If not let, maybe you’ve defined unstable inside an attrset marked rec, which has much the same effect: the scope only extends from the { of the attrset to the matching }.)

Are you experienced with any other programming languages?

Yes, I understand scope and yes, it’s in a let, but how can I add it as a parameter to the module or what is the proper way to let the submodule understand it?:wink:

I’m afraid you should read up on the module system (manual, wiki), because this isn’t a thing it’s designed to do in the way you’re asking. As I said before, I think the typical patterns would be to use unstable in an overlay, import it anew or from a common file, or define a module option and reference the value of that option from config.