Hi all! I am experimenting with NixOS, and I am hitting a roadblock as I can’t find any documentation on how to pass multiple arguments to an imported nix file. I tried the usage of args
, but also lib.mkOption
, but both seem to fail.
Note that I am running this from home-manager, e.g. home-manager switch -n
. I have the feeling that impacts the way I am off on a conceptual level, or misunderstand how nix import
works. I think I have to use config
, but don’t understand how that works.
I am getting a range of errors related to missing Attributes or just build failures.
The relevant code reduced to the essentials is the following:
home.nix
{ config, pkgs, lib, ... }:
let
username = "myuser";
homeDirectory = "/somepath";
myarg = 2;
myfunction = import ./myfunction.nix {
lib = lib;
# passing additional args here does not work for example
# foo = myarg;
};
# more nix
# ...
in {
home.username = username;
home.homeDirectory = homeDirectory;
# Here I would like to use myfunction.something
# I don't think I understand the syntax.
# more nix setting home.file and such
# ....
home.packages = with pkgs; [
jq
];
home.sessionVariables = {
# EDITOR = "emacs";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}
myfunction.nix
{ lib, ... }:
let
# does not work
# foo = args.foo;
a = args.foo or 0;
result = foo + 3;
in {
something = result;
}
I can’t find docs on how to do this properly. Could somebody point me to the right documentation or give a minimal example?
Thanks a lot!