refactor: niri config

This commit is contained in:
2026-04-29 15:49:32 +02:00
parent efb0179344
commit 5bc37c7009
3 changed files with 376 additions and 307 deletions
+80 -56
View File
@@ -1,9 +1,10 @@
{ {
browserCommand, browserCommand,
shortcutCommands,
terminalCommand, terminalCommand,
uxCommands,
}: }:
{ {
# Application and utility launchers
"Mod+Return" = { "Mod+Return" = {
action.spawn = terminalCommand; action.spawn = terminalCommand;
hotkey-overlay.title = "Terminal"; hotkey-overlay.title = "Terminal";
@@ -22,25 +23,76 @@
}; };
"Mod+E" = { "Mod+E" = {
repeat = false; repeat = false;
action.spawn = uxCommands.neovimProjects; action.spawn = shortcutCommands.neovimProjects;
hotkey-overlay.title = "Neovim Projects"; hotkey-overlay.title = "Neovim Projects";
}; };
"Mod+Ctrl+Return" = { "Mod+Ctrl+Return" = {
repeat = false; repeat = false;
action.spawn = uxCommands.nixosTerminal; action.spawn = shortcutCommands.nixosTerminal;
hotkey-overlay.title = "NixOS Config Terminal"; hotkey-overlay.title = "NixOS Config Terminal";
}; };
"Mod+Ctrl+Shift+Return" = { "Mod+Ctrl+Shift+Return" = {
repeat = false; repeat = false;
action.spawn = uxCommands.nixosSwitch; action.spawn = shortcutCommands.nixosSwitch;
hotkey-overlay.title = "NixOS Switch"; hotkey-overlay.title = "NixOS Switch";
}; };
"Mod+Ctrl+E" = { "Mod+Ctrl+E" = {
repeat = false; repeat = false;
action.spawn = uxCommands.editSecrets; action.spawn = shortcutCommands.editSecrets;
hotkey-overlay.title = "Edit Secrets"; hotkey-overlay.title = "Edit Secrets";
}; };
"Mod+Ctrl+F" = {
repeat = false;
action.spawn = [
shortcutCommands.vicinaeCommand
"files"
];
hotkey-overlay.title = "Find Files";
};
"Mod+V" = {
repeat = false;
action.spawn = shortcutCommands.clipboardHistory;
hotkey-overlay.title = "Clipboard History";
};
"Mod+Ctrl+N" = {
repeat = false;
action.spawn = [
shortcutCommands.vicinaeCommand
"nix-options"
];
hotkey-overlay.title = "NixOS Options";
};
"Mod+Ctrl+H" = {
repeat = false;
action.spawn = [
shortcutCommands.vicinaeCommand
"home-manager-options"
];
hotkey-overlay.title = "Home Manager Options";
};
"Mod+Ctrl+P" = {
repeat = false;
action.spawn = [
shortcutCommands.vicinaeCommand
"nix-packages"
];
hotkey-overlay.title = "Nix Packages";
};
"Mod+Ctrl+W" = {
repeat = false;
action.spawn = [
shortcutCommands.vicinaeCommand
"niri-windows"
];
hotkey-overlay.title = "Windows";
};
"Mod+Ctrl+C" = {
repeat = false;
action.spawn = shortcutCommands.pickColor;
hotkey-overlay.title = "Pick Color";
};
# Hardware media, volume, and brightness keys
"XF86AudioPlay" = { "XF86AudioPlay" = {
action.spawn-sh = "playerctl play-pause"; action.spawn-sh = "playerctl play-pause";
allow-when-locked = true; allow-when-locked = true;
@@ -82,10 +134,12 @@
allow-when-locked = true; allow-when-locked = true;
}; };
# Screenshots
"Mod+S".action.screenshot = [ ]; "Mod+S".action.screenshot = [ ];
"Mod+Ctrl+S".action.screenshot-screen = [ ]; "Mod+Ctrl+S".action.screenshot-screen = [ ];
"Mod+Alt+S".action.screenshot-window = [ ]; "Mod+Alt+S".action.screenshot-window = [ ];
# Session and compositor controls
"Mod+Shift+Slash".action.show-hotkey-overlay = [ ]; "Mod+Shift+Slash".action.show-hotkey-overlay = [ ];
"Mod+Escape" = { "Mod+Escape" = {
action.toggle-keyboard-shortcuts-inhibit = [ ]; action.toggle-keyboard-shortcuts-inhibit = [ ];
@@ -99,6 +153,7 @@
"Ctrl+Alt+Delete".action.quit = [ ]; "Ctrl+Alt+Delete".action.quit = [ ];
"Mod+Shift+P".action.power-off-monitors = [ ]; "Mod+Shift+P".action.power-off-monitors = [ ];
# Overview and window close
"Mod+O" = { "Mod+O" = {
action.toggle-overview = [ ]; action.toggle-overview = [ ];
repeat = false; repeat = false;
@@ -108,6 +163,7 @@
repeat = false; repeat = false;
}; };
# Keyboard focus movement
"Mod+Left".action.focus-column-or-monitor-left = [ ]; "Mod+Left".action.focus-column-or-monitor-left = [ ];
"Mod+Down".action.focus-window-down = [ ]; "Mod+Down".action.focus-window-down = [ ];
"Mod+Up".action.focus-window-up = [ ]; "Mod+Up".action.focus-window-up = [ ];
@@ -117,6 +173,7 @@
"Mod+K".action.focus-window-up = [ ]; "Mod+K".action.focus-window-up = [ ];
"Mod+L".action.focus-column-or-monitor-right = [ ]; "Mod+L".action.focus-column-or-monitor-right = [ ];
# Keyboard window and column movement
"Mod+Alt+Left".action.move-column-left-or-to-monitor-left = [ ]; "Mod+Alt+Left".action.move-column-left-or-to-monitor-left = [ ];
"Mod+Alt+Down".action.move-window-down-or-to-workspace-down = [ ]; "Mod+Alt+Down".action.move-window-down-or-to-workspace-down = [ ];
"Mod+Alt+Up".action.move-window-up-or-to-workspace-up = [ ]; "Mod+Alt+Up".action.move-window-up-or-to-workspace-up = [ ];
@@ -126,12 +183,19 @@
"Mod+Alt+K".action.move-window-up-or-to-workspace-up = [ ]; "Mod+Alt+K".action.move-window-up-or-to-workspace-up = [ ];
"Mod+Alt+L".action.move-column-right-or-to-monitor-right = [ ]; "Mod+Alt+L".action.move-column-right-or-to-monitor-right = [ ];
# First and last column navigation
"Mod+Home".action.focus-column-first = [ ]; "Mod+Home".action.focus-column-first = [ ];
"Mod+End".action.focus-column-last = [ ]; "Mod+End".action.focus-column-last = [ ];
"Mod+Alt+Home".action.move-column-to-first = [ ]; "Mod+Alt+Home".action.move-column-to-first = [ ];
"Mod+Alt+End".action.move-column-to-last = [ ]; "Mod+Alt+End".action.move-column-to-last = [ ];
# Move focus, columns, and workspaces across monitors
"Mod+Tab".action.focus-monitor-next = [ ]; "Mod+Tab".action.focus-monitor-next = [ ];
"Mod+A" = {
repeat = false;
action.spawn = shortcutCommands.swapMonitorWorkspaces;
hotkey-overlay.title = "Swap Monitor Workspaces";
};
"Mod+Alt+Tab".action.move-column-to-monitor-next = [ ]; "Mod+Alt+Tab".action.move-column-to-monitor-next = [ ];
"Mod+Shift+Tab".action.move-workspace-to-monitor-next = [ ]; "Mod+Shift+Tab".action.move-workspace-to-monitor-next = [ ];
@@ -140,21 +204,25 @@
"Mod+Shift+Up".action.focus-monitor-up = [ ]; "Mod+Shift+Up".action.focus-monitor-up = [ ];
"Mod+Shift+Right".action.focus-monitor-right = [ ]; "Mod+Shift+Right".action.focus-monitor-right = [ ];
# Linear workspace navigation
"Mod+Page_Down".action.focus-workspace-down = [ ]; "Mod+Page_Down".action.focus-workspace-down = [ ];
"Mod+Page_Up".action.focus-workspace-up = [ ]; "Mod+Page_Up".action.focus-workspace-up = [ ];
"Mod+U".action.focus-workspace-down = [ ]; "Mod+U".action.focus-workspace-down = [ ];
"Mod+I".action.focus-workspace-up = [ ]; "Mod+I".action.focus-workspace-up = [ ];
# Move columns between adjacent workspaces
"Mod+Alt+Page_Down".action.move-column-to-workspace-down = [ ]; "Mod+Alt+Page_Down".action.move-column-to-workspace-down = [ ];
"Mod+Alt+Page_Up".action.move-column-to-workspace-up = [ ]; "Mod+Alt+Page_Up".action.move-column-to-workspace-up = [ ];
"Mod+Alt+U".action.move-column-to-workspace-down = [ ]; "Mod+Alt+U".action.move-column-to-workspace-down = [ ];
"Mod+Alt+I".action.move-column-to-workspace-up = [ ]; "Mod+Alt+I".action.move-column-to-workspace-up = [ ];
# Reorder workspaces
"Mod+Shift+Page_Down".action.move-workspace-down = [ ]; "Mod+Shift+Page_Down".action.move-workspace-down = [ ];
"Mod+Shift+Page_Up".action.move-workspace-up = [ ]; "Mod+Shift+Page_Up".action.move-workspace-up = [ ];
"Mod+Shift+U".action.move-workspace-down = [ ]; "Mod+Shift+U".action.move-workspace-down = [ ];
"Mod+Shift+I".action.move-workspace-up = [ ]; "Mod+Shift+I".action.move-workspace-up = [ ];
# Mouse workspace navigation
"Mod+WheelScrollDown" = { "Mod+WheelScrollDown" = {
action.focus-workspace-down = [ ]; action.focus-workspace-down = [ ];
cooldown-ms = 150; cooldown-ms = 150;
@@ -172,6 +240,7 @@
cooldown-ms = 150; cooldown-ms = 150;
}; };
# Mouse column navigation and movement
"Mod+WheelScrollRight".action.focus-column-or-monitor-right = [ ]; "Mod+WheelScrollRight".action.focus-column-or-monitor-right = [ ];
"Mod+WheelScrollLeft".action.focus-column-or-monitor-left = [ ]; "Mod+WheelScrollLeft".action.focus-column-or-monitor-left = [ ];
"Mod+Alt+WheelScrollRight".action.move-column-right-or-to-monitor-right = [ ]; "Mod+Alt+WheelScrollRight".action.move-column-right-or-to-monitor-right = [ ];
@@ -179,6 +248,7 @@
"Mod+Shift+WheelScrollDown".action.focus-column-or-monitor-right = [ ]; "Mod+Shift+WheelScrollDown".action.focus-column-or-monitor-right = [ ];
"Mod+Shift+WheelScrollUp".action.focus-column-or-monitor-left = [ ]; "Mod+Shift+WheelScrollUp".action.focus-column-or-monitor-left = [ ];
# Direct workspace focus
"Mod+1".action.focus-workspace = 1; "Mod+1".action.focus-workspace = 1;
"Mod+2".action.focus-workspace = 2; "Mod+2".action.focus-workspace = 2;
"Mod+3".action.focus-workspace = 3; "Mod+3".action.focus-workspace = 3;
@@ -189,6 +259,7 @@
"Mod+8".action.focus-workspace = 8; "Mod+8".action.focus-workspace = 8;
"Mod+9".action.focus-workspace = 9; "Mod+9".action.focus-workspace = 9;
# Move columns to numbered workspaces
"Mod+Ctrl+1".action.move-column-to-workspace = 1; "Mod+Ctrl+1".action.move-column-to-workspace = 1;
"Mod+Ctrl+2".action.move-column-to-workspace = 2; "Mod+Ctrl+2".action.move-column-to-workspace = 2;
"Mod+Ctrl+3".action.move-column-to-workspace = 3; "Mod+Ctrl+3".action.move-column-to-workspace = 3;
@@ -199,11 +270,13 @@
"Mod+Ctrl+8".action.move-column-to-workspace = 8; "Mod+Ctrl+8".action.move-column-to-workspace = 8;
"Mod+Ctrl+9".action.move-column-to-workspace = 9; "Mod+Ctrl+9".action.move-column-to-workspace = 9;
# Add and remove windows from columns
"Mod+BracketLeft".action.consume-or-expel-window-left = [ ]; "Mod+BracketLeft".action.consume-or-expel-window-left = [ ];
"Mod+BracketRight".action.consume-or-expel-window-right = [ ]; "Mod+BracketRight".action.consume-or-expel-window-right = [ ];
"Mod+Comma".action.consume-window-into-column = [ ]; "Mod+Comma".action.consume-window-into-column = [ ];
"Mod+Period".action.expel-window-from-column = [ ]; "Mod+Period".action.expel-window-from-column = [ ];
# Column and window presentation modes
"Mod+R".action.switch-preset-column-width = [ ]; "Mod+R".action.switch-preset-column-width = [ ];
"Mod+Shift+R".action.switch-preset-column-width-back = [ ]; "Mod+Shift+R".action.switch-preset-column-width-back = [ ];
"Mod+Ctrl+R".action.reset-window-height = [ ]; "Mod+Ctrl+R".action.reset-window-height = [ ];
@@ -213,6 +286,7 @@
"Mod+M".action.maximize-window-to-edges = [ ]; "Mod+M".action.maximize-window-to-edges = [ ];
"Mod+C".action.center-column = [ ]; "Mod+C".action.center-column = [ ];
# Manual column width and window height adjustments
"Mod+Shift+H".action.set-column-width = "-10%"; "Mod+Shift+H".action.set-column-width = "-10%";
"Mod+Shift+L".action.set-column-width = "+10%"; "Mod+Shift+L".action.set-column-width = "+10%";
"Mod+Shift+J".action.set-window-height = "+10%"; "Mod+Shift+J".action.set-window-height = "+10%";
@@ -222,57 +296,7 @@
"Mod+Shift+Minus".action.set-window-height = "-10%"; "Mod+Shift+Minus".action.set-window-height = "-10%";
"Mod+Shift+Equal".action.set-window-height = "+10%"; "Mod+Shift+Equal".action.set-window-height = "+10%";
"Mod+Ctrl+F" = { # Floating and tabbed layout toggles
repeat = false;
action.spawn = [
uxCommands.vicinaeCommand
"files"
];
hotkey-overlay.title = "Find Files";
};
"Mod+V" = {
repeat = false;
action.spawn = uxCommands.clipboardHistory;
hotkey-overlay.title = "Clipboard History";
};
"Mod+Ctrl+N" = {
repeat = false;
action.spawn = [
uxCommands.vicinaeCommand
"nix-options"
];
hotkey-overlay.title = "NixOS Options";
};
"Mod+Ctrl+H" = {
repeat = false;
action.spawn = [
uxCommands.vicinaeCommand
"home-manager-options"
];
hotkey-overlay.title = "Home Manager Options";
};
"Mod+Ctrl+P" = {
repeat = false;
action.spawn = [
uxCommands.vicinaeCommand
"nix-packages"
];
hotkey-overlay.title = "Nix Packages";
};
"Mod+Ctrl+W" = {
repeat = false;
action.spawn = [
uxCommands.vicinaeCommand
"niri-windows"
];
hotkey-overlay.title = "Windows";
};
"Mod+Ctrl+C" = {
repeat = false;
action.spawn = uxCommands.pickColor;
hotkey-overlay.title = "Pick Color";
};
"Mod+Alt+V".action.toggle-window-floating = [ ]; "Mod+Alt+V".action.toggle-window-floating = [ ];
"Mod+Shift+V".action.switch-focus-between-floating-and-tiling = [ ]; "Mod+Shift+V".action.switch-focus-between-floating-and-tiling = [ ];
"Mod+W".action.toggle-column-tabbed-display = [ ]; "Mod+W".action.toggle-column-tabbed-display = [ ];
+225
View File
@@ -0,0 +1,225 @@
{
config,
lib,
pkgs,
repo,
}:
let
nixosConfigDir = repo.account.nixosConfigurationPath;
mkTerminalScript =
{
name,
title,
appId ? "niri-shortcut-terminal",
workdir ? nixosConfigDir,
command ? null,
runtimeInputs ? [ ],
}:
let
args =
(
if config.meta.desktop.terminal.desktopEntryName == "kitty" then
[
"--class"
appId
"--title"
title
"--directory"
workdir
]
else if config.meta.desktop.terminal.desktopEntryName == "foot" then
[
"--app-id"
appId
"--title"
title
"--working-directory"
workdir
]
else
[ ]
)
++ lib.optionals (command != null) [
"--"
"${pkgs.bash}/bin/bash"
"-lc"
command
];
in
pkgs.writeShellApplication {
inherit name runtimeInputs;
checkPhase = "";
text = ''
# shellcheck disable=SC2016
cd ${lib.escapeShellArg workdir}
exec ${lib.escapeShellArg config.meta.desktop.terminal.command} ${
lib.concatMapStringsSep " " lib.escapeShellArg args
}
'';
};
in
rec {
scripts = {
nixosTerminal = mkTerminalScript {
name = "niri-shortcut-nixos-terminal";
title = "NixOS Config";
};
nixosSwitch = mkTerminalScript {
name = "niri-shortcut-nixos-switch";
title = "NixOS Switch";
appId = "niri-shortcut-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-shortcut-edit-secrets";
title = "Edit Secrets";
appId = "niri-shortcut-float";
runtimeInputs = [ pkgs.sops ];
command = ''
sops edit ${lib.escapeShellArg "${nixosConfigDir}/modules/secrets/secrets.yaml"}
'';
};
neovimProjects = mkTerminalScript {
name = "niri-shortcut-neovim-projects";
title = "Neovim Projects";
command = ''
nvim -c 'Telescope projects'
'';
};
vicinaeCommand = pkgs.writeShellApplication {
name = "niri-shortcut-vicinae-command";
runtimeInputs = [ config.programs.vicinae.package ];
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-shortcut-clipboard-history";
runtimeInputs = [
pkgs.cliphist
config.programs.vicinae.package
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-shortcut-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"
'';
};
swapMonitorWorkspaces = pkgs.writeShellApplication {
name = "niri-shortcut-swap-monitor-workspaces";
runtimeInputs = [
pkgs.jq
pkgs.niri
];
text = ''
focused_output="$(niri msg --json focused-output | jq -r '.name // empty')"
if [ -z "$focused_output" ]; then
exit 0
fi
niri msg action focus-monitor-next
target_output="$(niri msg --json focused-output | jq -r '.name // empty')"
if [ -z "$target_output" ] || [ "$target_output" = "$focused_output" ]; then
exit 0
fi
target_workspace_idx="$(
niri msg --json workspaces \
| jq -r --arg output "$target_output" '
first(.[] | select(.output == $output and .is_active) | .idx) // empty
'
)"
if [ -z "$target_workspace_idx" ]; then
niri msg action focus-monitor "$focused_output"
exit 0
fi
niri msg action focus-monitor "$focused_output"
niri msg action move-workspace-to-monitor "$target_output"
niri msg action focus-workspace "$target_workspace_idx"
niri msg action move-workspace-to-monitor "$focused_output"
'';
};
};
commands = lib.mapAttrs (_: lib.getExe) scripts;
}
+71 -251
View File
@@ -11,14 +11,22 @@ in
{ pkgs, ... }: { pkgs, ... }:
{ {
imports = [ inputs.niri.nixosModules.niri ]; imports = [ inputs.niri.nixosModules.niri ];
nixpkgs.overlays = [ inputs.niri.overlays.niri ]; nixpkgs.overlays = [ inputs.niri.overlays.niri ];
programs.niri.enable = true; programs = {
programs.niri.package = pkgs.niri-unstable; dconf.enable = true;
programs.dconf.enable = true; niri = {
enable = true;
package = pkgs.niri-unstable;
};
};
services = {
gvfs.enable = true;
udisks2.enable = true;
};
services.gvfs.enable = true;
services.udisks2.enable = true;
xdg.portal.enable = true; xdg.portal.enable = true;
}; };
@@ -31,241 +39,59 @@ in
... ...
}: }:
let let
repoTheme = repo.theme.kanagawa; borderPalette = repo.theme.kanagawa.palette.niri.border;
browserCommand = config.meta.desktop.browser.command; shortcuts = import ./_shortcuts.nix {
fileManagerPackage = config.meta.desktop.fileManager.package; inherit
terminalCommand = config.meta.desktop.terminal.command; config
terminalDesktopEntryName = config.meta.desktop.terminal.desktopEntryName; lib
nixosConfigDir = repo.account.nixosConfigurationPath; pkgs
secretsFile = "${nixosConfigDir}/modules/secrets/secrets.yaml"; repo
outputs = lib.mapAttrs ( ;
_: display: };
{
position = {
x = display.x;
y = display.y;
};
}
// lib.optionalAttrs (display.primary or false) {
"focus-at-startup" = true;
}
// lib.optionalAttrs (display.scale != null) {
inherit (display) scale;
}
// lib.optionalAttrs (display.width != null && display.height != null && display.refresh != null) {
mode = {
inherit (display)
width
height
refresh
;
};
}
) 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 in
{ {
home.sessionVariables.NIXOS_OZONE_WL = "1"; home = {
sessionVariables.NIXOS_OZONE_WL = "1";
dconf.settings = { packages =
"org/gnome/desktop/interface" = { with pkgs;
color-scheme = "prefer-dark"; [
}; playerctl
brightnessctl
xwayland-satellite
]
++ [
config.meta.desktop.fileManager.package
]
++ lib.attrValues shortcuts.scripts;
}; };
home.packages = dconf.settings."org/gnome/desktop/interface".color-scheme = "prefer-dark";
with pkgs;
[
playerctl
brightnessctl
xwayland-satellite
]
++ [ fileManagerPackage ]
++ lib.attrValues uxScripts;
programs.niri.settings = { programs.niri.settings = {
inherit outputs; outputs = lib.mapAttrs (
_: display:
{
position = {
inherit (display) x y;
};
}
// lib.optionalAttrs (display.primary or false) {
"focus-at-startup" = true;
}
// lib.optionalAttrs (display.scale != null) {
inherit (display) scale;
}
// lib.optionalAttrs (display.width != null && display.height != null && display.refresh != null) {
mode = {
inherit (display)
width
height
refresh
;
};
}
) osConfig.meta.machine.displays;
environment.DISPLAY = ":0"; environment.DISPLAY = ":0";
spawn-at-startup = [ spawn-at-startup = [
{ command = [ "xwayland-satellite" ]; } { command = [ "xwayland-satellite" ]; }
@@ -277,9 +103,9 @@ in
animations.slowdown = 0.6; animations.slowdown = 0.6;
cursor = with config.home.pointerCursor; { cursor = {
size = size; inherit (config.home.pointerCursor) size;
theme = name; theme = config.home.pointerCursor.name;
hide-after-inactive-ms = 3000; hide-after-inactive-ms = 3000;
hide-when-typing = true; hide-when-typing = true;
}; };
@@ -288,15 +114,14 @@ in
always-center-single-column = true; always-center-single-column = true;
gaps = 14; gaps = 14;
focus-ring.enable = false; focus-ring.enable = false;
default-column-width.proportion = 1. / 2.; default-column-width.proportion = 1. / 2.;
border = { border = {
enable = true; enable = true;
width = 3; width = 3;
active.color = repoTheme.palette.niri.border.active; active.color = borderPalette.active;
inactive.color = repoTheme.palette.niri.border.inactive; inactive.color = borderPalette.inactive;
urgent.color = repoTheme.palette.niri.border.urgent; urgent.color = borderPalette.urgent;
}; };
}; };
@@ -316,7 +141,7 @@ in
} }
{ {
matches = [ matches = [
{ app-id = "^niri-ux-float$"; } { app-id = "^niri-shortcut-float$"; }
]; ];
open-floating = true; open-floating = true;
open-focused = true; open-focused = true;
@@ -334,18 +159,13 @@ in
repeat-rate = 50; repeat-rate = 50;
xkb.options = "caps:escape"; xkb.options = "caps:escape";
}; };
touchpad.dwt = true;
touchpad = {
dwt = true;
};
}; };
binds = import ./_bindings.nix { binds = import ./_bindings.nix {
inherit browserCommand = config.meta.desktop.browser.command;
browserCommand terminalCommand = config.meta.desktop.terminal.command;
terminalCommand shortcutCommands = shortcuts.commands;
uxCommands
;
}; };
}; };
}; };