Xfce

From NixOS Wiki
Revision as of 21:03, 5 April 2019 by imported>Mucaho (Add section about xmonad)

Xfce is a lightweight desktop environment based on GTK+. It includes a window manager, a file manager, desktop and panel.

Enabling

To use xfce set service.xserver.desktopManager.xfce.enable to true. For example:

/etc/nixos/configuration.nix
{ config, pkgs, callPackage, ... }: {
  ...
  # if you use pulseaudio
  nixpkgs.config.pulseaudio = true;

  services.xserver = {
    enable = true;
    desktopManager = {
      default = "xfce";
      xterm.enable = false;
      xfce.enable = true;
    };
  };
  ...
}

Using as a desktop manager and not a window manager

You can use xfce purely as a desktop manager, leaving window management to another window manager like i3 for example. In this scenario, xfce's role is to answer to media keys, prompt when plugging a new monitor and so on.

Example config:

/etc/nixos/configuration.nix
{ config, pkgs, callPackage, ... }: {
  ...
  services.xserver = {
    enable = true;   
    desktopManager = {
      default = "xfce";
      xterm.enable = false;
      xfce = {
        enable = true;
        noDesktop = true;
        enableXfwm = false;
      };
    };
    windowManager.i3.enable = true;
  };
  ...
}

On first login, make sure to choose the session xfce+i3 in your display manager. If you choose xfce you will end up in xfce without panels nor window manager, which is unusable.

Note that xfce manages your session instead of i3: exiting i3 will blank your screen but not terminate your session. In your i3 config, replace i3-msg exit with xfce4-session-logout.

Usage with xmonad as window manager

One of the possibilities is to use xmonad as a window manager in a Xfce desktop environment. The previously described configuration is extended with the part that configures xmonad:

/etc/nixos/configuration.nix
{ config, pkgs, callPackage, ... }: {
  ...
  services.xserver = {
    enable = true;   
    desktopManager = {
      default = "xfce";
      xterm.enable = false;
      xfce = {
        enable = true;
        noDesktop = true;
        enableXfwm = false;
      };
    };
    windowManager = {
      default = "xmonad";
      xmonad = {
        enable = true;
        enableContribAndExtras = true;
        extraPackages = haskellPackages : [
          haskellPackages.xmonad-contrib
          haskellPackages.xmonad-extras
          haskellPackages.xmonad
        ];
      };
    };
  };
  ...
}

Xmonad's contrib package comes with a config to integrate seamlessly into Xfce, like connecting workspaces to xfce's top panel's preview of workspaces. To enable this config, put the following into the user's xmonad config file:

~/.xmonad/xmonad.hs
  import XMonad
  import XMonad.Config.Xfce
  main = xmonad xfceConfig
         { terminal = "xfce4-terminal"
         , modMask = mod4Mask -- optional: use Win key instead of Alt as modifier key
         }

Since Xfce uses Alt for a lot of keybindings, using the Win key for xmonad hotkeys may be preferred.

Note that, unlike suggested in additional resources, the xmonad packages should not be installed in the environment (neither as systemPackages nor user packages), since that leads to errors when (re)compiling xmonad's config file.

Additional resources:

Haskell Wiki: Installing xmonad on NixOS

Haskell Wiki: Using xmonad in Xfce

Troubleshooting

Pulseaudio

If you use pulse audio, set nixpkgs.config.pulseaudio = true as shown above. Otherwise, you may experience glitches like being able to mute the sound card but not unmute it.