feat: Enable system flake additions from external files
This commit is contained in:
@@ -47,22 +47,36 @@ let
|
||||
mkHostGroup = { prefix, count, system ? "x86_64-linux", extraModules ? [], deviceOverrides ? {} }:
|
||||
lib.listToAttrs (map (i: {
|
||||
name = "${prefix}${toString i}";
|
||||
value = mkHost {
|
||||
hostName = "${prefix}${toString i}";
|
||||
inherit system;
|
||||
extraModules = extraModules ++
|
||||
(lib.optional (builtins.hasAttr (toString i) deviceOverrides)
|
||||
({ ... }:
|
||||
let
|
||||
devConf = deviceOverrides.${toString i};
|
||||
fsConf = builtins.removeAttrs devConf [ "extraUsers" ];
|
||||
in {
|
||||
host.filesystem = fsConf;
|
||||
modules.users.enabledUsers = devConf.extraUsers or [];
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
value =
|
||||
let
|
||||
devConf = deviceOverrides.${toString i} or {};
|
||||
hasOverride = builtins.hasAttr (toString i) deviceOverrides;
|
||||
|
||||
# Extract flakeUrl if it exists
|
||||
externalFlake = if hasOverride && (builtins.hasAttr "flakeUrl" devConf)
|
||||
then builtins.getFlake devConf.flakeUrl
|
||||
else null;
|
||||
|
||||
# Module from external flake
|
||||
externalModule = if externalFlake != null
|
||||
then externalFlake.nixosModules.default
|
||||
else {};
|
||||
|
||||
# Config override module
|
||||
overrideModule = { ... }:
|
||||
let
|
||||
# Remove special keys that are not filesystem options
|
||||
fsConf = builtins.removeAttrs devConf [ "extraUsers" "flakeUrl" ];
|
||||
in lib.mkIf hasOverride {
|
||||
host.filesystem = fsConf;
|
||||
modules.users.enabledUsers = devConf.extraUsers or [];
|
||||
};
|
||||
in
|
||||
mkHost {
|
||||
hostName = "${prefix}${toString i}";
|
||||
inherit system;
|
||||
extraModules = extraModules ++ [ overrideModule ] ++ (lib.optional (externalFlake != null) externalModule);
|
||||
};
|
||||
}) (lib.range 1 count));
|
||||
|
||||
# Generate host groups based on the input hosts configuration
|
||||
|
||||
@@ -3,7 +3,7 @@ let
|
||||
userSubmodule = lib.types.submodule {
|
||||
options = {
|
||||
isNormalUser = lib.mkOption { type = lib.types.bool; default = true; };
|
||||
description = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; };
|
||||
description = lib.mkOption { type = lib.types.str; default = ""; };
|
||||
extraGroups = lib.mkOption { type = lib.types.listOf lib.types.str; default = []; };
|
||||
hashedPassword = lib.mkOption { type = lib.types.str; default = "!"; };
|
||||
extraPackages = lib.mkOption { type = lib.types.listOf lib.types.package; default = []; };
|
||||
@@ -49,9 +49,7 @@ in
|
||||
finalPackages = lib.subtractLists user.excludePackages (defaultPackages ++ user.extraPackages);
|
||||
in
|
||||
{
|
||||
inherit (user) isNormalUser extraGroups hashedPassword;
|
||||
description = if user.description != null then user.description else lib.mkDefault "";
|
||||
openssh.authorizedKeys.keys = user.opensshKeys;
|
||||
inherit (user) isNormalUser description extraGroups hashedPassword;
|
||||
packages = finalPackages;
|
||||
shell = config.modules.users.shell;
|
||||
}
|
||||
@@ -68,7 +66,7 @@ in
|
||||
enabledAccounts = lib.filterAttrs (name: _: lib.elem name config.modules.users.enabledUsers) config.modules.users.accounts;
|
||||
in
|
||||
lib.mapAttrs (name: user: { ... }: {
|
||||
imports = user.extraImports ++
|
||||
imports = user.extraImports ++ [ ../sw/theme.nix ../sw/nvim.nix ] ++
|
||||
(lib.optional (user.flakeUrl != "") (builtins.getFlake user.flakeUrl).homeManagerModules.default);
|
||||
home.username = name;
|
||||
home.homeDirectory = if name == "root" then "/root" else "/home/${name}";
|
||||
|
||||
Reference in New Issue
Block a user