From d6878abc6172c41ae0c2507cd97cde98b112b49f Mon Sep 17 00:00:00 2001 From: Jelle Spreeuwenberg Date: Wed, 6 May 2026 19:32:37 +0200 Subject: [PATCH] refactor default apps and add walker --- modules/capabilities/desktop-defaults.nix | 128 ++++++++++++---------- modules/capabilities/neovim/default.nix | 6 + modules/capabilities/niri/_bindings.nix | 14 +-- modules/capabilities/niri/_shortcuts.nix | 76 ++----------- modules/capabilities/niri/default.nix | 16 +-- modules/capabilities/terminal.nix | 58 ++++------ modules/capabilities/vicinae.nix | 25 +---- modules/capabilities/walker.nix | 54 ++++----- modules/lib/schema.nix | 74 ++----------- modules/profiles/workstation-base.nix | 9 +- 10 files changed, 161 insertions(+), 299 deletions(-) diff --git a/modules/capabilities/desktop-defaults.nix b/modules/capabilities/desktop-defaults.nix index 1ee69e4..73b1e7b 100644 --- a/modules/capabilities/desktop-defaults.nix +++ b/modules/capabilities/desktop-defaults.nix @@ -1,63 +1,88 @@ -{ ... }: +{ config, ... }: let - mkPrimaryDesktopApplication = - { - name, - package, - desktopEntryName, - }: - { pkgs, ... }: - { - meta.desktop.${name} = { - inherit desktopEntryName; - package = package pkgs; - }; - }; + homeModules = config.flake.modules.homeManager; + vivaldiPackage = pkgs: pkgs.vivaldi; + nautilusPackage = pkgs: pkgs.nautilus; in { - flake.modules.homeManager.primary-browser-vivaldi = mkPrimaryDesktopApplication { - name = "browser"; - package = pkgs: pkgs.vivaldi; - desktopEntryName = "vivaldi-stable"; + flake.modules.homeManager.browser-vivaldi = + { pkgs, ... }: + { + home.packages = [ (vivaldiPackage pkgs) ]; + }; + + flake.modules.homeManager.primary-browser-vivaldi = + { lib, pkgs, ... }: + { + imports = [ homeModules.browser-vivaldi ]; + + meta.desktop.browserCommand = lib.getExe (vivaldiPackage pkgs); + home.sessionVariables.BROWSER = lib.getExe (vivaldiPackage pkgs); + xdg.mimeApps.defaultApplicationPackages = [ (vivaldiPackage pkgs) ]; + }; + + flake.modules.homeManager.file-manager-nautilus = + { pkgs, ... }: + { + home.packages = [ (nautilusPackage pkgs) ]; + }; + + flake.modules.homeManager.primary-file-manager-nautilus = + { lib, pkgs, ... }: + { + imports = [ homeModules.file-manager-nautilus ]; + + meta.desktop.fileManagerCommand = lib.getExe (nautilusPackage pkgs); + xdg.mimeApps.defaultApplicationPackages = [ (nautilusPackage pkgs) ]; + }; + + flake.modules.homeManager.image-viewer-imv = { + programs.imv.enable = true; }; - flake.modules.homeManager.primary-file-manager-nautilus = mkPrimaryDesktopApplication { - name = "fileManager"; - package = pkgs: pkgs.nautilus; - desktopEntryName = "org.gnome.Nautilus"; + flake.modules.homeManager.default-image-viewer-imv = + { pkgs, ... }: + { + imports = [ homeModules.image-viewer-imv ]; + + xdg.mimeApps.defaultApplicationPackages = [ pkgs.imv ]; + }; + + flake.modules.homeManager.document-viewer-sioyek = { + programs.sioyek.enable = true; }; - flake.modules.homeManager.desktop-defaults = - { config, pkgs, ... }: + flake.modules.homeManager.default-document-viewer-sioyek = + { pkgs, ... }: + { + imports = [ homeModules.document-viewer-sioyek ]; + + xdg.mimeApps.defaultApplicationPackages = [ pkgs.sioyek ]; + }; + + flake.modules.homeManager.workstation-apps = + { pkgs, ... }: + { + home.packages = with pkgs; [ + postman + spotify + calcure + planify + unzip + gimp + dbeaver-bin + ]; + }; + + flake.modules.homeManager.xdg = + { config, ... }: let - browser = config.meta.desktop.browser; - fileManager = config.meta.desktop.fileManager; homeDir = config.home.homeDirectory; localDir = "${homeDir}/.local"; mediaDir = "${homeDir}/media"; in { home.preferXdgDirectories = true; - home.sessionVariables.BROWSER = browser.command; - - home.packages = - with pkgs; - [ - postman - spotify - calcure - planify - unzip - gimp - dbeaver-bin - ] - ++ [ - browser.package - fileManager.package - ]; - - programs.imv.enable = true; - programs.sioyek.enable = true; xdg = { enable = true; @@ -85,17 +110,6 @@ in mimeApps = { enable = true; - defaultApplicationPackages = - with pkgs; - [ - sioyek - imv - neovim - ] - ++ [ - fileManager.package - browser.package - ]; }; }; }; diff --git a/modules/capabilities/neovim/default.nix b/modules/capabilities/neovim/default.nix index baba615..66a9add 100644 --- a/modules/capabilities/neovim/default.nix +++ b/modules/capabilities/neovim/default.nix @@ -4,6 +4,12 @@ let repoTheme = config.repo.theme.kanagawa; in { + flake.modules.homeManager.default-editor-neovim = + { pkgs, ... }: + { + xdg.mimeApps.defaultApplicationPackages = [ pkgs.neovim ]; + }; + flake.modules.homeManager.neovim = { pkgs, diff --git a/modules/capabilities/niri/_bindings.nix b/modules/capabilities/niri/_bindings.nix index 350f98d..9a968bc 100644 --- a/modules/capabilities/niri/_bindings.nix +++ b/modules/capabilities/niri/_bindings.nix @@ -1,6 +1,6 @@ { browserCommand, - launcherCommands, + launcherCommand, shortcutCommands, terminalCommand, }: @@ -16,7 +16,7 @@ }; "Mod+Space" = { repeat = false; - action.spawn = launcherCommands.open; + action.spawn = launcherCommand; hotkey-overlay.title = "App Launcher"; }; "Mod+E" = { @@ -39,16 +39,6 @@ action.spawn = shortcutCommands.editSecrets; hotkey-overlay.title = "Edit Secrets"; }; - "Mod+Ctrl+F" = { - repeat = false; - action.spawn = launcherCommands.files; - hotkey-overlay.title = "Find Files"; - }; - "Mod+V" = { - repeat = false; - action.spawn = shortcutCommands.clipboardHistory; - hotkey-overlay.title = "Clipboard History"; - }; "Mod+Ctrl+C" = { repeat = false; action.spawn = shortcutCommands.pickColor; diff --git a/modules/capabilities/niri/_shortcuts.nix b/modules/capabilities/niri/_shortcuts.nix index 43196bc..a1319ea 100644 --- a/modules/capabilities/niri/_shortcuts.nix +++ b/modules/capabilities/niri/_shortcuts.nix @@ -6,72 +6,40 @@ }: let nixosConfigDir = repo.account.nixosConfigurationPath; - launcherDmenuCommand = - lib.concatMapStringsSep " " lib.escapeShellArg - config.meta.desktop.launcher.commands.dmenu; 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 - ]; + args = lib.optionals (command != null) [ + "--" + "${pkgs.bash}/bin/bash" + "-lc" + command + ]; + argString = lib.concatMapStringsSep " " lib.escapeShellArg args; 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 - } - ''; + text = lib.concatStringsSep "\n" [ + "# shellcheck disable=SC2016" + "cd ${lib.escapeShellArg workdir}" + "exec ${lib.escapeShellArg config.meta.desktop.terminalCommand} ${argString}" + ]; }; 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 @@ -109,8 +77,6 @@ rec { 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"} @@ -119,29 +85,11 @@ rec { neovimProjects = mkTerminalScript { name = "niri-shortcut-neovim-projects"; - title = "Neovim Projects"; command = '' nvim -c 'Telescope projects' ''; }; - clipboardHistory = pkgs.writeShellApplication { - name = "niri-shortcut-clipboard-history"; - runtimeInputs = [ - pkgs.cliphist - config.meta.desktop.launcher.package - pkgs.wl-clipboard - ]; - text = '' - selection="$(cliphist list | ${launcherDmenuCommand})" - if [ -z "$selection" ]; then - exit 0 - fi - - printf '%s' "$selection" | cliphist decode | wl-copy - ''; - }; - pickColor = pkgs.writeShellApplication { name = "niri-shortcut-pick-color"; runtimeInputs = [ diff --git a/modules/capabilities/niri/default.nix b/modules/capabilities/niri/default.nix index 30d5966..528c05a 100644 --- a/modules/capabilities/niri/default.nix +++ b/modules/capabilities/niri/default.nix @@ -59,9 +59,6 @@ in brightnessctl xwayland-satellite ] - ++ [ - config.meta.desktop.fileManager.package - ] ++ lib.attrValues shortcuts.scripts; }; @@ -139,13 +136,6 @@ in }; clip-to-geometry = true; } - { - matches = [ - { app-id = "^niri-shortcut-float$"; } - ]; - open-floating = true; - open-focused = true; - } ]; debug.honor-xdg-activation-with-invalid-serial = true; @@ -163,9 +153,9 @@ in }; binds = import ./_bindings.nix { - browserCommand = config.meta.desktop.browser.command; - launcherCommands = config.meta.desktop.launcher.commands; - terminalCommand = config.meta.desktop.terminal.command; + browserCommand = config.meta.desktop.browserCommand; + launcherCommand = config.meta.desktop.launcherCommand; + terminalCommand = config.meta.desktop.terminalCommand; shortcutCommands = shortcuts.commands; }; }; diff --git a/modules/capabilities/terminal.nix b/modules/capabilities/terminal.nix index 67a1477..8c32990 100644 --- a/modules/capabilities/terminal.nix +++ b/modules/capabilities/terminal.nix @@ -19,30 +19,6 @@ let ''; }; - mkTerminal = - { - desktopEntryName, - packageFor, - terminalModule, - }: - { config, pkgs, ... }: - let - package = packageFor pkgs; - in - { - imports = [ terminalModule ]; - - config = { - meta.desktop.terminal = { - inherit desktopEntryName package; - }; - - xdg.terminal-exec = { - enable = true; - settings.default = [ config.meta.desktop.terminal.desktopId ]; - }; - }; - }; in { flake.modules.homeManager.terminal-foot = @@ -194,15 +170,29 @@ in }; }; - flake.modules.homeManager.primary-terminal-foot = mkTerminal { - desktopEntryName = "foot"; - packageFor = pkgs: pkgs.foot; - terminalModule = config.flake.modules.homeManager.terminal-foot; - }; + flake.modules.homeManager.primary-terminal-foot = + { lib, pkgs, ... }: + { + imports = [ config.flake.modules.homeManager.terminal-foot ]; - flake.modules.homeManager.primary-terminal-kitty = mkTerminal { - desktopEntryName = "kitty"; - packageFor = pkgs: kittySingleInstance pkgs; - terminalModule = config.flake.modules.homeManager.terminal-kitty; - }; + meta.desktop.terminalCommand = lib.getExe pkgs.foot; + + xdg.terminal-exec = { + enable = true; + settings.default = [ "foot.desktop" ]; + }; + }; + + flake.modules.homeManager.primary-terminal-kitty = + { lib, pkgs, ... }: + { + imports = [ config.flake.modules.homeManager.terminal-kitty ]; + + meta.desktop.terminalCommand = lib.getExe (kittySingleInstance pkgs); + + xdg.terminal-exec = { + enable = true; + settings.default = [ "kitty.desktop" ]; + }; + }; } diff --git a/modules/capabilities/vicinae.nix b/modules/capabilities/vicinae.nix index 5ba23e3..0b7f24c 100644 --- a/modules/capabilities/vicinae.nix +++ b/modules/capabilities/vicinae.nix @@ -14,7 +14,6 @@ in let repoTheme = repo.theme.kanagawa; palette = repoTheme.palette; - launcherCommand = lib.getExe config.programs.vicinae.package; in { programs.vicinae = { @@ -74,28 +73,6 @@ in ]; }; - meta.desktop.launcher = { - package = config.programs.vicinae.package; - commands = { - open = [ - launcherCommand - "toggle" - ]; - files = [ - launcherCommand - "deeplink" - "vicinae://extensions/sameoldlab/fuzzy-files/find" - ]; - dmenu = [ - launcherCommand - "dmenu" - "--navigation-title" - "Clipboard" - "--placeholder" - "Search clipboard" - "--no-metadata" - ]; - }; - }; + meta.desktop.launcherCommand = lib.getExe config.programs.vicinae.package; }; } diff --git a/modules/capabilities/walker.nix b/modules/capabilities/walker.nix index c748228..2505168 100644 --- a/modules/capabilities/walker.nix +++ b/modules/capabilities/walker.nix @@ -1,40 +1,40 @@ -{ inputs, ... }: +{ config, inputs, ... }: +let + homeModules = config.flake.modules.homeManager; +in { + flake.modules.nixos.walker-cache = { + nix.settings = { + extra-substituters = [ + "https://walker.cachix.org" + "https://walker-git.cachix.org" + ]; + extra-trusted-public-keys = [ + "walker.cachix.org-1:fG8q+uAaMqhsMxWjwvk0IMb4mFPFLqHjuvfwQxE4oJM=" + "walker-git.cachix.org-1:vmC0ocfPWh0S/vRAQGtChuiZBTAe4wiKDeyyXM0/7pM=" + ]; + }; + }; + flake.modules.homeManager.walker = { config, - lib, ... }: - let - launcherCommand = lib.getExe config.programs.walker.package; - in { imports = [ inputs.walker.homeManagerModules.default ]; programs.walker = { - enable = true; - runAsService = true; - }; - - meta.desktop.launcher = { - package = config.programs.walker.package; - commands = { - open = [ launcherCommand ]; - files = [ - launcherCommand - "--query" - "/" - "--placeholder" - "Find files" - ]; - dmenu = [ - launcherCommand - "--dmenu" - "--placeholder" - "Search clipboard" - ]; - }; + enable = false; + runAsService = false; }; }; + + flake.modules.homeManager.primary-launcher-walker = + { config, lib, ... }: + { + imports = [ homeModules.walker ]; + + meta.desktop.launcherCommand = lib.getExe config.programs.walker.package; + }; } diff --git a/modules/lib/schema.nix b/modules/lib/schema.nix index 6c0bc32..b241acd 100644 --- a/modules/lib/schema.nix +++ b/modules/lib/schema.nix @@ -81,64 +81,6 @@ let } ); - desktopApplicationType = lib.types.submodule ( - { config, ... }: - { - options = { - package = lib.mkOption { - type = lib.types.package; - }; - - command = lib.mkOption { - type = lib.types.str; - default = lib.getExe config.package; - defaultText = lib.literalExpression "lib.getExe config.package"; - }; - - desktopEntryName = lib.mkOption { - type = lib.types.str; - }; - - desktopId = lib.mkOption { - type = lib.types.str; - default = "${config.desktopEntryName}.desktop"; - defaultText = lib.literalExpression ''"${config.desktopEntryName}.desktop"''; - }; - }; - } - ); - - launcherType = lib.types.submodule ( - { config, ... }: - { - options = { - package = lib.mkOption { - type = lib.types.package; - }; - - command = lib.mkOption { - type = lib.types.str; - default = lib.getExe config.package; - defaultText = lib.literalExpression "lib.getExe config.package"; - }; - - commands = { - open = lib.mkOption { - type = lib.types.listOf lib.types.str; - }; - - files = lib.mkOption { - type = lib.types.listOf lib.types.str; - }; - - dmenu = lib.mkOption { - type = lib.types.listOf lib.types.str; - }; - }; - }; - } - ); - displayType = lib.types.submodule ( { ... }: { @@ -255,20 +197,20 @@ in config.flake.modules.homeManager.meta = { ... }: { - options.meta.desktop.browser = lib.mkOption { - type = desktopApplicationType; + options.meta.desktop.browserCommand = lib.mkOption { + type = lib.types.str; }; - options.meta.desktop.fileManager = lib.mkOption { - type = desktopApplicationType; + options.meta.desktop.fileManagerCommand = lib.mkOption { + type = lib.types.str; }; - options.meta.desktop.terminal = lib.mkOption { - type = desktopApplicationType; + options.meta.desktop.terminalCommand = lib.mkOption { + type = lib.types.str; }; - options.meta.desktop.launcher = lib.mkOption { - type = launcherType; + options.meta.desktop.launcherCommand = lib.mkOption { + type = lib.types.str; }; options.meta.pinentry.package = lib.mkOption { diff --git a/modules/profiles/workstation-base.nix b/modules/profiles/workstation-base.nix index 32abe5f..5e7b0fd 100644 --- a/modules/profiles/workstation-base.nix +++ b/modules/profiles/workstation-base.nix @@ -24,6 +24,7 @@ in nixosModules.theme nixosModules.ai nixosModules.hidraw-access + nixosModules.walker-cache ]; services.dbus.implementation = "broker"; @@ -42,9 +43,14 @@ in homeModules.passwords homeModules.clipboard homeModules.dev-tools + homeModules.xdg + homeModules.workstation-apps homeModules.primary-browser-vivaldi homeModules.primary-file-manager-nautilus - homeModules.desktop-defaults + homeModules.primary-launcher-walker + homeModules.default-image-viewer-imv + homeModules.default-document-viewer-sioyek + homeModules.default-editor-neovim homeModules.email homeModules.mpv homeModules.niri @@ -58,7 +64,6 @@ in homeModules.primary-terminal-kitty homeModules.terminal-foot homeModules.theme - homeModules.walker homeModules.noctalia { programs.discord = {