manually install xmonad with haskell-stack
install the dependencies for xmonad
sudo apt install git libx11-dev libxft-dev libxinerama-dev libxrandr-dev libxss-dev
We’ll use the XDG directory specifications here, meaning our configuration will reside within $XDG_CONFIG_HOME, which is ~/.config on most systems. Let’s create this directory and move to it:
mkdir -p ~/.config/xmonad && cd ~/.config/xmonad
If you already have an xmonad.hs configuration, you can copy it over now. If not, you can use the defaults: create a file called xmonad.hs with the following content:
import XMonad
main :: IO ()
main = xmonad def
Still in ~/.config/xmonad, clone xmonad and xmonad-contrib repositories using git:
git clone https://github.com/xmonad/xmonad
git clone https://github.com/xmonad/xmonad-contrib
This will give you the latest HEAD; if you want you can also check out a tagged release, e.g.:
git clone --branch v0.15 https://github.com/xmonad/xmonad
git clone --branch v0.16 https://github.com/xmonad/xmonad-contrib
(Sources and binaries don’t usually go into ~/.config. In our case, however, it avoids complexities related to Haskell build tools and lets us focus on the important bits of XMonad installation.)
edit your shell config file
vi ~/.zshrc
and add the following code
# set PATH so it includes user local bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
- then source your shell config file
source ~/.zshrc
install stack
sudo apt install haskell-stack
If you install stack via this method, it is advisable that you run stack upgrade after installation. This will make sure that you are on the most recent version of the program, regardless of which version your distribution actually packages.
stack upgrade
Let’s create a stack project. Since we’re already in the correct directory (~/.config/xmonad) with xmonad and xmonad-contrib subdirectories, starting a new stack project is as simple as running stack init.
Stack should now inform you that it will use the relevant stack and cabal files from xmonad and xmonad-contrib to generate its stack.yaml file. At the time of writing, this looks a little bit like this:
- make sure you are in the ~/.config/xmonad
cd ~/.config/xmonad
- run stack init
stack init
- output
Looking for .cabal or package.yaml files to use to init the project. Using cabal packages:
- xmonad-contrib/
- xmonad/
Selecting the best among 19 snapshots…
Matches https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml
Selected resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml Initialising configuration using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml Total number of user packages considered: 2 Writing configuration to file: stack.yaml All done.
If you look into your current directory now, you should see a freshly generated stack.yaml file:
ls
- output
xmonad xmonad-contrib stack.yaml xmonad.hs
The meat of that file (comments start with #, we’ve omitted them here) will look a little bit like
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml
packages:
- xmonad
- xmonad-contrib
With stack.yaml alongside xmonad.hs, xmonad now knows that it needs to use stack ghc instead of just ghc when (re)compiling its configuration. If you want to keep xmonad sources and the stack project elsewhere, but still use xmonad –recompile, symlink your real stack.yaml into the xmonad configuration directory, or use a custom build script.
Installing things is as easy as typing stack install. This will install the correct version of GHC, as well as build all of the required packages (stack build) and then copy the relevant executables (xmonad, in our case) to ~/.local/bin. Make sure to add that directory to your $PATH!
If you’re getting build failures while building the X11 package it may be that you don’t have the required C libraries installed. See above.
stack install
This step varies depending on your distribution and X display manager (if any).
Debian, Ubuntu
etc/X11/xinit/xinitrc runs /etc/X11/Xsession which runs ~.xsession, so you probably want to put exec xmonad there (don’t forget the shebang and chmod).
(Tested with startx, xdm, lightdm.)
By using ~/.xsession, the distro takes care of stuff like dbus, ssh-agent, X resources, etc. If you want a completely manual X session, use ~/.xinitrc instead. Or invoke startx/xinit with an explicit path. create a symbolic to /usr/bin/xmonad
Some newer display managers require an entry in usr/share/xsessions. To use your custom ~.xsession, put these lines to /usr/share/xsessions/xmonad.desktop
you can create a symlink from ~/.local/bin/xmonad to /usr/bin/xmonad
if you dont create a symbolic link to /usr/bin/xmonad your graphical login manager wont boot into xmonad and will just return to the login screen
sudo ln -s ~/.local/bin/xmonad /usr/bin
you can then create a desktop file like this
[Desktop Entry]
Name=XMonad
Comment=Lightweight tiling window manager
Exec=xmonad
Type=XSession
and then copy the xmonad.desktop file to /usr/share/xsessions
sudo cp xmonad.desktop /usr/share/xsessions
you can also use the xmonad-ARCH executable that xmonad –recompile generates instead of xmonad in your startup see notes at the end of document for more info
in which case you dont need to create a symlink
- and replace username with your username
[Desktop Entry]
Name=XMonad
Comment=Lightweight tiling window manager
Exec=/home/username/.cache/xmonad/xmonad-x86_64-linux
Type=XSession
and then copy the xmonad.desktop file to /usr/share/xsessions
sudo cp xmonad.desktop /usr/share/xsessions
if you already have xmonad installed with apt then switch to another desktop like gnome which is installed by default on ubuntu, or if you dont have another desktop installed, install something like dwm
after you have switched to another desktop like gnome then you can uninstall xmonad installed with apt
sudo apt remove xmonad libghc-xmonad-contrib-dev
# feh set wallpaper
feh --no-fehbg --bg-center --image-bg '#353535' '/home/djwilcox/.config/wallpaper/freebsd.png'
# set the cursor form xmonad
xsetroot -cursor_name left_ptr
# start ssh-agent and window mamager
exec ssh-agent /home/djwilcox/.cache/xmonad/xmonad-x86_64-linux
If you need to customize what happens during xmonad –recompile (bound to M-q by default), perhaps because your xmonad configuration is a whole separate Haskell package, you need to create a so-called build file. This is quite literally just a shell script called build in your xmonad directory (which is ~/.config/xmonad for us) that tells xmonad how it should build its executable.
A good starting point (this is essentially what xmonad would do without a build file, with the exception that we are invoking stack ghc instead of plain ghc) would be
#!/bin/sh
exec stack ghc -- \
--make xmonad.hs \
-i \
-ilib \
-fforce-recomp \
-main-is main \
-v0 \
-o "$1"
make the build script executable
chmod +x build
By default, xmonad always recompiles itself when a build script is used (because the build script could contain arbitrary code, so a simple check whether the xmonad.hs file changed is not enough). If you find that too annoying, then you can use the xmonad-ARCH executable that xmonad –recompile generates instead of xmonad in your startup. For example, instead of writing
exec xmonad
in your ~/.xinitrc, you would write
exec /home/username/.cache/xmonad/xmonad-x86_64-linux
replacing username with your username
The ~/.cache prefix is the $XDG_CACHE_HOME directory. Note that if your xmonad configuration resides within ~/.xmonad, then the executable will also be within that directory and not in $XDG_CACHE_HOME.