Debugging What parameters are passed to a mouse/function

I am trying to produce a configuration for my machine.

I have a file containing

# Load lib code
haumea.lib.load {
  src = ./src;

and I get the error

   error: function 'anonymous lambda' called with unexpected argument 'inputs'

       at /nix/store/qs41xp9pkgbfcwf27k1g8f8531fydc7y-source/lib/default.nix:5:1:

            4| # Load lib code
            5| {
             | ^
            6|   lib,

Why does it complain about an argument that is not in the file?
How can I tell what arguments are passed to the function - ie what the calling function is sending sdown?

_module.args does not have inputs but and argument to flake-parts does have inherit inputs

Is there anyway to make the arguments called and passed explicit otherwise I seem to have to add an inherit here and that breaks another call.

I want my lib functions to be sealed and only take and pass in what I say. Otherwise I just doing not know what data is being passed in or out.

At a minimum how can I see what attributes are passed to a function and also be sure that nothing that function calls uses another arguments.

Well, some file importing the Nix file is passing the inputs argument. If the file is a module, I would expect some other module adds inputs to _module.args but it is hard to tell without knowing the importer (i.e. having a full trace).

Something like this should work:

bultins.trace args (
  haumea.lib.load {
    src = ./src;

Nix is basically a purely functional language. If you do not use the other args explicitly, nothing will have access to them.

I understand the language I think.

But with modules (and possibly flake-parts) I get the issue in that if a module complains it is not being passed argument x

error: function 'anonymous lambda' called without required argument 'mwblib"
  • I then add inherit x to _module.args and nix flake check goes further but then complains on another module that it is being passed argument x which it dose not want.
error: function 'anonymous lambda' called with unexpected argument 'mwblib'

(Or vice versa)

So how can I control passing an argument to only some modules

I am saying there is little point in that.

You could do something like:

{ pkgs, ... }:
  sealModuleOnlyLib = modulePath: {lib, ...}: import modulePath { inherit lib; };
  imports = [
    (sealModuleOnlyLib ./foo.nix)

But then you will need a sealing function for every combination of function arguments of your sealed modules.

Or you could create a introspective sealing function using builtins.functionArgs similarly to how callPackage works but then you would not be able to prevent the modules just adding whatever they want, and the sealing function happily obliging. At which point you can just go with the recommended usage pattern of ellipsis argument and not capturing the rest of arguments with @ – you will not have top-down enforcement but there will be much less hassle.

Also even the explicit sealing would not prevent transitive imports breaking out of the jail. For that you would probably need a separate module system instance.

But I still do not understand what you are trying to achieve.

I am trying to create a library in ./lib which I can import and a set of packages that I import using a function in ./lib that uses callPackage to call all the directories in ./pkgs.

The pkgs seem to be called in 3 places

  1. nixosConfigurations (and jomeConfiguration)
  2. setup devshells
  3. in nix flake check

I can get 2 out of the 3 to work but not all 3 there is always a call importing the packages that complains that an attribute is passed or not passed to the function (or that the function needs an input that is not passed in when making the library call but it is imported when in import ./lib.