diff --git a/modules/services/walker.nix b/modules/services/walker.nix new file mode 100644 index 00000000..abdb8d09 --- /dev/null +++ b/modules/services/walker.nix @@ -0,0 +1,120 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + types + mkIf + mkMerge + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.services.walker; + tomlFormat = pkgs.formats.toml { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + + options.services.walker = { + enable = mkEnableOption "walker"; + package = mkPackageOption pkgs "walker" { nullable = true; }; + settings = mkOption { + inherit (tomlFormat) type; + default = { }; + example = { + app_launch_prefix = ""; + terminal_title_flag = ""; + locale = ""; + close_when_open = false; + theme = "default"; + monitor = ""; + hotreload_theme = false; + as_window = false; + timeout = 0; + disable_click_to_close = false; + force_keyboard_focus = false; + }; + description = '' + Configuration settings for walker. All the available options can be found here: + + ''; + }; + + theme = mkOption { + type = + with types; + nullOr (submodule { + options = { + name = mkOption { + type = types.str; + default = "nixos"; + description = "The theme name."; + }; + + layout = mkOption { + inherit (tomlFormat) type; + default = { }; + description = '' + The layout of the theme. + + See for the full list of options. + ''; + }; + + style = mkOption { + type = lines; + default = ""; + description = "The styling of the theme, written in GTK CSS."; + }; + }; + }); + default = null; + description = "The custom theme used by walker. Setting this option overrides `settings.theme`."; + }; + + systemd.enable = mkOption { + type = types.bool; + default = false; + example = true; + description = "Whatever to enable Walker's Systemd Unit."; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.walker" pkgs lib.platforms.linux) + { + assertion = cfg.systemd.enable -> (cfg.package != null); + message = "Can't set services.walker.package to null if services.walker.systemd.enable is set to true;"; + } + ]; + + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + xdg.configFile."walker/config.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "walker-config" cfg.settings; + }; + systemd.user.services.walker = mkIf (cfg.systemd.enable && cfg.package != null) { + Unit.Description = "Walker - Application Runner"; + Install.WantedBy = [ "graphical-session.target" ]; + Service = { + ExecStart = "${lib.getExe cfg.package} --gapplication-service"; + Restart = "on-failure"; + }; + }; + } + (mkIf (cfg.theme != null) { + services.walker.settings.theme = cfg.theme.name; + xdg.configFile = { + "walker/themes/${cfg.theme.name}.toml".source = + tomlFormat.generate "walker-theme-${cfg.theme.name}.toml" cfg.theme.layout; + "walker/themes/${cfg.theme.name}.css".text = cfg.theme.style; + }; + }) + ]); +} diff --git a/tests/modules/services/walker/config.toml b/tests/modules/services/walker/config.toml new file mode 100644 index 00000000..5e89218a --- /dev/null +++ b/tests/modules/services/walker/config.toml @@ -0,0 +1,11 @@ +app_launch_prefix = "" +as_window = false +close_when_open = false +disable_click_to_close = false +force_keyboard_focus = false +hotreload_theme = false +locale = "" +monitor = "" +terminal_title_flag = "" +theme = "mytheme" +timeout = 0 diff --git a/tests/modules/services/walker/default.nix b/tests/modules/services/walker/default.nix new file mode 100644 index 00000000..5e57c7db --- /dev/null +++ b/tests/modules/services/walker/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + walker-example-config = ./example-config.nix; +} diff --git a/tests/modules/services/walker/example-config.nix b/tests/modules/services/walker/example-config.nix new file mode 100644 index 00000000..bc01bdd5 --- /dev/null +++ b/tests/modules/services/walker/example-config.nix @@ -0,0 +1,57 @@ +{ + services.walker = { + enable = true; + systemd.enable = true; + settings = { + app_launch_prefix = ""; + terminal_title_flag = ""; + locale = ""; + close_when_open = false; + monitor = ""; + hotreload_theme = false; + as_window = false; + timeout = 0; + disable_click_to_close = false; + force_keyboard_focus = false; + }; + + theme = { + name = "mytheme"; + layout = { + ui = { + anchors = { + bottom = true; + left = true; + right = true; + top = true; + }; + + window = { + h_align = "fill"; + v_align = "fill"; + }; + }; + }; + style = '' + * { + color: #dcd7ba; + } + ''; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/walker/config.toml + assertFileExists home-files/.config/walker/themes/mytheme.toml + assertFileExists home-files/.config/walker/themes/mytheme.css + + assertFileContent home-files/.config/walker/config.toml \ + ${./config.toml} + + assertFileContent home-files/.config/walker/themes/mytheme.toml \ + ${./mytheme.toml} + + assertFileContent home-files/.config/walker/themes/mytheme.css \ + ${./mytheme.css} + ''; +} diff --git a/tests/modules/services/walker/mytheme.css b/tests/modules/services/walker/mytheme.css new file mode 100644 index 00000000..035660d4 --- /dev/null +++ b/tests/modules/services/walker/mytheme.css @@ -0,0 +1,3 @@ +* { + color: #dcd7ba; +} diff --git a/tests/modules/services/walker/mytheme.toml b/tests/modules/services/walker/mytheme.toml new file mode 100644 index 00000000..1dc1cd72 --- /dev/null +++ b/tests/modules/services/walker/mytheme.toml @@ -0,0 +1,9 @@ +[ui.anchors] +bottom = true +left = true +right = true +top = true + +[ui.window] +h_align = "fill" +v_align = "fill"