Merge pull request #20385 from ericsagnes/feat/i3-refactor

i3 module: refactor
This commit is contained in:
Joachim F 2016-11-23 05:11:14 +01:00 committed by GitHub
commit a6f392abd6

View File

@ -3,52 +3,58 @@
with lib; with lib;
let let
wmCfg = config.services.xserver.windowManager; cfg = config.services.xserver.windowManager.i3;
in
{
options.services.xserver.windowManager.i3 = {
enable = mkEnableOption "i3 window manager";
i3option = name: {
enable = mkEnableOption name;
configFile = mkOption { configFile = mkOption {
default = null; default = null;
type = types.nullOr types.path; type = with types; nullOr path;
description = '' description = ''
Path to the i3 configuration file. Path to the i3 configuration file.
If left at the default value, $HOME/.i3/config will be used. If left at the default value, $HOME/.i3/config will be used.
''; '';
}; };
extraSessionCommands = mkOption { extraSessionCommands = mkOption {
default = ""; default = "";
type = types.lines; type = types.lines;
description = '' description = ''
Shell commands executed just before i3 is started. Shell commands executed just before i3 is started.
''; '';
}; };
package = mkOption {
type = types.package;
default = pkgs.i3;
defaultText = "pkgs.i3";
example = "pkgs.i3-gaps";
description = ''
i3 package to use.
'';
};
}; };
i3config = name: pkg: cfg: { config = mkIf cfg.enable {
services.xserver.windowManager.session = [{ services.xserver.windowManager.session = [{
inherit name; name = "i3";
start = '' start = ''
${cfg.extraSessionCommands} ${cfg.extraSessionCommands}
${pkg}/bin/i3 ${optionalString (cfg.configFile != null) ${cfg.package}/bin/i3 ${optionalString (cfg.configFile != null)
"-c \"${cfg.configFile}\"" "-c \"${cfg.configFile}\""
} & } &
waitPID=$! waitPID=$!
''; '';
}]; }];
environment.systemPackages = [ pkg ]; environment.systemPackages = [ cfg.package ];
}; };
in imports = [
(mkRemovedOptionModule [ "services" "xserver" "windowManager" "i3-gaps" "enable" ]
{ "Use services.xserver.windowManager.i3.enable and set services.xserver.windowManager.i3.package to pkgs.i3-gaps to use i3-gaps.")
options.services.xserver.windowManager = {
i3 = i3option "i3";
i3-gaps = i3option "i3-gaps";
};
config = mkMerge [
(mkIf wmCfg.i3.enable (i3config "i3" pkgs.i3 wmCfg.i3))
(mkIf wmCfg.i3-gaps.enable (i3config "i3-gaps" pkgs.i3-gaps wmCfg.i3-gaps))
]; ];
} }