From 8ff7bb3f4d82a05a52d5242ec454bba14f5d6cc6 Mon Sep 17 00:00:00 2001 From: Henri Sota Date: Tue, 16 Apr 2024 22:44:55 +0200 Subject: [PATCH] tofi: add module --- modules/lib/maintainers.nix | 6 ++ modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + modules/programs/tofi.nix | 63 +++++++++++++++++++ tests/default.nix | 1 + .../programs/tofi/basic-configuration.conf | 12 ++++ .../programs/tofi/basic-configuration.nix | 28 +++++++++ tests/modules/programs/tofi/default.nix | 1 + 8 files changed, 120 insertions(+) create mode 100644 modules/programs/tofi.nix create mode 100644 tests/modules/programs/tofi/basic-configuration.conf create mode 100644 tests/modules/programs/tofi/basic-configuration.nix create mode 100644 tests/modules/programs/tofi/default.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 2c4fbd9d..727d4c3c 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -77,6 +77,12 @@ githubId = 32838899; name = "Daniel Wagenknecht"; }; + henrisota = { + email = "henrisota@users.noreply.github.com"; + github = "henrisota"; + githubId = "56848082"; + name = "Henri Sota"; + }; jack5079 = { name = "Jack W."; email = "nix@jack.cab"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 2c00c5ed..8e304545 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1483,6 +1483,14 @@ in { A new module is available: 'programs.fd'. ''; } + + { + time = "2024-04-19T09:23:52+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.tofi'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index b182a33e..c283b071 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -228,6 +228,7 @@ let ./programs/tiny.nix ./programs/tmate.nix ./programs/tmux.nix + ./programs/tofi.nix ./programs/topgrade.nix ./programs/translate-shell.nix ./programs/urxvt.nix diff --git a/modules/programs/tofi.nix b/modules/programs/tofi.nix new file mode 100644 index 00000000..acc1a994 --- /dev/null +++ b/modules/programs/tofi.nix @@ -0,0 +1,63 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.tofi; + +in { + meta.maintainers = [ hm.maintainers.henrisota ]; + + options.programs.tofi = { + enable = mkEnableOption "Tofi, a tiny dynamic menu for Wayland"; + + package = mkPackageOption pkgs "tofi" { }; + + settings = mkOption { + type = with types; + let primitive = either (either str int) bool; + in attrsOf primitive; + default = { }; + example = literalExpression '' + { + background-color = "#000000"; + border-width = 0; + font = "monospace"; + height = "100%"; + num-results = 5; + outline-width = 0; + padding-left = "35%"; + padding-top = "35%"; + result-spacing = 25; + width = "100%"; + } + ''; + description = '' + Settings to be written to the Tofi configuration file. + + See + for the full list of options. + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = + [ (hm.assertions.assertPlatform "programs.tofi" pkgs platforms.linux) ]; + + home.packages = [ cfg.package ]; + + xdg.configFile."tofi/config" = mkIf (cfg.settings != { }) { + text = let + renderedSettings = generators.toINIWithGlobalSection { } { + globalSection = cfg.settings; + }; + in removeSuffix "\n\n" '' + # Generated by Home Manager. + + ${renderedSettings} + ''; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 62538966..c95b288a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -207,6 +207,7 @@ in import nmtSrc { ./modules/programs/swayr ./modules/programs/terminator ./modules/programs/thunderbird + ./modules/programs/tofi ./modules/programs/waybar ./modules/programs/wlogout ./modules/programs/wofi diff --git a/tests/modules/programs/tofi/basic-configuration.conf b/tests/modules/programs/tofi/basic-configuration.conf new file mode 100644 index 00000000..3a95c23e --- /dev/null +++ b/tests/modules/programs/tofi/basic-configuration.conf @@ -0,0 +1,12 @@ +# Generated by Home Manager. + +background-color=#000000 +border-width=0 +font=monospace +height=100% +num-results=5 +outline-width=0 +padding-left=35% +padding-top=35% +result-spacing=25 +width=100% diff --git a/tests/modules/programs/tofi/basic-configuration.nix b/tests/modules/programs/tofi/basic-configuration.nix new file mode 100644 index 00000000..28b28996 --- /dev/null +++ b/tests/modules/programs/tofi/basic-configuration.nix @@ -0,0 +1,28 @@ +{ config, pkgs, ... }: { + config = { + programs.tofi = { + enable = true; + package = pkgs.tofi; + settings = { + background-color = "#000000"; + border-width = 0; + font = "monospace"; + height = "100%"; + num-results = 5; + outline-width = 0; + padding-left = "35%"; + padding-top = "35%"; + result-spacing = 25; + width = "100%"; + }; + }; + + test.stubs.tofi = { }; + + nmt.script = '' + assertFileExists home-files/.config/tofi/config + assertFileContent home-files/.config/tofi/config \ + ${./basic-configuration.conf} + ''; + }; +} diff --git a/tests/modules/programs/tofi/default.nix b/tests/modules/programs/tofi/default.nix new file mode 100644 index 00000000..22b89d80 --- /dev/null +++ b/tests/modules/programs/tofi/default.nix @@ -0,0 +1 @@ +{ tofi-basic-configuration = ./basic-configuration.nix; }