1
0
mirror of https://github.com/nix-community/home-manager synced 2024-07-01 02:48:30 +02:00
home-manager/modules/services/swayidle.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

136 lines
3.5 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.swayidle;
mkTimeout = t:
[ "timeout" (toString t.timeout) (escapeShellArg t.command) ]
++ optionals (t.resumeCommand != null) [
"resume"
(escapeShellArg t.resumeCommand)
];
mkEvent = e: [ e.event (escapeShellArg e.command) ];
args = cfg.extraArgs ++ (concatMap mkTimeout cfg.timeouts)
++ (concatMap mkEvent cfg.events);
in {
meta.maintainers = [ maintainers.c0deaddict ];
options.services.swayidle = let
timeoutModule = { ... }: {
options = {
timeout = mkOption {
type = types.ints.positive;
example = 60;
description = lib.mdDoc "Timeout in seconds.";
};
command = mkOption {
type = types.str;
description =
lib.mdDoc "Command to run after timeout seconds of inactivity.";
};
resumeCommand = mkOption {
type = with types; nullOr str;
default = null;
description =
lib.mdDoc "Command to run when there is activity again.";
};
};
};
eventModule = { ... }: {
options = {
event = mkOption {
type = types.enum [ "before-sleep" "after-resume" "lock" "unlock" ];
description = lib.mdDoc "Event name.";
};
command = mkOption {
type = types.str;
description = lib.mdDoc "Command to run when event occurs.";
};
};
};
in {
enable = mkEnableOption (lib.mdDoc "idle manager for Wayland");
package = mkOption {
type = types.package;
default = pkgs.swayidle;
defaultText = literalExpression "pkgs.swayidle";
description = lib.mdDoc "Swayidle package to install.";
};
timeouts = mkOption {
type = with types; listOf (submodule timeoutModule);
default = [ ];
example = literalExpression ''
[
{ timeout = 60; command = "${pkgs.swaylock}/bin/swaylock -fF"; }
]
'';
description = lib.mdDoc "List of commands to run after idle timeout.";
};
events = mkOption {
type = with types; listOf (submodule eventModule);
default = [ ];
example = literalExpression ''
[
{ event = "before-sleep"; command = "${pkgs.swaylock}/bin/swaylock"; }
{ event = "lock"; command = "lock"; }
]
'';
description = lib.mdDoc "Run command on occurrence of a event.";
};
extraArgs = mkOption {
type = with types; listOf str;
default = [ ];
description = lib.mdDoc "Extra arguments to pass to swayidle.";
};
systemdTarget = mkOption {
type = types.str;
default = "sway-session.target";
description = lib.mdDoc ''
Systemd target to bind to.
'';
};
};
config = mkIf cfg.enable {
assertions = [
(hm.assertions.assertPlatform "services.swayidle" pkgs platforms.linux)
];
systemd.user.services.swayidle = {
Unit = {
Description = "Idle manager for Wayland";
Documentation = "man:swayidle(1)";
PartOf = [ "graphical-session.target" ];
};
Service = {
Type = "simple";
# swayidle executes commands using "sh -c", so the PATH needs to contain a shell.
Environment = [ "PATH=${makeBinPath [ pkgs.bash ]}" ];
ExecStart =
"${cfg.package}/bin/swayidle -w ${concatStringsSep " " args}";
};
Install = { WantedBy = [ cfg.systemdTarget ]; };
};
};
}