feat: auto import modules and simplify configs
This commit is contained in:
@@ -7,19 +7,23 @@
|
||||
name:
|
||||
{
|
||||
system,
|
||||
users ? [ ],
|
||||
user ? null,
|
||||
}:
|
||||
|
||||
let
|
||||
hostConfig = ../hosts/${name}/configuration.nix;
|
||||
hostHWConfig = ../hosts/${name}/hardware-configuration.nix;
|
||||
hasHWConfig = builtins.pathExists hostHWConfig;
|
||||
hasUser = user != null;
|
||||
|
||||
userNixosConfigs = map (user: ../users/${user}/nixos.nix) (
|
||||
builtins.filter (user: builtins.pathExists ../users/${user}/nixos.nix) users
|
||||
);
|
||||
userKeys = if hasUser then import ../users/${user}/keys.nix else { };
|
||||
|
||||
userHMConfigs = nixpkgs.lib.genAttrs users (user: import ../users/${user}/home-manager.nix);
|
||||
# auto-import all nixos modules and profiles
|
||||
nixosModuleList = builtins.attrValues inputs.self.nixosModules;
|
||||
nixosProfileList = builtins.attrValues inputs.self.nixosProfiles;
|
||||
|
||||
# auto-import all home-manager modules
|
||||
hmModuleList = builtins.attrValues inputs.self.homeManagerModules;
|
||||
|
||||
in
|
||||
nixpkgs.lib.nixosSystem {
|
||||
@@ -33,16 +37,23 @@ nixpkgs.lib.nixosSystem {
|
||||
hostConfig
|
||||
]
|
||||
++ nixpkgs.lib.optional hasHWConfig hostHWConfig
|
||||
++ userNixosConfigs
|
||||
++ nixosModuleList
|
||||
++ nixosProfileList
|
||||
++ nixpkgs.lib.optional (
|
||||
hasUser && builtins.pathExists ../users/${user}/nixos.nix
|
||||
) ../users/${user}/nixos.nix
|
||||
++ [
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.backupFileExtension = "backup";
|
||||
home-manager.users = userHMConfigs;
|
||||
home-manager.users = nixpkgs.lib.mkIf hasUser {
|
||||
${user} = import ../users/${user}/home-manager.nix;
|
||||
};
|
||||
home-manager.sharedModules = hmModuleList;
|
||||
home-manager.extraSpecialArgs = { inherit inputs; };
|
||||
}
|
||||
];
|
||||
specialArgs = { inherit inputs; };
|
||||
specialArgs = { inherit inputs userKeys; };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user