refactor: simplify shared config contracts
This commit is contained in:
+23
-39
@@ -31,17 +31,9 @@ let
|
||||
let
|
||||
hostUserSpecs = lib.mapAttrs (_: spec: normalizeHostUser spec) users;
|
||||
hostUsers = lib.mapAttrs (_: spec: spec.account) hostUserSpecs;
|
||||
|
||||
userAssertions = lib.mapAttrsToList (userName: spec: {
|
||||
assertion = userName == spec.account.name;
|
||||
message = "Host `${name}` declares user `${userName}` with mismatched account name `${spec.account.name}`.";
|
||||
}) hostUserSpecs;
|
||||
|
||||
passwordUserSpecs = lib.filterAttrs (_: spec: spec.needsPassword) hostUserSpecs;
|
||||
in
|
||||
{
|
||||
assertions = userAssertions;
|
||||
|
||||
meta.host = {
|
||||
inherit
|
||||
displays
|
||||
@@ -69,7 +61,7 @@ let
|
||||
users.users = lib.mapAttrs (
|
||||
userName: spec:
|
||||
{
|
||||
name = spec.account.name;
|
||||
name = userName;
|
||||
home = spec.account.homeDirectory;
|
||||
isNormalUser = true;
|
||||
shell = pkgs.zsh;
|
||||
@@ -131,67 +123,59 @@ let
|
||||
}:
|
||||
lib.attrByPath path null pkgs;
|
||||
|
||||
resolveUserTerminal =
|
||||
resolveRepoTerminal =
|
||||
{
|
||||
pkgs,
|
||||
user,
|
||||
}:
|
||||
let
|
||||
terminal = config.meta.lib.repo.desktop.terminal;
|
||||
package = resolvePackagePath {
|
||||
inherit pkgs;
|
||||
path = user.terminalPackagePath;
|
||||
path = terminal.packagePath;
|
||||
};
|
||||
hasPackage = package != null;
|
||||
hasMainProgram = hasPackage && package ? meta.mainProgram;
|
||||
mainProgram = if hasMainProgram then package.meta.mainProgram else null;
|
||||
desktopId = if mainProgram == null then null else "${mainProgram}.desktop";
|
||||
in
|
||||
{
|
||||
inherit
|
||||
desktopId
|
||||
hasMainProgram
|
||||
hasPackage
|
||||
mainProgram
|
||||
package
|
||||
;
|
||||
inherit (terminal)
|
||||
command
|
||||
desktopId
|
||||
packagePath
|
||||
;
|
||||
|
||||
hasPackage = package != null;
|
||||
|
||||
hasDesktopEntry =
|
||||
desktopId != null && builtins.pathExists "${package}/share/applications/${desktopId}";
|
||||
package != null && builtins.pathExists "${package}/share/applications/${terminal.desktopId}";
|
||||
|
||||
hasTerminfo = hasPackage && lib.elem "terminfo" package.outputs;
|
||||
hasTerminfo = package != null && lib.elem "terminfo" package.outputs;
|
||||
};
|
||||
|
||||
mkTerminalAssertions =
|
||||
{
|
||||
terminal,
|
||||
user,
|
||||
requireDesktopEntry ? false,
|
||||
requireKitty ? false,
|
||||
requireMainProgram ? true,
|
||||
requireTerminfo ? false,
|
||||
}:
|
||||
lib.flatten [
|
||||
[
|
||||
{
|
||||
assertion = terminal.hasPackage;
|
||||
message = "Unknown terminal package `${lib.showAttrPath user.terminalPackagePath}` for user `${user.name}`.";
|
||||
message = "Unknown terminal package `${lib.showAttrPath terminal.packagePath}` in `meta.lib.repo.desktop.terminal`.";
|
||||
}
|
||||
{
|
||||
assertion = terminal.command == "kitty";
|
||||
message = "The repo terminal is currently expected to be kitty.";
|
||||
}
|
||||
]
|
||||
(lib.optional requireMainProgram {
|
||||
assertion = terminal.hasMainProgram;
|
||||
message = "Terminal package `${lib.showAttrPath user.terminalPackagePath}` must define `meta.mainProgram`.";
|
||||
})
|
||||
(lib.optional requireDesktopEntry {
|
||||
assertion = terminal.hasDesktopEntry;
|
||||
message = "Terminal package `${lib.showAttrPath user.terminalPackagePath}` must provide `${terminal.desktopId}`.";
|
||||
})
|
||||
(lib.optional requireKitty {
|
||||
assertion = terminal.hasMainProgram && terminal.mainProgram == "kitty";
|
||||
message = "The terminal feature currently only supports kitty-specific Home Manager configuration.";
|
||||
message = "Terminal package `${lib.showAttrPath terminal.packagePath}` must provide `${terminal.desktopId}`.";
|
||||
})
|
||||
(lib.optional requireTerminfo {
|
||||
assertion = terminal.hasTerminfo;
|
||||
message = "Terminal package `${lib.showAttrPath user.terminalPackagePath}` must provide a `terminfo` output.";
|
||||
message = "Terminal package `${lib.showAttrPath terminal.packagePath}` must provide a `terminfo` output.";
|
||||
})
|
||||
];
|
||||
|
||||
@@ -356,9 +340,9 @@ in
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
options.meta.lib.resolveUserTerminal = lib.mkOption {
|
||||
options.meta.lib.resolveRepoTerminal = lib.mkOption {
|
||||
type = lib.types.raw;
|
||||
description = "Internal helper to resolve and validate user terminal metadata.";
|
||||
description = "Internal helper to resolve and validate the repo-standard terminal.";
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
};
|
||||
@@ -384,7 +368,7 @@ in
|
||||
mkTerminalAssertions
|
||||
mkHost
|
||||
resolvePackagePath
|
||||
resolveUserTerminal
|
||||
resolveRepoTerminal
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user