refactor: centralize workstation HM base and derive terminal from user metadata
This commit is contained in:
@@ -1,10 +1,47 @@
|
||||
{
|
||||
flake.modules.homeManager.terminal =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
rawTerminalAttrPath = lib.splitString "." config.meta.user.terminalPackageAttr;
|
||||
terminalAttrPath =
|
||||
if rawTerminalAttrPath != [ ] && builtins.head rawTerminalAttrPath == "pkgs" then
|
||||
builtins.tail rawTerminalAttrPath
|
||||
else
|
||||
rawTerminalAttrPath;
|
||||
terminalPackage = lib.attrByPath terminalAttrPath null pkgs;
|
||||
hasTerminalPackage = terminalPackage != null;
|
||||
hasMainProgram = hasTerminalPackage && terminalPackage ? meta.mainProgram;
|
||||
terminalDesktopId =
|
||||
if hasMainProgram then "${terminalPackage.meta.mainProgram}.desktop" else null;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = hasTerminalPackage;
|
||||
message = "Unknown terminal package `${config.meta.user.terminalPackageAttr}` for user `${config.meta.user.name}`.";
|
||||
}
|
||||
{
|
||||
assertion = hasMainProgram;
|
||||
message = "Terminal package `${config.meta.user.terminalPackageAttr}` must define `meta.mainProgram`.";
|
||||
}
|
||||
{
|
||||
assertion = hasMainProgram && builtins.pathExists "${terminalPackage}/share/applications/${terminalDesktopId}";
|
||||
message = "Terminal package `${config.meta.user.terminalPackageAttr}` must provide `${terminalDesktopId}`.";
|
||||
}
|
||||
{
|
||||
assertion = hasMainProgram && terminalPackage.meta.mainProgram == "kitty";
|
||||
message = "The terminal feature currently only supports kitty-specific Home Manager configuration.";
|
||||
}
|
||||
];
|
||||
|
||||
xdg.terminal-exec = {
|
||||
enable = true;
|
||||
settings.default = [ "kitty.desktop" ];
|
||||
settings.default = lib.optional (terminalDesktopId != null) terminalDesktopId;
|
||||
};
|
||||
|
||||
programs.kitty = {
|
||||
|
||||
Reference in New Issue
Block a user