xmonad/xmonad

compilation via stack doesn't use xmonad.hs

Closed this issue · 4 comments

Problem Description

I attempted to build xmonad as described in "Build using Stack" section in README.md.

However, it doesn't pick up the changes from xmonad.hs file - it simply builds the default xmonad from xmonad/Main.hs file.

Steps to Reproduce

$ mkdir -p ~/.config/xmonad/
$ cd ~/.config/xmonad/
$ git clone https://github.com/xmonad/xmonad
$ git clone https://github.com/xmonad/xmonad-contrib
$ cat xmonad.hs
import XMonad
main :: IO ()
main = xmonad def2 -- this is a deliberate typo, meant to showcase that this config isn't picked up.
$ cat stack.yaml
resolver:
  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/25.yaml
packages:
- xmonad
- xmonad-contrib
$ ls
xmonad  xmonad-contrib  stack.yaml  xmonad.hs
$ stack install
...
Copying from
/home/platon/.config/xmonad/.stack-work/install/x86_64-linux-tinfo6/3648a80ef765c2c356e5d3335ec640bb3d1c79a4bce6fe28668efc284f01017a/9.4.8/bin/xmonad to
/home/platon/.local/bin/xmonad.
Copied executables to /home/platon/.local/bin/:
* xmonad

Observe that build didn't fail - as I understand it, that's because it didn't use the expected xmonad.hs file.

Checklist

  • I've read CONTRIBUTING.md

  • I tested my configuration

    • With xmonad commit 4b9ef59
    • With xmonad-contrib commit bfe2f5b3

This is actually working as designed. Xmonad recompiles the xmonad.hs file when you do xmonad --recompile. What you've done so far is you only built the xmonad distribution itself.

Oh, I see how it should work now. Thanks!

One more question, if I may - how should I manage additional dependencies in this setup? For example, my xmonad.hs depends on regex-pcre and lens. I've added them via stack install <dependency-name>, and they got installed and corresponding entries are added to stack.yaml.lock. I've even added them to extra-deps in stack.yaml.

However if I nuke stack files and run a clean install, these dependencies are not present.

You'll probably need to create a cabal project for this, and put the dependencies into your cabal file

I've created a file ~/.config/xmonad/my-dependencies/my-dependencies.cabal with contents:

cabal-version: 3.4
name: my-dependencies
version: 0.0.0
build-type: Simple

library
  build-depends: regex-pcre
               , extra
               , lens
               , relude

and added my-dependencies to packages in stack.yaml.

Seems to work now, thank you!

Perhaps in the future it will make sense to move all the code from my xmonad config into this cabal project, and use xmonad.hs to only call a single exported main method from it.