Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMonad on Nix - cannot find xmonad-contrib

I am trying to use nix on ubuntu, with XMonad as my window manager. I have this working well on one host using nixOS, but I have a second device that isn't yet ready for nixOS. nix on top of Ubuntu is mostly working well there, but xmonad cannot find contributory libraries.

The relevant packages are installed:

$ nix-env -q | grep xmonad
xmonad-0.13
xmonad-contrib-0.13
xmonad-extras-0.12.1

But recompiling my xmonad.hs, it cannot find the contrib libs:

$ xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs

xmonad.hs:32:1: error:
Failed to load interface for ‘XMonad.Layout.NoBorders’
Use -v to see a list of the files searched for.

...

Please check the file for errors.

The relevant files are installed:

$ ls /nix/store/*xmonad-contrib*/lib/**/NoBorders*
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.hi

By adding xmonad-contrib to my nixpkgs config.nix, I have gotten these libs added to the ghc package registry:

$ cat ~/.config/nixpkgs/config.nix 
with (import <nixpkgs> {});
{
  packageOverrides = pkgs: with pkgs; {

    myHaskellEnv = pkgs.haskellPackages.ghcWithPackages (haskellPackages: with haskellPackages; [ xmonad-contrib ]);
  };
}
$ nix-env -iA nixpkgs.myHaskellEnv
$ ghc-pkg list | grep xmonad
  xmonad-0.13
  xmonad-contrib-0.13
$

with this, this ghc(i) works well:

$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/ghc ~/.xmonad/xmonad.hs
[1 of 1] Compiling Main             ( /home/martyn/.xmonad/xmonad.hs, /home/martyn/.xmonad/xmonad.o ) [flags changed]
Linking /home/martyn/.xmonad/xmonad ...

But even the version of xmonad in that dir cannot find the libs:

$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs

xmonad.hs:32:1: error:
  Failed to load interface for ‘XMonad.Layout.NoBorders’
  Use -v to see a list of the files searched for.

I can work around this by compiling using the ghc as above, and moving the output by hand to ~/.xmonad/xmonad-x86_64-linux, and running that. But this is a wee bit hacky, and surely shouldn't be necessary?

like image 414
user3416536 Avatar asked Jun 27 '17 10:06

user3416536


1 Answers

A friend solved this for me offline, I reproduce this here for others with the same issue.

Essentially, we need to use xmonad-with-packages, and list the packages, rather than ghc-with-packages.

To achieve this, we provide our own xmonad, referenced from within ~/.nixpkgs/config.nix:

{
  packageOverrides = pkgs_: with pkgs_; {
    xmonad            = import ./xmonad { nixpkgs = pkgs_; };
  };
}

And fill out ~/.nixpkgs/xmonad/default.nix thus:

{ nixpkgs ? import <nixpkgs> {} }:

nixpkgs.xmonad-with-packages.override {
  packages = hPkgs: with hPkgs; [ xmonad-contrib ];
}

This installs an xmonad that knows where to find its libraries, and everything's good!

like image 139
user3416536 Avatar answered Nov 15 '22 04:11

user3416536