diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 375be75a9..6f810af34 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -360,6 +360,8 @@ Makefile @thiagokokada /modules/programs/zsh/prezto.nix @NickHu +/modules/services/autorandr.nix @GaetanLepage + /modules/services/barrier.nix @Kritnich /tests/modules/services/barrier @Kritnich diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 12d83bd40..57c5574fd 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -907,6 +907,14 @@ in A new module is available: 'programs.rbenv'. ''; } + + { + time = "2023-02-02T20:49:05+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.autorandr'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 7bd4a49b1..0e71ea3a1 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -203,6 +203,7 @@ let ./programs/zplug.nix ./programs/zsh.nix ./programs/zsh/prezto.nix + ./services/autorandr.nix ./services/barrier.nix ./services/betterlockscreen.nix ./services/blueman-applet.nix diff --git a/modules/services/autorandr.nix b/modules/services/autorandr.nix new file mode 100644 index 000000000..84791a667 --- /dev/null +++ b/modules/services/autorandr.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.services.autorandr; + +in { + + meta.maintainers = [ maintainers.GaetanLepage ]; + + options = { + services.autorandr = { + enable = mkEnableOption "" // { + description = '' + Whether to enable the Autorandr systemd service. + This module is complementary to programs.autorandr which handles the + configuration (profiles). + ''; + }; + + ignoreLid = mkOption { + default = false; + type = types.bool; + description = + "Treat outputs as connected even if their lids are closed."; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.autorandr" pkgs + lib.platforms.linux) + ]; + + systemd.user.services.autorandr = { + Unit = { + Description = "autorandr"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.autorandr}/bin/autorandr --change ${ + optionalString cfg.ignoreLid "--ignore-lid" + }"; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + }; +}