diff --git a/modules/services/picom.nix b/modules/services/picom.nix index d4702d3e..9ea052ec 100644 --- a/modules/services/picom.nix +++ b/modules/services/picom.nix @@ -1,13 +1,14 @@ { config, lib, pkgs, ... }: -with lib; -with builtins; - let + inherit (builtins) toJSON toString; + inherit (lib) + concatStringsSep elemAt literalExpression mkEnableOption mkIf mkOption + mkRemovedOptionModule optional optionalAttrs optionalString types; cfg = config.services.picom; - configFile = pkgs.writeText "picom.conf" (optionalString cfg.fade '' + configFile = optionalString cfg.fade '' # fading fading = true; fade-delta = ${toString cfg.fadeDelta}; @@ -46,8 +47,7 @@ let # other options backend = ${toJSON cfg.backend}; vsync = ${toJSON cfg.vSync}; - refresh-rate = ${toString cfg.refreshRate}; - '' + cfg.extraOptions); + '' + cfg.extraOptions; in { @@ -250,15 +250,6 @@ in { ''; }; - refreshRate = mkOption { - type = types.int; - default = 0; - example = 60; - description = '' - Screen refresh rate (0 = automatically detect). - ''; - }; - package = mkOption { type = types.package; default = pkgs.picom; @@ -282,6 +273,11 @@ in { }; }; + imports = [ + (mkRemovedOptionModule [ "services" "picom" "refreshRate" ] + "The option `refresh-rate` has been deprecated by upstream.") + ]; + config = mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.picom" pkgs @@ -290,6 +286,8 @@ in { home.packages = [ cfg.package ]; + xdg.configFile."picom/picom.conf".text = configFile; + systemd.user.services.picom = { Unit = { Description = "Picom X11 compositor"; @@ -299,17 +297,13 @@ in { Install = { WantedBy = [ "graphical-session.target" ]; }; - Service = let - experimentalBackendsFlag = - if cfg.experimentalBackends then " --experimental-backends" else ""; - in { - ExecStart = "${cfg.package}/bin/picom --config ${configFile}" - + experimentalBackendsFlag; + Service = { + ExecStart = concatStringsSep " " ([ + "${cfg.package}/bin/picom" + "--config ${config.xdg.configFile."picom/picom.conf".source}" + ] ++ optional cfg.experimentalBackends "--experimental-backends"); Restart = "always"; RestartSec = 3; - } // optionalAttrs (cfg.backend == "glx") { - # Temporarily fixes corrupt colours with Mesa 18. - Environment = [ "allow_rgb10_configs=false" ]; }; }; }; diff --git a/tests/default.nix b/tests/default.nix index 6eb636f8..03a86aec 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -155,6 +155,7 @@ import nmt { ./modules/services/mpd ./modules/services/pantalaimon ./modules/services/pbgopy + ./modules/services/picom ./modules/services/playerctld ./modules/services/polybar ./modules/services/redshift-gammastep diff --git a/tests/modules/services/picom/default.nix b/tests/modules/services/picom/default.nix new file mode 100644 index 00000000..64370131 --- /dev/null +++ b/tests/modules/services/picom/default.nix @@ -0,0 +1 @@ +{ picom-basic-configuration = ./picom-basic-configuration.nix; } diff --git a/tests/modules/services/picom/picom-basic-configuration-expected.conf b/tests/modules/services/picom/picom-basic-configuration-expected.conf new file mode 100644 index 00000000..6a7ac09a --- /dev/null +++ b/tests/modules/services/picom/picom-basic-configuration-expected.conf @@ -0,0 +1,33 @@ +# fading +fading = true; +fade-delta = 5; +fade-in-step = 0.04; +fade-out-step = 0.04; +fade-exclude = ["window_type *= 'menu'","name ~= 'Firefox$'","focused = 1"]; + +# shadows +shadow = true; +shadow-offset-x = -10; +shadow-offset-y = -15; +shadow-opacity = 0.8; +shadow-exclude = ["window_type *= 'menu'","name ~= 'Firefox$'","focused = 1"]; + +# opacity +active-opacity = 1.0; +inactive-opacity = 1.0; +inactive-dim = 0.0; +opacity-rule = []; + +wintypes: +{ + dock = { shadow = false; }; + dnd = { shadow = false; }; + popup_menu = { opacity = 1.0; }; + dropdown_menu = { opacity = 1.0; }; +}; + +# other options +backend = "xrender"; +vsync = true; +unredir-if-possible = true; +dbe = true; diff --git a/tests/modules/services/picom/picom-basic-configuration-expected.service b/tests/modules/services/picom/picom-basic-configuration-expected.service new file mode 100644 index 00000000..62620502 --- /dev/null +++ b/tests/modules/services/picom/picom-basic-configuration-expected.service @@ -0,0 +1,12 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +ExecStart=@picom@/bin/picom --config /nix/store/00000000000000000000000000000000-hm_picompicom.conf --experimental-backends +Restart=always +RestartSec=3 + +[Unit] +After=graphical-session-pre.target +Description=Picom X11 compositor +PartOf=graphical-session.target diff --git a/tests/modules/services/picom/picom-basic-configuration.nix b/tests/modules/services/picom/picom-basic-configuration.nix new file mode 100644 index 00000000..41f1ba01 --- /dev/null +++ b/tests/modules/services/picom/picom-basic-configuration.nix @@ -0,0 +1,37 @@ +{ config, pkgs, ... }: + +{ + services.picom = { + enable = true; + fade = true; + fadeDelta = 5; + fadeSteps = [ "0.04" "0.04" ]; + fadeExclude = + [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ]; + shadow = true; + shadowOffsets = [ (-10) (-15) ]; + shadowOpacity = "0.8"; + shadowExclude = + [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ]; + backend = "xrender"; + vSync = true; + extraOptions = '' + unredir-if-possible = true; + dbe = true; + ''; + experimentalBackends = true; + }; + + test.stubs.picom = { }; + + nmt.script = '' + assertFileContent \ + home-files/.config/picom/picom.conf \ + ${./picom-basic-configuration-expected.conf} + + serviceFile=$(normalizeStorePaths home-files/.config/systemd/user/picom.service) + assertFileContent \ + "$serviceFile" \ + ${./picom-basic-configuration-expected.service} + ''; +}