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 ];
56 defaultText = literalExpression ''
57 with pkgs; [
58 dmenu
59 i3status
60 ]
61 '';
62 description = ''
63 Extra packages to be installed system wide.
64 '';
65 };
66 };
67
68 config = mkIf cfg.enable {
69 services.xserver.windowManager.session = [
70 {
71 name = "i3";
72 start = ''
73 ${cfg.extraSessionCommands}
74
75 ${lib.optionalString cfg.updateSessionEnvironment updateSessionEnvironmentScript}
76
77 ${cfg.package}/bin/i3 ${optionalString (cfg.configFile != null) "-c /etc/i3/config"} &
78 waitPID=$!
79 '';
80 }
81 ];
82 programs.i3lock.enable = mkDefault true;
83 environment.systemPackages = [ cfg.package ] ++ cfg.extraPackages;
84 environment.etc."i3/config" = mkIf (cfg.configFile != null) {
85 source = cfg.configFile;
86 };
87 };
88
89 imports = [
90 (mkRemovedOptionModule [
91 "services"
92 "xserver"
93 "windowManager"
94 "i3-gaps"
95 "enable"
96 ] "i3-gaps was merged into i3. Use services.xserver.windowManager.i3.enable instead.")
97 ];
98}