From 482b5d730c0cb9a5d39876c1733f8eeae7036300 Mon Sep 17 00:00:00 2001 From: Bruno Bigras <24027+bbigras@users.noreply.github.com> Date: Sat, 16 Aug 2025 16:24:55 -0400 Subject: [PATCH] WIP: wayland-bongocat: init module --- modules/lib/maintainers.nix | 6 + modules/programs/wayland-bongocat.nix | 145 ++++++++++++++++++ .../wayland-bongocat/custom-settings.nix | 41 +++++ .../wayland-bongocat/default-settings.nix | 21 +++ .../programs/wayland-bongocat/default.nix | 4 + 5 files changed, 217 insertions(+) create mode 100644 modules/programs/wayland-bongocat.nix create mode 100644 tests/modules/programs/wayland-bongocat/custom-settings.nix create mode 100644 tests/modules/programs/wayland-bongocat/default-settings.nix create mode 100644 tests/modules/programs/wayland-bongocat/default.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index beefbc9ae2fa..cde1bbd8c67b 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -73,6 +73,12 @@ github = "bamhm182"; githubId = 920269; }; + bbigras = { + name = "bbigras"; + email = "24027+bbigras@users.noreply.github.com"; + github = "bbigras"; + githubId = 24027; + }; bikku = { name = "Bikku"; email = "bikku+dev@slmail.me"; diff --git a/modules/programs/wayland-bongocat.nix b/modules/programs/wayland-bongocat.nix new file mode 100644 index 000000000000..3b99227d6fb1 --- /dev/null +++ b/modules/programs/wayland-bongocat.nix @@ -0,0 +1,145 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit (lib) + mkIf + mkOption + types + ; + cfg = config.programs.wayland-bongocat; + boolToInt = value: if value then 1 else 0; +in +{ + meta.maintainers = [ lib.maintainers.bbigras ]; + options.programs.wayland-bongocat = { + enable = lib.mkEnableOption "the wayland bongocat overlay"; + package = lib.mkPackageOption pkgs "wayland-bongocat" { nullable = true; }; + + cat = { + height = mkOption { + default = 50; + example = 25; + type = types.ints.unsigned; + description = "Size of bongo cat (16-128)."; + }; + xOffset = mkOption { + default = 0; + example = 25; + type = types.ints.unsigned; + description = "Horizontal position offset."; + }; + yOffset = mkOption { + default = 0; + example = 25; + type = types.ints.unsigned; + description = "Vertical position offset."; + }; + }; + keyboardDevices = mkOption { + default = [ "/dev/input/event4" ]; + example = [ "/dev/input/event1" ]; + type = types.listOf types.path; + description = "Input device paths."; + }; + fps = mkOption { + default = 60; + example = 60; + type = types.ints.unsigned; + description = "Animation frame rate (1-120)."; + }; + overlayOpacity = mkOption { + default = 150; + example = 0; + type = types.ints.unsigned; + description = "Background opacity (0-255, 0=transparent)."; + }; + overlayPosition = mkOption { + default = "top"; + example = "bottom"; + type = types.enum [ + "bottom" + "top" + ]; + description = "Position of overlay on screen"; + }; + debug = mkOption { + type = types.bool; + default = false; + description = "Enable debug logging"; + }; + monitor = mkOption { + default = null; + example = "eDP-1"; + type = types.str; + description = '' + Monitor to display on (e.g., "eDP-1", "HDMI-A-1") + Default (null) = Auto-detect + ''; + }; + }; + config = + let + configDir = + if (pkgs.stdenv.targetPlatform.isDarwin) then + "Library/Application Support/wayland-bongocat" + else + "${config.xdg.configHome}/wayland-bongocat"; + configFile = "${configDir}/settings.conf"; + + settings = { + main = { + cat_height = cfg.cat.height; + cat_x_offset = cfg.cat.xOffset; + cat_y_offset = cfg.cat.yOffset; + enable_debug = boolToInt cfg.debug; + fps = cfg.fps; + overlay_opacity = cfg.overlayOpacity; + }; + }; + in + mkIf cfg.enable { + home = { + packages = mkIf (cfg.package != null) [ cfg.package ]; + + file.wayland-bongocat-settings = { + enable = settings != { }; + target = configFile; + text = + let + toIni = lib.generators.toINI { }; + in + lib.mkMerge ( + [ + "# Generated by Home Manager." + (toIni settings) + ] + ++ (builtins.map (item: "keyboard_device=${item}") cfg.keyboardDevices) + ); + + }; + }; + systemd.user.services = { + bongocat = { + Unit = { + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + Service = { + Restart = "on-failure"; + PrivateTmp = true; + ProtectSystem = "full"; + Type = "exec"; + Slice = "session.slice"; # ? + ExecStart = "${pkgs.wayland-bongocat}/bin/bongocat --config ${configFile}"; + }; + }; + }; + }; +} diff --git a/tests/modules/programs/wayland-bongocat/custom-settings.nix b/tests/modules/programs/wayland-bongocat/custom-settings.nix new file mode 100644 index 000000000000..6285aad4ac1a --- /dev/null +++ b/tests/modules/programs/wayland-bongocat/custom-settings.nix @@ -0,0 +1,41 @@ +{ config, pkgs, ... }: +{ + config = { + programs.wayland-bongocat = { + package = config.lib.test.mkStubPackage { name = "wayland-bongocat"; }; + enable = true; + cat = { + height = 123; + }; + keyboardDevices = [ + "/dev/input/event1" + "/dev/input/event2" + ]; + }; + + nmt.script = + let + configDir = + if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support/wayland-bongocat" + else + "home-files/.config/wayland-bongocat"; + configFile = "${configDir}/settings.conf"; + in + '' + assertFileExists "${configFile}" + assertFileContent "${configFile}" ${pkgs.writeText "wayland-bongocat.config-custom.expected" '' + # Generated by Home Manager. + [main] + cat_height=123 + cat_x_offset=0 + cat_y_offset=0 + enable_debug=0 + fps=60 + overlay_opacity=150 + + keyboard_device=/dev/input/event1 + keyboard_device=/dev/input/event2''} + ''; + }; +} diff --git a/tests/modules/programs/wayland-bongocat/default-settings.nix b/tests/modules/programs/wayland-bongocat/default-settings.nix new file mode 100644 index 000000000000..590228748094 --- /dev/null +++ b/tests/modules/programs/wayland-bongocat/default-settings.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: +{ + config = { + programs.wayland-bongocat = { + package = config.lib.test.mkStubPackage { name = "wayland-bongocat"; }; + enable = true; + }; + + nmt.script = + let + configDir = + if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support/wayland-bongocat" + else + "home-files/.config/wayland-bongocat"; + in + '' + assertPathNotExists "${configDir}/settings.conf" + ''; + }; +} diff --git a/tests/modules/programs/wayland-bongocat/default.nix b/tests/modules/programs/wayland-bongocat/default.nix new file mode 100644 index 000000000000..badfe89a58df --- /dev/null +++ b/tests/modules/programs/wayland-bongocat/default.nix @@ -0,0 +1,4 @@ +{ + wayland-bongocat-default-settings = ./default-settings.nix; + wayland-bongocat-custom-settings = ./custom-settings.nix; +}