diff --git a/modules/programs/eww.nix b/modules/programs/eww.nix index 75a109226..9eb9d22b7 100644 --- a/modules/programs/eww.nix +++ b/modules/programs/eww.nix @@ -3,12 +3,10 @@ with lib; let - cfg = config.programs.eww; ewwCmd = "${cfg.package}/bin/eww"; - in { - meta.maintainers = [ hm.maintainers.mainrs ]; + meta.maintainers = [ hm.maintainers.mainrs maintainers.eveeifyeve ]; options.programs.eww = { enable = mkEnableOption "eww"; @@ -23,8 +21,46 @@ in { ''; }; + yuckConfig = mkOption { + type = types.nullOr types.lines; + default = null; + example = '' + (defwindow example + :monitor 0 + :geometry (geometry :x "0%" + :y "20px" + :width "90%" + :height "30px" + :anchor "top center") + :stacking "fg" + :reserve (struts :distance "40px" :side "top") + :windowtype "dock" + :wm-ignore false + "example content") + ''; + description = '' + The content that gets symlinked to + {file} `$XDG_CONFIG_HOME/eww/eww.yuck`. + ''; + }; + + scssConfig = mkOption { + type = types.nullOr types.lines; + default = null; + example = '' + window { + background: pink; + } + ''; + description = '' + The directory that gets symlinked to + {file} `$XDG_CONFIG_HOME/eww/eww.scss`. + ''; + }; + configDir = mkOption { - type = types.path; + type = types.nullOr types.path; + default = null; example = literalExpression "./eww-config-dir"; description = '' The directory that gets symlinked to @@ -32,6 +68,21 @@ in { ''; }; + systemd.enable = mkEnableOption "Launches Eww Daemon"; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Eww service. + + When setting this value to `"sway-session.target"`, + make sure to also enable {option}`wayland.windowManager.sway.systemd.enable`, + otherwise the service may never be started. + ''; + }; + enableBashIntegration = mkEnableOption "Bash integration" // { default = true; }; @@ -45,26 +96,66 @@ in { }; }; - config = mkIf cfg.enable { - home.packages = [ cfg.package ]; - xdg.configFile."eww".source = cfg.configDir; + config = mkIf cfg.enable (mkMerge [ + { + assertions = + let message = "You can have either yuck & scss or configDir enabled"; + in [ + { + assertion = !(cfg.scssConfig == null && cfg.configDir == null); + inherit message; + } + { + assertion = !(cfg.yuckConfig == null && cfg.configDir == null); + inherit message; + } + ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration '' - if [[ $TERM != "dumb" ]]; then - eval "$(${ewwCmd} shell-completions --shell bash)" - fi - ''; + home.packages = [ cfg.package ]; - programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' - if [[ $TERM != "dumb" ]]; then - eval "$(${ewwCmd} shell-completions --shell zsh)" - fi - ''; + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + if [[ $TERM != "dumb" ]]; then + eval "$(${ewwCmd} shell-completions --shell bash)" + fi + ''; - programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' - if test "$TERM" != "dumb" - eval "$(${ewwCmd} shell-completions --shell fish)" - end - ''; - }; + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + if [[ $TERM != "dumb" ]]; then + eval "$(${ewwCmd} shell-completions --shell zsh)" + fi + ''; + + programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' + if test "$TERM" != "dumb" + eval "$(${ewwCmd} shell-completions --shell fish)" + end + ''; + } + + (mkIf cfg.configDir + == null { xdg.configFile."eww".source = cfg.configDir; }) + + (mkIf cfg.yuckConfig == null { xdg.configFile."eww/eww.yuck".text = cfg.yuckConfig; }) + + (mkIf cfg.scssConfig == null { xdg.configFile."eww/eww.scss".text = cfg.scssConfig; }) + + (mkIf cfg.systemd.enable { + systemd.user.services.eww = { + Unit = { + Description = "ElKowars wacky widgets daemon"; + Documentation = "https://elkowar.github.io/eww/"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = "${cfg.package} daemon --no-daemonize"; + ExecStop = "${cfg.package} kill"; + ExecReload = "${cfg.package} reload"; + }; + + Install = { WantedBy = [ cfg.systemd.target ]; }; + }; + }) + ]); } diff --git a/tests/default.nix b/tests/default.nix index f4b03275b..89ac1940c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -194,6 +194,7 @@ in import nmtSrc { ./modules/programs/beets # One test relies on services.mpd ./modules/programs/bemenu ./modules/programs/boxxy + ./modules/programs/eww ./modules/programs/firefox/firefox.nix ./modules/programs/firefox/floorp.nix ./modules/programs/foot diff --git a/tests/modules/programs/eww/basic-configuration.nix b/tests/modules/programs/eww/basic-configuration.nix new file mode 100644 index 000000000..48304f59f --- /dev/null +++ b/tests/modules/programs/eww/basic-configuration.nix @@ -0,0 +1,38 @@ +{ config, pkgs, ... }: + +{ + config = { + programs.eww = { + enable = true; + systemd.enable = true; + configYuck = '' + (defwindow example + :monitor 0 + :geometry (geometry :x "0%" + :y "20px" + :width "90%" + :height "30px" + :anchor "top center") + :stacking "fg" + :reserve (struts :distance "40px" :side "top") + :windowtype "dock" + :wm-ignore false + "example content") + ''; + configScss = '' + window { + background: pink; + } + ''; + }; + + test.stubs.eww = { name = "eww"; }; + + nmt.script = '' + assertFileExists home-files/.config/eww/eww.yuck + assertFileExists home-files/.config/eww/eww.scss + serviceFile=$(normalizeStorePaths home-files/.config/systemd/user/eww.service) + assertFileContent "$serviceFile" ${./basic-configuration.service} + ''; + }; +} diff --git a/tests/modules/programs/eww/basic-configuration.service b/tests/modules/programs/eww/basic-configuration.service new file mode 100644 index 000000000..bc260f691 --- /dev/null +++ b/tests/modules/programs/eww/basic-configuration.service @@ -0,0 +1,13 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +ExecReload=@eww@ reload +ExecStart=@eww@ daemon --no-daemonize +ExecStop=@eww@ kill + +[Unit] +After=graphical-session.target +Description=ElKowars wacky widgets daemon +Documentation=https://elkowar.github.io/eww/ +PartOf=graphical-session.target diff --git a/tests/modules/programs/eww/default.nix b/tests/modules/programs/eww/default.nix new file mode 100644 index 000000000..500e1accd --- /dev/null +++ b/tests/modules/programs/eww/default.nix @@ -0,0 +1 @@ +{ eww-basic-configuration = ./basic-configuration.nix; }