fork/home-manager
git clone https://git.julia.blue/fork/home-manager
6e1eff9a
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . kanshi ; 8 9outputModule = types . submodule { 10options = { 11 12criteria = mkOption { 13type = types . str ; 14description = '' 15The criteria can either be an output name, an output description or "*". 16The latter can be used to match any output. 17 18On 19{manpage}`sway(1)`, 20output names and descriptions can be obtained via 21`swaymsg -t get_outputs`. 22'' ; 23}; 24 25status = mkOption { 26type = types . nullOr ( types . enum [ "enable" "disable" ]); 27default = null ; 28description = '' 29Enables or disables the specified output. 30'' ; 31}; 32 33mode = mkOption { 34type = types . nullOr types . str ; 35default = null ; 36example = "1920x1080@60Hz" ; 37description = '' 38<width>x<height>[@<rate>[Hz]] 39 40Configures the specified output to use the specified mode. 41Modes are a combination of width and height (in pixels) and 42a refresh rate (in Hz) that your display can be configured to use. 43'' ; 44}; 45 46position = mkOption { 47type = types . nullOr types . str ; 48default = null ; 49example = "1600,0" ; 50description = '' 51<x>,<y> 52 53Places the output at the specified position in the global coordinates 54space. 55'' ; 56}; 57 58scale = mkOption { 59type = types . nullOr types . float ; 60default = null ; 61example = 2 ; 62description = '' 63Scales the output by the specified scale factor. 64'' ; 65}; 66 67transform = mkOption { 68type = types . nullOr ( types . enum [ 69"normal" 70"90" 71"180" 72"270" 73"flipped" 74"flipped-90" 75"flipped-180" 76"flipped-270" 77]); 78default = null ; 79description = '' 80Sets the output transform. 81'' ; 82}; 83 84adaptiveSync = mkOption { 85type = types . nullOr types . bool ; 86default = null ; 87example = true ; 88description = '' 89Enables or disables adaptive synchronization 90(aka. Variable Refresh Rate). 91'' ; 92}; 93}; 94}; 95 96outputStr = 97{ criteria , status , mode , position , scale , transform , adaptiveSync , ...} : 98''output " ${ criteria } "'' + optionalString ( status != null ) " ${ status } " 99+ optionalString ( mode != null ) " mode ${ mode } " 100+ optionalString ( position != null ) " position ${ position } " 101+ optionalString ( scale != null ) " scale ${ toString scale } " 102+ optionalString ( transform != null ) " transform ${ transform } " 103+ optionalString ( adaptiveSync != null ) 104" adaptive_sync ${ if adaptiveSync then "on" else "off" } " ; 105 106profileModule = types . submodule { 107options = { 108outputs = mkOption { 109type = types . listOf outputModule ; 110default = [ ]; 111description = '' 112Outputs configuration. 113'' ; 114}; 115 116exec = mkOption { 117type = with types ; coercedTo str singleton ( listOf str ); 118default = [ ]; 119example = 120"[ \${pkg.sway}/bin/swaymsg workspace 1, move workspace to eDP-1 ]" ; 121description = '' 122Commands executed after the profile is successfully applied. 123Note that if you provide multiple commands, they will be 124executed asynchronously with no guaranteed ordering. 125'' ; 126}; 127}; 128}; 129 130profileStr = name : 131{ outputs , exec , ...} :'' 132profile ${ name } { 133${ 134concatStringsSep "\n " 135( map outputStr outputs ++ map ( cmd : "exec ${ cmd } " ) exec ) 136} 137} 138'' ; 139in { 140 141meta . maintainers = [ hm . maintainers . nurelin ]; 142 143options . services . kanshi = { 144enable = mkEnableOption 145"kanshi, a Wayland daemon that automatically configures outputs" ; 146 147package = mkOption { 148type = types . package ; 149default = pkgs . kanshi ; 150defaultText = literalExpression "pkgs.kanshi" ; 151description = '' 152kanshi derivation to use. 153'' ; 154}; 155 156profiles = mkOption { 157type = types . attrsOf profileModule ; 158default = { }; 159description = '' 160List of profiles. 161'' ; 162example = literalExpression '' 163undocked = { 164outputs = [ 165{ 166criteria = "eDP-1"; 167} 168]; 169}; 170docked = { 171outputs = [ 172{ 173criteria = "eDP-1"; 174} 175{ 176criteria = "Some Company ASDF 4242"; 177transform = "90"; 178} 179]; 180}; 181'' ; 182}; 183 184extraConfig = mkOption { 185type = types . lines ; 186default = "" ; 187description = '' 188Extra configuration lines to append to the kanshi 189configuration file. 190'' ; 191}; 192 193systemdTarget = mkOption { 194type = types . str ; 195default = "sway-session.target" ; 196description = '' 197Systemd target to bind to. 198'' ; 199}; 200}; 201 202config = mkIf cfg . enable { 203assertions = [ 204( lib . hm . assertions . assertPlatform "services.kanshi" pkgs 205lib . platforms . linux ) 206]; 207 208xdg . configFile . "kanshi/config" . text = '' 209${ concatStringsSep "\n" ( mapAttrsToList profileStr cfg . profiles )} 210${ cfg . extraConfig } 211'' ; 212 213systemd . user . services . kanshi = { 214Unit = { 215Description = "Dynamic output configuration" ; 216Documentation = "man:kanshi(1)" ; 217PartOf = cfg . systemdTarget ; 218Requires = cfg . systemdTarget ; 219After = cfg . systemdTarget ; 220}; 221 222Service = { 223Type = "simple" ; 224ExecStart = " ${ cfg . package } /bin/kanshi" ; 225Restart = "always" ; 226}; 227 228Install = { WantedBy = [ cfg . systemdTarget ]; }; 229}; 230}; 231}