Compiling xmonad

I’m trying to compile xmonad on nixos. I’m using this shell:

let
  pkgs = import <nixpkgs> {};
in
  pkgs.mkShell {
    buildInputs = with pkgs; with pkgs.xorg; [
      libX11 libXinerama libXext libXrandr libXScrnSaver
      ghc cabal-install
      zlib
    ];
  }

Command cabal build in this shell worked when I tried it on arch linux but failed with this error on latest nixos:

Configuring library for JuicyPixels-3.3.5..
Preprocessing library for JuicyPixels-3.3.5..
Building library for JuicyPixels-3.3.5..
[ 1 of 30] Compiling Codec.Picture.InternalHelper ( src/Codec/Picture/InternalHelper.hs, dist/build/Codec/Picture/InternalHelper.o )
[ 2 of 30] Compiling Codec.Picture.Metadata.Exif ( src/Codec/Picture/Metadata/Exif.hs, dist/build/Codec/Picture/Metadata/Exif.o )
[ 3 of 30] Compiling Codec.Picture.Metadata ( src/Codec/Picture/Metadata.hs, dist/build/Codec/Picture/Metadata.o )
[ 4 of 30] Compiling Codec.Picture.Tiff.Internal.Types ( src/Codec/Picture/Tiff/Internal/Types.hs, dist/build/Codec/Picture/Tiff/Internal/Types.o )
[ 5 of 30] Compiling Codec.Picture.Tiff.Internal.Metadata ( src/Codec/Picture/Tiff/Internal/Metadata.hs, dist/build/Codec/Picture/Tiff/Internal/Metadata.o )
[ 6 of 30] Compiling Codec.Picture.Types ( src/Codec/Picture/Types.hs, dist/build/Codec/Picture/Types.o )
<command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory)

Why can’t cabal find libz.so?

Don’t know so much about Haskell and xmonad, but usually you shouldn’t need to write a custom shell.nix for interactive development for any package that is already available in nixpkgs.
Instead you will be dropped in a shell for building a package by going to your nixpkgs checkout and calling:

nix-shell -A xmonad

Edit:
It seems the package is called:

nix-shell -A xmonad-with-packages
2 Likes

I’m not sure what the root of the problem is (though it might be related to the ghc environment files that cabal generates), but I have a shell.nix I’ve been using to compile xmonad on nixos. I enter the nix-shell and run cabal v2-build.

Here’s my shell.nix (Edit: the only significant difference I see is the fact that I’m not listing zlib as a buildInput):

{ nixpkgs ? import <nixpkgs>, compiler ? "ghc861" }:

let
  pkgs = nixpkgs { };

  compilers = {
    ghc861 = (import (builtins.fetchTarball {
      url    = "https://github.com/NixOS/nixpkgs/archive/1f212565d2fcfe2c880e739d4462731a6ec19654.tar.gz";
      sha256 = "1fcrpfj98khlaxygy2vz2lm94xyir29rvv9pw2i7xdb7xymvrwar";
    }) { }).haskell.compiler.ghc861;

    ghc843 = (import (builtins.fetchTarball {
      url    = "https://github.com/NixOS/nixpkgs/archive/32dcb6051a9a2fa687283f4883d3552c3a46c081.tar.gz";
      sha256 = "1dvgk1cvai79yxn9lk9fnzqsqwi236y99ldxky6v999dx33nzygb";
    }) { }).haskell.compiler.ghc843;

    ghc822 = (import (builtins.fetchTarball {
      url    = "https://github.com/NixOS/nixpkgs/archive/8746c77a383f5c76153c7a181f3616d273acfa2a.tar.gz";
      sha256 = "1dvhx9hcij3j94yv102f7bhqy73k50sr3lazn28zzj8yg5lbahar";
    }) { }).haskell.compiler.ghc822;

    ghc802 = (import (builtins.fetchTarball {
      url    = "https://github.com/NixOS/nixpkgs/archive/32dcb6051a9a2fa687283f4883d3552c3a46c081.tar.gz";
      sha256 = "1dvgk1cvai79yxn9lk9fnzqsqwi236y99ldxky6v999dx33nzygb";
    }) { }).haskell.compiler.ghc802;
  };

in with pkgs; mkShell {
  buildInputs = [
    xorg.libX11
    xorg.libXinerama
    xorg.libXext
    xorg.libXrandr
    xorg.libXScrnSaver
    cabal-install
    compilers.${compiler}
  ];

  shellHook = ''
    rm -rf dist dist-newstyle .ghc.environment.*
  '';
}

haskellPackages.xmonad is the base package available through hackage. However, I’m not sure how useful the “unwrapped” version is

There was another thread that asked about a similar problem:

However, in this thread we had no problem with linking to zlib when doing cabal build, but we did have a problem with cabal repl.

In one of the posts in that thread, I listed some of the steps I used to try to debug this problem. You might find this helpful.

If you can’t get this working at all, then going with the nix-shell -A xmonad-with-packages route is probably the easiest workaround.

1 Like