1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-27 04:09:47 +01:00
home-manager/modules/services/kanshi.nix

232 lines
5.7 KiB
Nix
Raw Normal View History

2020-04-12 15:42:43 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.kanshi;
outputModule = types.submodule {
options = {
criteria = mkOption {
type = types.str;
description = ''
2020-04-12 15:42:43 +02:00
The criteria can either be an output name, an output description or "*".
The latter can be used to match any output.
On
{manpage}`sway(1)`,
2020-04-12 15:42:43 +02:00
output names and descriptions can be obtained via
`swaymsg -t get_outputs`.
2020-04-12 15:42:43 +02:00
'';
};
status = mkOption {
type = types.nullOr (types.enum [ "enable" "disable" ]);
default = null;
description = ''
2020-04-12 15:42:43 +02:00
Enables or disables the specified output.
'';
};
mode = mkOption {
type = types.nullOr types.str;
default = null;
example = "1920x1080@60Hz";
description = ''
2020-04-12 15:42:43 +02:00
<width>x<height>[@<rate>[Hz]]
2020-04-12 15:42:43 +02:00
Configures the specified output to use the specified mode.
Modes are a combination of width and height (in pixels) and
a refresh rate (in Hz) that your display can be configured to use.
'';
};
position = mkOption {
type = types.nullOr types.str;
default = null;
example = "1600,0";
description = ''
2020-04-12 15:42:43 +02:00
<x>,<y>
2020-04-12 15:42:43 +02:00
Places the output at the specified position in the global coordinates
space.
'';
};
scale = mkOption {
type = types.nullOr types.float;
default = null;
example = 2;
description = ''
2020-04-12 15:42:43 +02:00
Scales the output by the specified scale factor.
'';
};
transform = mkOption {
type = types.nullOr (types.enum [
"normal"
"90"
"180"
"270"
"flipped"
"flipped-90"
"flipped-180"
"flipped-270"
]);
default = null;
description = ''
2020-04-12 15:42:43 +02:00
Sets the output transform.
'';
};
2023-08-10 15:05:36 +02:00
adaptiveSync = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = ''
Enables or disables adaptive synchronization
(aka. Variable Refresh Rate).
'';
};
2020-04-12 15:42:43 +02:00
};
};
2023-08-10 15:05:36 +02:00
outputStr =
{ criteria, status, mode, position, scale, transform, adaptiveSync, ... }:
2020-04-12 15:42:43 +02:00
''output "${criteria}"'' + optionalString (status != null) " ${status}"
+ optionalString (mode != null) " mode ${mode}"
+ optionalString (position != null) " position ${position}"
+ optionalString (scale != null) " scale ${toString scale}"
2023-08-10 15:05:36 +02:00
+ optionalString (transform != null) " transform ${transform}"
+ optionalString (adaptiveSync != null)
" adaptive_sync ${if adaptiveSync then "on" else "off"}";
2020-04-12 15:42:43 +02:00
profileModule = types.submodule {
options = {
outputs = mkOption {
type = types.listOf outputModule;
default = [ ];
description = ''
2020-04-12 15:42:43 +02:00
Outputs configuration.
'';
};
exec = mkOption {
type = with types; coercedTo str singleton (listOf str);
default = [ ];
2020-04-12 15:42:43 +02:00
example =
"[ \${pkg.sway}/bin/swaymsg workspace 1, move workspace to eDP-1 ]";
description = ''
2022-12-03 05:20:00 +01:00
Commands executed after the profile is successfully applied.
Note that if you provide multiple commands, they will be
executed asynchronously with no guaranteed ordering.
2020-04-12 15:42:43 +02:00
'';
};
};
};
profileStr = name:
{ outputs, exec, ... }: ''
2020-04-12 15:42:43 +02:00
profile ${name} {
${
concatStringsSep "\n "
(map outputStr outputs ++ map (cmd: "exec ${cmd}") exec)
}
2020-04-12 15:42:43 +02:00
}
'';
in {
meta.maintainers = [ hm.maintainers.nurelin ];
2020-04-12 15:42:43 +02:00
options.services.kanshi = {
enable = mkEnableOption
"kanshi, a Wayland daemon that automatically configures outputs";
2020-04-12 15:42:43 +02:00
package = mkOption {
type = types.package;
default = pkgs.kanshi;
defaultText = literalExpression "pkgs.kanshi";
description = ''
2020-04-12 15:42:43 +02:00
kanshi derivation to use.
'';
};
profiles = mkOption {
type = types.attrsOf profileModule;
default = { };
description = ''
2020-04-12 15:42:43 +02:00
List of profiles.
'';
example = literalExpression ''
undocked = {
outputs = [
{
criteria = "eDP-1";
}
];
};
docked = {
outputs = [
{
criteria = "eDP-1";
}
{
criteria = "Some Company ASDF 4242";
transform = "90";
}
];
};
'';
2020-04-12 15:42:43 +02:00
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = ''
2020-04-12 15:42:43 +02:00
Extra configuration lines to append to the kanshi
configuration file.
'';
};
systemdTarget = mkOption {
type = types.str;
default = "sway-session.target";
description = ''
2020-04-12 15:42:43 +02:00
Systemd target to bind to.
'';
};
};
config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.kanshi" pkgs
lib.platforms.linux)
];
2020-04-12 15:42:43 +02:00
xdg.configFile."kanshi/config".text = ''
${concatStringsSep "\n" (mapAttrsToList profileStr cfg.profiles)}
${cfg.extraConfig}
'';
systemd.user.services.kanshi = {
Unit = {
Description = "Dynamic output configuration";
Documentation = "man:kanshi(1)";
PartOf = cfg.systemdTarget;
Requires = cfg.systemdTarget;
After = cfg.systemdTarget;
};
Service = {
Type = "simple";
ExecStart = "${cfg.package}/bin/kanshi";
Restart = "always";
};
Install = { WantedBy = [ cfg.systemdTarget ]; };
};
};
}