diff options
Diffstat (limited to 'users/kassouni/palette/default.nix')
| -rw-r--r-- | users/kassouni/palette/default.nix | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/users/kassouni/palette/default.nix b/users/kassouni/palette/default.nix index 235f774..7e9eec4 100644 --- a/users/kassouni/palette/default.nix +++ b/users/kassouni/palette/default.nix @@ -1,18 +1,56 @@ -{ pkgs, lib, ... }: +{ + config, + lib, + pkgs, + ... +}: let - commandFiles = lib.attrNames ( - lib.filterAttrs (name: type: type == "regular" && name != "default.nix" && lib.hasSuffix ".nix" name) - (builtins.readDir ./.) + cfg = config.kassouni.palette; + + # Every sibling .nix file is an ordinary home-manager module that appends to + # kassouni.palette.commands, so dropping a file in here adds an entry. + commandModules = map (file: ./. + "/${file}") ( + lib.attrNames ( + lib.filterAttrs (name: type: type == "regular" && name != "default.nix" && lib.hasSuffix ".nix" name) + (builtins.readDir ./.) + ) ); - commands = map (file: pkgs.callPackage (./. + "/${file}") { }) commandFiles; in { - home.packages = [ + imports = commandModules; + + options.kassouni.palette.commands = lib.mkOption { + type = lib.types.listOf ( + lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Label shown in the palette menu."; + }; + icon = lib.mkOption { + type = lib.types.str; + description = "Nerd Font glyph shown before the label."; + }; + exe = lib.mkOption { + type = lib.types.package; + description = "Executable to run when the entry is selected."; + }; + }; + } + ); + default = [ ]; + description = '' + Entries shown in the rofi command palette. Menu order follows module + import order, which is alphabetical by filename. + ''; + }; + + config.home.packages = [ (pkgs.writers.writeBashBin "open-palette" '' set -eu - exes=(${lib.concatMapStringsSep " " (c: c.exe) commands}) + exes=(${lib.concatMapStringsSep " " (c: "${c.exe}") cfg.commands}) idx=$(${pkgs.rofi}/bin/rofi -dmenu -i -format i -p palette <<EOF -${lib.concatMapStrings (c: "${c.icon} ${c.name}\n") commands}EOF +${lib.concatMapStrings (c: "${c.icon} ${c.name}\n") cfg.commands}EOF ) exec "''${exes[$idx]}" '') |
