Hi,
I’m new to Nix and I’m trying structure my NixOS configuration. Therefore I created the following file which should eventually hold all settings of a specific user:
# users/tom/default.nix
{}: {
systemSettings = { config, ... }: {
imports = [];
# Apply base user system settings
inherit ((import ../base.nix).systemSettings {});
# Apply user specific user system settings
config = {
users.users.tom = {
# Set password
initialPassword = "changeme";
};
};
};
homeSettings = { ... }: {
# TODO
};
}
As far as I understand, a module is a function taking the current config
and returning a set with three keys (imports
, config
, options
). Therefore the function systemSettings
returns a module, correct?
To group all users together I created this file:
# users/default.nix
{}: {
tom = import ./tom {};
}
Now I want to use the module the function returns in my NixOS configuration but I don’t know how to provide the config
parameter. The code looks like this:
{
description = "NixOS Configuration";
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.11";
home-manager = {
url = "home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, home-manager, ...}@inputs:
let
inherit (nixpkgs) lib;
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
system = "x86_64-linux";
# Import users
users = import ./users {};
in {
nixosConfigurations = {
nuc = lib.nixosSystem {
inherit system;
modules = [
{
# Base system configuration
}
{
imports = [];
options = {};
# Use users.tom.systemSettings
config = users.tom.systemSettings {
inherit super; # How to get "config"?
};
}
];
};
};
};
}
Thank you very much in advance for reading through all of this. I’m fairly new to Nix so my code is probably far from perfect. But I appreciate any help (regarding this topic or other stuff that’s wrong about the code)