Jump to content

I3: Difference between revisions

From NixOS Wiki
adding examples for i3status configuration in home-manager
Tejing (talk | contribs)
cleaned up and separated the example code for installing with home-manager into 2 properly-marked file boxes
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Lowercase_title}}
{{DISPLAYTITLE:i3}}
{{Expansion|there are a lot more [https://search.nixos.org/options/?query=i3 options]}}
{{Expansion|there are a lot more [https://search.nixos.org/options/?query=i3 options]}}
[https://i3wm.org/ i3] is a tiling window manager for X.
[https://i3wm.org/ i3] is a tiling window manager for [[Xorg|X Window System]].


== Enabling ==
== Enabling ==


To use i3 set <code>services.xserver.windowManager.i3.enable</code> to <code>true</code>. For example:
To use i3 set {{nixos:option|services.xserver.windowManager.i3.enable}} to <code>true</code>. For example:
{{file|/etc/nixos/configuration.nix|nix|
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
<nowiki>
Line 11: Line 11:


{
{
  ...
  environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw
   ...
   ...
   services.xserver = {
   services.xserver = {
     enable = true;
     enable = true;
    desktopManager = {
      xterm.enable = false;
    };
 
    displayManager = {
        defaultSession = "none+i3";
    };


     windowManager.i3 = {
     windowManager.i3 = {
Line 31: Line 21:
         i3status # gives you the default i3 status bar
         i3status # gives you the default i3 status bar
         i3lock #default i3 screen locker
         i3lock #default i3 screen locker
        i3blocks #if you are planning on using i3blocks over i3status
     ];
     ];
     };
     };
Line 39: Line 28:
</nowiki>
</nowiki>
}}
}}
By default, the path to the i3 configuration file is <code>$HOME/.i3/config</code>. For a full list of i3 options, refer to the {{nixos:option|services.xserver.windowManager.i3}} module options.
{{Evaluate}}
{{Evaluate}}


=== Using home-manager ===
=== Using home-manager ===
{{file|~/.config/nixpkg/home.nix|nix|
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
<nowiki>
#in configuration.nix
services.xserver = {
services.xserver = {
   enable = true;
   enable = true;
   windowManager.i3.enable = true;
   windowManager.i3.enable = true;
  };
};
  services.displayManager = {
services.displayManager.defaultSession = "none+i3";
    defaultSession = "none+i3";
</nowiki>
  };
}}


#in home.nix
{{file|home.nix|nix|
  xsession.windowManager.i3 = {
<nowiki>
    enable = true;
xsession.windowManager.i3 = {
    package = pkgs.i3-gaps;
  enable = true;
    config = {
  config = {
      modifier = "Mod4";
    modifier = "Mod4";
      gaps = {
     # See home-manager documentation for everything you can add here.
        inner = 10;
        outer = 5;
      };
     };
   };
   };
};
</nowiki>
</nowiki>
}}
}}


See also: [https://github.com/srid/nix-config/blob/705a70c094da53aa50cf560179b973529617eb31/nix/home/i3.nix https://github.com/srid/nix-config/blob/master/nix/home/i3.nix]
See also: [https://github.com/srid/nix-config/blob/705a70c094da53aa50cf560179b973529617eb31/nix/home/i3.nix srid/nix-config/nix/home/i3.nix]


=== With a desktop manager ===
=== With a desktop manager ===
Line 75: Line 63:
[[Xfce#Using_as_a_desktop_manager_and_not_a_window_manager]].
[[Xfce#Using_as_a_desktop_manager_and_not_a_window_manager]].


===I3-gaps fork===
== Common issues ==


To use i3-gaps fork, the following line should be added to the configuration.nix:
=== i3lock doesn't recognize my password ===
As of nixos 25.05, i3lock is no longer automatically configured to be able to use PAM to check passwords. If you installed i3 through nixos options, this is handled for you, but if you installed it elsewhere, such as through home-manager, then at minimum, you need to set:


<syntaxhighlight lang="nix" inline>services.xserver.windowManager.i3.package = pkgs.i3-gaps;</syntaxhighlight>
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
security.pam.services.i3lock.enable = true;
</nowiki>
}}


== Tips & tricks ==
== Tips & tricks ==
===i3blocks===
After installing and enabling i3blocks, you may notice that i3block won't work. why?


It seems that i3blocks read it's contents from a hardcoded path in /etc by default.
=== i3blocks ===
Since in nixos, this path look something like:
 
After installing and enabling i3blocks, you may find that i3block does not work. This issue occurs because i3blocks reads its contents from a hardcoded path in <code>/etc</code> by default.
 
Since in nixos however, these contents are located within the Nix store at a path similar to:


{{file|Path of i3blocks in nixos|nix|
{{file|Path of i3blocks in nixos|nix|
Line 94: Line 88:
}}
}}


And it can't find this path, so we have to create a link to this path by adding this line to configuration.nix file:
Since i3blocks cannot locate this path, you have to create a link to this path by adding this line to configuration.nix file:
{{file|/etc/nixos/configuration.nix|nix|
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
<nowiki>
Line 101: Line 95:
}}
}}


Finally, your block may looks like:
After rebuilding the system, you may configure your block like the following:
{{file|~/.config/i3/i3blocks.conf|nix|
{{file|~/.config/i3/i3blocks.conf|nix|
<nowiki>
<nowiki>
Line 112: Line 106:
}}
}}


===DConf===
=== DConf ===
 
If your settings aren't being saved for some applications (gtk3 applications, firefox), like the size of file selection windows, or the size of the save dialog, you will need to enable dconf:
If your settings aren't being saved for some applications (gtk3 applications, firefox), like the size of file selection windows, or the size of the save dialog, you will need to enable dconf:


Line 121: Line 116:
}}
}}


===Lxappearance===
=== Lxappearance ===
 
To change the icon and themes you can install lxappearance:
To change the icon and themes you can install lxappearance:


Line 135: Line 131:


=== Solve inconsistency between gtk2 and gtk3 themes ===
=== Solve inconsistency between gtk2 and gtk3 themes ===
If enabling '''dconf''' or installing '''Lxappearance''' but still see inconsistency between themes, you have to manually edit their configurations. In fact, It is possible to install some gtk3 themes but when you start another gtk2 application, your theme not effected properly. It's because there is no .gtkrc-2.0 in your home directory. First create it and paste these lines to it:
If enabling '''dconf''' or installing '''Lxappearance''' but still see inconsistency between themes, you have to manually edit their configurations. In fact, It is possible to install some gtk3 themes but when you start another gtk2 application, your theme not effected properly. It's because there is no .gtkrc-2.0 in your home directory. First create it and paste these lines to it:


Line 161: Line 158:


=== Wallpaper ===
=== Wallpaper ===
If <code>~/.background-image</code> exists then it will be displayed as a wallpaper. Options <code>services.xserver.desktopManager.wallpaper.combineScreens</code> and <code>.mode</code> control exactly how it is displayed.
If <code>~/.background-image</code> exists then it will be displayed as a wallpaper. Options <code>services.xserver.desktopManager.wallpaper.combineScreens</code> and <code>.mode</code> control exactly how it is displayed.


[[Category:Window managers]]
=== i3status with home-manager ===
[[Category:Applications]]
 
Same as in i3status-rust. Notice: home-manager will not override your existing config, i.e. if the file/folder  <code>~/.config/i3status/config</code>  is present on your system, there won't be any changes after rebuilding.
 
External resources that can help you with your setup: [https://home-manager-options.extranix.com/?query=xsession.windowManager.i3.config https://home-manager-options.extranix.com/?query=xsession.windowManager.i3.config]
 
==== To enable i3status in home-manager and change some basic options: ====
 
{{file|home.nix|nix|
<nowiki>
programs.i3status = {
 
  enable = true;
 
  general = {
    colors = true;
    color_good = "#98971a";
    color_bad  = "#9d0006";
    interval = 1;
  };
};
</nowiki>
}}
 
==== Adding various modules: ====
 
{{file|home.nix|nix|
<nowiki>
programs.i3status = {
  ...
  modules = {
 
    "disk /" = {
      enable = true;
      position = 1;
      settings = {
        format = "FREE: %free";
      };
    }; 
 
    # Current wireless connection (ethernet is pretty much the same)
    "wireless <replace-with-interface-name>" = {
      enable = true;
      position = 2;
      settings = {
        format_up = "W: (%quality at %essid) %ip";
        format_down = "W: down";
      };
    };
 
    # Battery status
    "battery 0" = {
      enable = true;
      position = 4;
      settings = {
        format = "BAT: %status %percentage %remaining %emptytime";
        format_down = "No battery";
        status_chr = "CHR";
        status_bat = "";
        status_unk = "?";
        status_full = "FULL";
        path = "/sys/class/power_supply/BAT1/uevent";
        low_threshold = 10;
      };
    };
  };
};
</nowiki>
}}
 
===== Disabling default i3status modules =====
 
After setting up i3status, you may notice it shows two eth- and wifi's. To disable <code>ethernet _first_</code> and <code>wireless _first_</code>, add the following:
 
{{file|home.nix|nix|
<nowiki>
programs.i3status.modules = {
  "wireless _first_" = {
    enable = false;
  };
 
  "ethernet _first_" = {
    enable = false;
  };
};
</nowiki>
}}


=== i3status-rust with home-manager ===
=== i3status-rust with home-manager ===
Line 170: Line 253:
i3status-rust can be configured through home-manager, but that configuration does not autoamatically update i3 to invoke i3status-rust. Instead <code>xsession.windowManager.i3.config.bars</code> needs to be updated to reference i3status-rust and the config files that the home-manager config produces. Consider the following setup:
i3status-rust can be configured through home-manager, but that configuration does not autoamatically update i3 to invoke i3status-rust. Instead <code>xsession.windowManager.i3.config.bars</code> needs to be updated to reference i3status-rust and the config files that the home-manager config produces. Consider the following setup:


{{file|~/.config/nixpkg/home.nix|nix|
{{file|home.nix|nix|
<nowiki>
<nowiki>
   xsession.windowManager.i3 = {
   xsession.windowManager.i3 = {
Line 201: Line 284:
</nowiki>
</nowiki>
}}
}}
=== i3status with home-manager ===


Same as in i3status-rust. Notice: home-manager will not override your existing config, i.e. if the file/folder  <code>~/.config/i3status/config</code>  is present on your system, there won't be any changes after rebuilding.
[[Category:Window managers]]
 
[[Category:Applications]]
External resources that can help you with your setup: https://mynixos.com/home-manager/options/xsession.windowManager.i3.config
[[Category:Desktop]]
 
===== To enable i3status in home-manager and change some basic options: =====
<syntaxhighlight lang="nix" line="1" start="1">
programs.i3status = {
 
  enable = true;
 
  general = {
    colors = true;
    color_good = "#98971a";
    color_bad  = "#9d0006";
    interval = 1;
  };
};
</syntaxhighlight>
 
===== Adding various modules: =====
<syntaxhighlight lang="nix" line="1" start="1">
modules = {
 
  "disk /" = {
    enable = true;
    position = 1;
    settings = {
      format = "FREE: %free";
    };
  /* Put some of the modules below after this comment */
 
  };
</syntaxhighlight>
 
===== Current wireless connection (ethernet is pretty much the same) =====
<syntaxhighlight lang="nix" line="1" start="1">
"wireless <replace-with-interface-name>" = {
  enable = true;
  position = 2;
  settings = {
    format_up = "W: (%quality at %essid) %ip";
    format_down = "W: down";
  };
};
</syntaxhighlight>
 
===== Battery status =====
<syntaxhighlight lang="nix" line="1" start="1">
"battery 0" = {
  enable = true;
  position = 4;
  settings = {
    format = "BAT: %status %percentage %remaining %emptytime";
    format_down = "No battery";
    status_chr = "CHR";
    status_bat = "";
    status_unk = "?";
    status_full = "FULL";
    path = "/sys/class/power_supply/BAT1/uevent";
    low_threshold = 10;
  };
};
 
</syntaxhighlight>
 
=== Disabling default i3status modules: ===
After setting up my config, i3status showed two eth- and wifi's. To disable <code>ethernet _first_</code>  and <code>wireless _first_</code>  just add:<syntaxhighlight lang="nix" line="1" start="1">
"wireless _first_" = {
  enable = false;
};
 
"ethernet _first_" = {
  enable = false;
};
</syntaxhighlight>

Latest revision as of 18:32, 24 June 2025

☶︎
This article or section needs to be expanded. Further information may be found in the related discussion page. Please consult the pedia article metapage for guidelines on contributing.

i3 is a tiling window manager for X Window System.

Enabling

To use i3 set services.xserver.windowManager.i3.enable to true. For example:

❄︎ /etc/nixos/configuration.nix
{ config, pkgs, callPackage, ... }: 

{
  ...
  services.xserver = {
    enable = true;

    windowManager.i3 = {
      enable = true;
      extraPackages = with pkgs; [
        dmenu #application launcher most people use
        i3status # gives you the default i3 status bar
        i3lock #default i3 screen locker
     ];
    };
  };
  ...
}

By default, the path to the i3 configuration file is $HOME/.i3/config. For a full list of i3 options, refer to the services.xserver.windowManager.i3 module options.

🟆︎
Tip: In order to affect your NixOS system by your nix-language-specific changes you must first evaluate it:
$ nixos-rebuild switch --sudo


Using home-manager

❄︎ /etc/nixos/configuration.nix
services.xserver = {
  enable = true;
  windowManager.i3.enable = true;
};
services.displayManager.defaultSession = "none+i3";
❄︎ home.nix
xsession.windowManager.i3 = {
  enable = true;
  config = {
    modifier = "Mod4";
    # See home-manager documentation for everything you can add here.
  };
};

See also: srid/nix-config/nix/home/i3.nix

With a desktop manager

i3 is a window manager and does not provide "cosmetic" services like managing multiple monitor configuration or media keys. This is what is usually delegated to a desktop manager. To use xfce as a desktop manager on top of i3, see Xfce#Using_as_a_desktop_manager_and_not_a_window_manager.

Common issues

i3lock doesn't recognize my password

As of nixos 25.05, i3lock is no longer automatically configured to be able to use PAM to check passwords. If you installed i3 through nixos options, this is handled for you, but if you installed it elsewhere, such as through home-manager, then at minimum, you need to set:

❄︎ /etc/nixos/configuration.nix
security.pam.services.i3lock.enable = true;

Tips & tricks

i3blocks

After installing and enabling i3blocks, you may find that i3block does not work. This issue occurs because i3blocks reads its contents from a hardcoded path in /etc by default.

Since in nixos however, these contents are located within the Nix store at a path similar to:

❄︎ Path of i3blocks in nixos
  /nix/store/k78nc1bplhy4yjblqwlc14h6rdisix3w-i3blocks-1.4/libexec/i3blocks/[BLOCKS]

Since i3blocks cannot locate this path, you have to create a link to this path by adding this line to configuration.nix file:

❄︎ /etc/nixos/configuration.nix
  environment.pathsToLink = [ "/libexec" ];

After rebuilding the system, you may configure your block like the following:

❄︎ ~/.config/i3/i3blocks.conf
[battery]                                                                                                        
label=                                                                                                         
command=/run/current-system/sw/libexec/i3blocks/battery                                                          
interval=10                                                                                                      
instance=1

DConf

If your settings aren't being saved for some applications (gtk3 applications, firefox), like the size of file selection windows, or the size of the save dialog, you will need to enable dconf:

❄︎ /etc/nixos/configuration.nix
  programs.dconf.enable = true;

Lxappearance

To change the icon and themes you can install lxappearance:

❄︎ /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
    #---- i3
    lxappearance
    ...
]

Solve inconsistency between gtk2 and gtk3 themes

If enabling dconf or installing Lxappearance but still see inconsistency between themes, you have to manually edit their configurations. In fact, It is possible to install some gtk3 themes but when you start another gtk2 application, your theme not effected properly. It's because there is no .gtkrc-2.0 in your home directory. First create it and paste these lines to it:

❄︎ ~/.gtkrc-2.0
gtk-theme-name="Sierra-compact-light"
gtk-icon-theme-name="ePapirus"
gtk-font-name="Ubuntu 11"
gtk-cursor-theme-name="Deepin"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintfull"
gtk-xft-rgba="rgb"
gtk-modules="gail:atk-bridge"

Change the options based on your installed themes and icon packs.

Wallpaper

If ~/.background-image exists then it will be displayed as a wallpaper. Options services.xserver.desktopManager.wallpaper.combineScreens and .mode control exactly how it is displayed.

i3status with home-manager

Same as in i3status-rust. Notice: home-manager will not override your existing config, i.e. if the file/folder ~/.config/i3status/config is present on your system, there won't be any changes after rebuilding.

External resources that can help you with your setup: https://home-manager-options.extranix.com/?query=xsession.windowManager.i3.config

To enable i3status in home-manager and change some basic options:

❄︎ home.nix
programs.i3status = {

  enable = true;

  general = {
    colors = true;
    color_good = "#98971a";
    color_bad  = "#9d0006";
    interval = 1;
  };
};

Adding various modules:

❄︎ home.nix
programs.i3status = {
  ...
  modules = {

    "disk /" = {
       enable = true;
       position = 1;
       settings = {
         format = "FREE: %free";
       };
    };  

    # Current wireless connection (ethernet is pretty much the same)
    "wireless &lt;replace-with-interface-name&gt;" = {
      enable = true;
      position = 2;
      settings = {
        format_up = "W: (%quality at %essid) %ip";
        format_down = "W: down";
      };
    }; 

    # Battery status
    "battery 0" = {
      enable = true;
      position = 4;
      settings = {
        format = "BAT: %status %percentage %remaining %emptytime";
        format_down = "No battery";
        status_chr = "CHR";
        status_bat = "";
        status_unk = "?";
        status_full = "FULL";
        path = "/sys/class/power_supply/BAT1/uevent";
        low_threshold = 10;
      };
    };
  };
};
Disabling default i3status modules

After setting up i3status, you may notice it shows two eth- and wifi's. To disable ethernet _first_ and wireless _first_, add the following:

❄︎ home.nix
programs.i3status.modules = {
  "wireless _first_" = {
    enable = false;
  };

  "ethernet _first_" = {
    enable = false;
  };
};

i3status-rust with home-manager

i3status-rust can be configured through home-manager, but that configuration does not autoamatically update i3 to invoke i3status-rust. Instead xsession.windowManager.i3.config.bars needs to be updated to reference i3status-rust and the config files that the home-manager config produces. Consider the following setup:

❄︎ home.nix
  xsession.windowManager.i3 = {
    enable = true;
    config = {
      bars = [
        {
          position = "top";
          statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs ~/.config/i3status-rust/config-top.toml";
        }
      ];
    };
  };

  programs.i3status-rust = {
    enable = true;
    bars = {
      top = {
        blocks = [
         {
           block = "time";
           interval = 60;
           format = "%a %d/%m %k:%M %p";
         }
       ];
      };
    };
  };
}