1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.xserver.windowManager.i3;
12 updateSessionEnvironmentScript = ''
13 systemctl --user import-environment PATH DISPLAY XAUTHORITY DESKTOP_SESSION XDG_CONFIG_DIRS XDG_DATA_DIRS XDG_RUNTIME_DIR XDG_SESSION_ID DBUS_SESSION_BUS_ADDRESS || true
14 dbus-update-activation-environment --systemd --all || true
15 '';
16in
17
18{
19 options.services.xserver.windowManager.i3 = {
20 enable = mkEnableOption "i3 window manager";
21
22 configFile = mkOption {
23 default = null;
24 type = with types; nullOr path;
25 description = ''
26 Path to the i3 configuration file.
27 If left at the default value, $HOME/.i3/config will be used.
28 '';
29 };
30
31 updateSessionEnvironment = mkOption {
32 default = true;
33 type = types.bool;
34 description = ''
35 Whether to run dbus-update-activation-environment and systemctl import-environment before session start.
36 Required for xdg portals to function properly.
37 '';
38 };
39
40 extraSessionCommands = mkOption {
41 default = "";
42 type = types.lines;
43 description = ''
44 Shell commands executed just before i3 is started.
45 '';
46 };
47
48 package = mkPackageOption pkgs "i3" { };
49
50 extraPackages = mkOption {
51 type = with types; listOf package;
52 default = with pkgs; [
53 dmenu
54 i3status
55 i3lock
56 ];
57 defaultText = literalExpression ''
58 with pkgs; [
59 dmenu
60 i3status
61 i3lock
62 ]
63 '';
64 description = ''
65 Extra packages to be installed system wide.
66 '';
67 };
68 };
69
70 config = mkIf cfg.enable {
71 services.xserver.windowManager.session = [
72 {
73 name = "i3";
74 start = ''
75 ${cfg.extraSessionCommands}
76
77 ${lib.optionalString cfg.updateSessionEnvironment updateSessionEnvironmentScript}
78
79 ${cfg.package}/bin/i3 ${optionalString (cfg.configFile != null) "-c /etc/i3/config"} &
80 waitPID=$!
81 '';
82 }
83 ];
84 environment.systemPackages = [ cfg.package ] ++ cfg.extraPackages;
85 environment.etc."i3/config" = mkIf (cfg.configFile != null) {
86 source = cfg.configFile;
87 };
88 };
89
90 imports = [
91 (mkRemovedOptionModule [
92 "services"
93 "xserver"
94 "windowManager"
95 "i3-gaps"
96 "enable"
97 ] "i3-gaps was merged into i3. Use services.xserver.windowManager.i3.enable instead.")
98 ];
99}