Chris Stryczynski

Software Developer / Consultant

How to install a custom XMonad as a nix package in Nixos

Posted on: 09/06/2019

It’s a bit of a mission to get XMonad installed on Nixos - because XMonad has some quirks as to how it restarts / recompiles your config etc.

Currently (after learning me some Nix):

Make a buildable nix package with:

default.nix

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" }:
nixpkgs.pkgs.haskell.packages.${compiler}.callPackage ./xmonad.nix { }

(I gott the below using cabal2nix - cabal2nix . > xmonad.nix). xmonad.nix

{ mkDerivation, base, containers, deepseq, hpack, lens, mtl
, pretty-simple, process, stdenv, string-conversions, time, X11
, xmonad, xmonad-contrib
}:
mkDerivation {
  pname = "my-xmonad";
  version = "0.2.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  libraryToolDepends = [ hpack ];
  executableHaskellDepends = [
    base containers deepseq lens mtl pretty-simple process
    string-conversions time X11 xmonad xmonad-contrib
  ];
  preConfigure = "hpack";
  license = stdenv.lib.licenses.gpl2;
}

You should then be able to nix-build and have it build successfully.

In my nixos configuration I just define/reference the package as:

myxmonad = pkgs.callPackage /home/chris/fromLaptopt/usbflash/Haskell/MyXmonad/default.nix {};

Previously:

I had great luck with following https://functor.tokyo/blog/2018-02-16-setup-xmonad-on-nixos, though I had to do some changes I think around stack / how my project is built. Here is the adapted build file I used (I think most of it is isn’t used though):

#!/usr/bin/env bash
set -e

#
# Set config values used for building and running xmonad and taffybar.

# The directory in $HOME with all the XMonad stuff.
#export XMONAD_DIR="/etc/nixos/xmonad"
export XMONAD_DIR="/home/chris/fromLaptopt/usbflash/Haskell/MyXmonad"

# A directory to use to install the taffybar and xmonad binaries.
export XMONAD_LOCAL_BIN_PATH="${XMONAD_DIR}/local-bin"



# Exit with an error message.
function die ()
{
	local msg="${1}"
	echo "${msg}" >&2
	exit 1
}

# Make sure we are in the ~/.xmonad/ directory, so that relative paths can
# be used in the following variables.
cd "$XMONAD_DIR"

# Input file paths
build_file_path="./build"
xmonad_build_vars_file_path="./xmonad_build_vars.sh"
xmonad_hs_file_path="./lib/xmonad.hs"

# Source the xmonad build variables, like the LTS version to use.

if [ "$?" -ne 0 ]
then
	die "Failed to source the xmonad_build_vars.sh file."
fi

# Create the binary directory for things like taffybar and gtk2hs build tools.
mkdir -p "${XMONAD_LOCAL_BIN_PATH}"

xmonadExe="${XMONAD_DIR}/xmonad-x86_64-linux"

# Figure out what the binary name is for the output xmonad binary.
xmonadBin="${1}"
if [ "${xmonadBin}" == "" ]
then
	xmonadBin="./xmonad-x86_64-linux"
fi

## Build my xmonad executable it doesn't exist, or if the settings files are
## newer than the existing executable.
#if [[ ( ! -x "${xmonadBin}" ) || ( "${xmonad_hs_file_path}" -nt "${xmonadBin}" ) ]]
#then
#	# delete old xmonad output files
#	rm -rf "${XMONAD_DIR}/xmonad.hi" "${XMONAD_DIR}/xmonad.o"
#  cd "$XMONAD_LOCAL_BIN_PATH"
#  stack build --nix --copy-bins
#
#fi
cd "$XMONAD_LOCAL_BIN_PATH"
stack build --nix --copy-bins

cp -uf "$xmonadExe" ~/.xmonad/
Comments

No comments, yet!

Submit a comment