I am writing some custom functions for extracting the user config (users.users.<name>
) from other configurations, as I want to make the config stateless and easy to share.
mkSystem = mkExtendable ({ system, inputs, modules ? { } }:
let
hasHm = (builtins.hasAttr "home-manager" inputs)
|| (builtins.hasAttr "hm" inputs);
injected = (builtins.map (m:
let
# Import and do the assertion for the input
imported = if builtins.isPath m then (import m) inputs.nixpkgs else m;
checked = imported;
in (checked)) (toList modules));
in (inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = (checked) ++ (inputs.nixpkgs.lib.optional hasHm
inputs.home-manager.nixosModules.home-manager);
specialArgs = { inherit inputs system; };
}));
I think the most ideomatic way for assertion in nixos would be doing with the assertions
like this, a random piece of code from HM:
But I cannot assert it like this, because by default the users.users.<name>
will have root
and nobody
, and I don’t want to mess with them.
And the import I have right now, gives me this error:
error: anonymous function at /nix/store/739czqh6li2gbg88llj08lkjsn16dhfw-source/hardware-configuration.nix:4:1 called without required argument 'config'
at /nix/store/la7x9ljhi2lllh8cf1hcnl80nrz1s439-source/lib.nix:73:48:
72| let
73| imported = if builtins.isPath m then (import m) inputs.nixpkgs else m;
| ^
74| checked = imported;
(use '--show-trace' to show detailed location information)
Can I import the modules here with import
? How can I do that?