feat: improve config UX

This commit is contained in:
2026-04-29 13:50:20 +02:00
parent a18d405ea7
commit efb0179344
2 changed files with 307 additions and 44 deletions
+196 -1
View File
@@ -35,6 +35,9 @@ in
browserCommand = config.meta.desktop.browser.command;
fileManagerPackage = config.meta.desktop.fileManager.package;
terminalCommand = config.meta.desktop.terminal.command;
terminalDesktopEntryName = config.meta.desktop.terminal.desktopEntryName;
nixosConfigDir = repo.account.nixosConfigurationPath;
secretsFile = "${nixosConfigDir}/modules/secrets/secrets.yaml";
outputs = lib.mapAttrs (
_: display:
{
@@ -59,6 +62,188 @@ in
};
}
) osConfig.meta.machine.displays;
terminalCommandArg = lib.escapeShellArg terminalCommand;
mkTerminalScript =
{
name,
title,
appId ? "niri-ux-terminal",
workdir ? nixosConfigDir,
command ? null,
runtimeInputs ? [ ],
}:
let
terminalArgs =
if terminalDesktopEntryName == "kitty" then
[
"--class"
appId
"--title"
title
"--directory"
workdir
]
else if terminalDesktopEntryName == "foot" then
[
"--app-id"
appId
"--title"
title
"--working-directory"
workdir
]
else
[ ];
commandArgs =
if command == null then
[ ]
else
[
"--"
"${pkgs.bash}/bin/bash"
"-lc"
command
];
execArgs = lib.concatMapStringsSep " " lib.escapeShellArg (terminalArgs ++ commandArgs);
in
pkgs.writeShellApplication {
inherit name runtimeInputs;
checkPhase = "";
text = ''
# shellcheck disable=SC2016
cd ${lib.escapeShellArg workdir}
exec ${terminalCommandArg} ${execArgs}
'';
};
uxScripts =
let
vicinaePackage = config.programs.vicinae.package or pkgs.vicinae;
in
{
nixosTerminal = mkTerminalScript {
name = "niri-ux-nixos-terminal";
title = "NixOS Config";
};
nixosSwitch = mkTerminalScript {
name = "niri-ux-nixos-switch";
title = "NixOS Switch";
appId = "niri-ux-float";
runtimeInputs = [
pkgs.coreutils
pkgs.nh
];
command = ''
set -o pipefail
log_dir="''${XDG_STATE_HOME:-$HOME/.local/state}/nixos-switch"
mkdir -p "$log_dir"
log="$log_dir/$(date +%Y%m%d-%H%M%S).log"
status_file="$(mktemp)"
printf 'Running nh os switch in %s\n\n' ${lib.escapeShellArg nixosConfigDir}
(
cd ${lib.escapeShellArg nixosConfigDir}
nh os switch
printf '%s' "$?" > "$status_file"
) 2>&1 | tee "$log"
status="$(cat "$status_file")"
rm -f "$status_file"
printf '\nLog: %s\n' "$log"
if [ "$status" -eq 0 ]; then
printf 'NixOS switch completed successfully.\n'
else
printf 'NixOS switch failed with exit code %s.\n' "$status"
fi
printf 'Press Enter to close...'
read -r _
exit "$status"
'';
};
editSecrets = mkTerminalScript {
name = "niri-ux-edit-secrets";
title = "Edit Secrets";
appId = "niri-ux-float";
runtimeInputs = [ pkgs.sops ];
command = ''
sops edit ${lib.escapeShellArg secretsFile}
'';
};
neovimProjects = mkTerminalScript {
name = "niri-ux-neovim-projects";
title = "Neovim Projects";
command = ''
nvim -c 'Telescope projects'
'';
};
vicinaeCommand = pkgs.writeShellApplication {
name = "niri-ux-vicinae-command";
runtimeInputs = [ vicinaePackage ];
text = ''
case "''${1:-}" in
files)
link="vicinae://extensions/sameoldlab/fuzzy-files/find"
;;
nix-options)
link="vicinae://extensions/knoopx/nix/options"
;;
home-manager-options)
link="vicinae://extensions/knoopx/nix/home-manager-options"
;;
nix-packages)
link="vicinae://extensions/knoopx/nix/packages"
;;
niri-windows)
link="vicinae://extensions/knoopx/niri/windows"
;;
*)
printf 'unknown Vicinae command target: %s\n' "''${1:-}" >&2
exit 64
;;
esac
exec vicinae deeplink "$link"
'';
};
clipboardHistory = pkgs.writeShellApplication {
name = "niri-ux-clipboard-history";
runtimeInputs = [
pkgs.cliphist
vicinaePackage
pkgs.wl-clipboard
];
text = ''
selection="$(cliphist list | vicinae dmenu --navigation-title Clipboard --placeholder 'Search clipboard' --no-metadata)"
if [ -z "$selection" ]; then
exit 0
fi
printf '%s' "$selection" | cliphist decode | wl-copy
'';
};
pickColor = pkgs.writeShellApplication {
name = "niri-ux-pick-color";
runtimeInputs = [
pkgs.libnotify
pkgs.niri
pkgs.wl-clipboard
];
text = ''
color="$(niri msg pick-color)"
printf '%s' "$color" | wl-copy
notify-send 'Color picked' "$color"
'';
};
};
uxCommands = lib.mapAttrs (_: lib.getExe) uxScripts;
in
{
home.sessionVariables.NIXOS_OZONE_WL = "1";
@@ -76,7 +261,8 @@ in
brightnessctl
xwayland-satellite
]
++ [ fileManagerPackage ];
++ [ fileManagerPackage ]
++ lib.attrValues uxScripts;
programs.niri.settings = {
inherit outputs;
@@ -128,9 +314,17 @@ in
};
clip-to-geometry = true;
}
{
matches = [
{ app-id = "^niri-ux-float$"; }
];
open-floating = true;
open-focused = true;
}
];
debug.honor-xdg-activation-with-invalid-serial = true;
gestures.hot-corners.enable = false;
input = {
focus-follows-mouse.enable = true;
@@ -150,6 +344,7 @@ in
inherit
browserCommand
terminalCommand
uxCommands
;
};
};