In nix repl I can load my systems flake and call the module function. But how can I easily give the attribute set when calling/loading the module, eg. something like
You really ought to instantiate a nixosSystem with the module to try to use it. And it looks like you already have nixosConfigurations.HOST, so assuming that imports the module, it’s already there within nixosConfigurations.HOST.config. e.g. in that instance, since the module defines environment.shellAliases.py, you can do nixosConfigurations.HOST.config.environment.shellAliases.py
Your syntax is wrong btw. Function calling binds tighter than operators, so trace 3+3 true is actually (trace 3) + (3 true), which incorrectly treats trace as a function of only one argument, and also tries to call 3 as though it were a function instead of a number. Should be trace (3+3) true
{ lib, config, ... }:
let
cfg = config.mymodule;
in
{
options = {
mymodule = {
firstName = lib.mkOption {
description = "Your first name";
type = lib.types.str;
default = "John";
};
lastName = lib.mkOption {
description = "Your last name";
type = lib.types.str;
default = "Doe";
};
fullName = lib.mkOption {
type = lib.types.str;
};
};
};
config = {
mymodule.fullName = "${cfg.firstName} ${cfg.lastName}";
};
}
sandbox.nix
(import <nixpkgs/lib>).evalModules {
modules = [{
# import your module here
imports = [ ./mymodule.nix ];
# For testing you can set any configs here
mymodule.firstName = "Jaques";
}];
}
Run and eval
ls -1 *.nix | \
entr sh -c 'nix-instantiate --eval ./sandbox.nix --strict -A config --json | jq'