# Jerry-rigging GHCup on NixOS?

**URL:** <https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295>\
**Category:** Uncategorized\
**Created:** [August 13, 2023, 7:50am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295 "2023-08-13T07:50:14Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liamzy](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Liamzy](https://discourse.haskell.org/u/Liamzy)\
**Post date:** [August 13, 2023, 7:50am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/1 "2023-08-13T07:50:14Z")

</div>

I’m sort of attached to the GHCup workflow, especially if I go to NixOS, simply because Haskell is niche, Nix / NixOS is niche, and crossing two niche technologies together gets me easily into the space where I have no community support at all (incidentally, IHP doesn’t run trivially on NixOS, despite being married to Nix).

From what I’ve heard, maerwald isn’t planning on supporting NixOS with GHCup at the moment, especially given NixOS’s hostility to outside toolchains (pip doesn’t seem to work either), but does anyone have experience in forcing NixOS to support GHCup? I’m now running an entertaining triboot system of NixOS - Arch - Win10 (with Debian WSL2 underneath to boot), so it’s not such a big deal, but it’d be fun to have access to the GHCup-based workflow on NixOS.

---

<div class="post-metadata">

**Author:** ![hellwolf](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hellwolf/32/3020_2.png) [@hellwolf](https://discourse.haskell.org/u/hellwolf)\
**Post date:** [August 13, 2023, 7:58am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/2 "2023-08-13T07:58:00Z")

</div>

If you took all the nixpills (including flakes), I would argue it’s actually much easier to setup Haskell tooling consistently and reproducibly using Nixpkgs. NixOS is not necessary relevant in this context. I use NixOS mostly on laptops, and I have an old server using Fedora+nixpkgs.

I still recommend people using ghcup unless I sense they might be interested in the pills too.

---

<div class="post-metadata">

**Author:** ![hellwolf](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hellwolf/32/3020_2.png) [@hellwolf](https://discourse.haskell.org/u/hellwolf)\
**Post date:** [August 13, 2023, 8:03am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/3 "2023-08-13T08:03:34Z")

</div>

But I do see that it might be difficult to quickly get started because there is a lack of single way of doing it, and hence hard to get started if one’s Nix Fu is not there yet.

Is anyone aware of a good writeup on this subject already? I might be able to provide one otherwise.

---

<div class="post-metadata">

**Author:** ![Liamzy](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Liamzy](https://discourse.haskell.org/u/Liamzy)\
**Post date:** [August 13, 2023, 8:52am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/4 "2023-08-13T08:52:04Z")

</div>

Yeah, perhaps I’m just too attached to maerwald’s work, because Nix is relatively rare and NixOps is actually a specific skill that can lead to lucrative positions.

It’s probably why I’m attached to Windows Haskell, even though Haskell on Windows is mediocre at best, since Windows is ubiquitous and being able to get Windows Haskell to work and be productive helps in pushing for acceptance of Haskell.

* * *

In my case, I love NixOS (it’s literally the most newbie friendly Linux provided you aren’t afraid of screwing around with .nix config files), I love Haskell, I love GHCup. I’m typing this on an Arch distro just to keep my GHCup, but I’ll probably figure out how to jerry-rig GHCup to sort of work.

---

<div class="post-metadata">

**Author:** ![angerman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/angerman/32/892_2.png) [@angerman](https://discourse.haskell.org/u/angerman)\
**Post date:** [August 13, 2023, 9:19am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/5 "2023-08-13T09:19:33Z")

</div>

Maybe you can outline what workflow you want to use? The fact of reliably installing binary distributions on nixOS might be a bit tricky.

Maybe the workflow you are looking for actually exists already?

Note that dealing with native dependencies on nixOS is quite different to how other more stateful/mutable distributions work.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [August 13, 2023, 9:23am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/6 "2023-08-13T09:23:57Z")

</div>

I’ve also been thinking about this. The workflow I would want is just the exact same as GHCup on other platforms: always downloading binaries (unless explicitly running `ghcup compile ...`) and having GHC (and HLS, cabal, stack) versions decoupled from nixpkgs.

I’ve briefly discussed this with @bgamari what it would take to fully support GHCup on NixOS and we came to the conclusion that it would not be an easy thing to do. Ben suggested that perhaps [GitHub - mpickering/ghc-artefact-nix: Create environments with GHC HEAD artefacts](https://github.com/mpickering/ghc-artefact-nix/) could be a way to tackle it.

Currently, I mostly use a command like this to get my GHC and HLS:

```haskell
nix-shell -p haskell.compiler.ghc945 -p haskell.packages.ghc945.haskell-language-server

```

It is decent. Sometimes to get the very latest GHC versions I have to use the unstable channel like this:

```haskell
nix-shell -I nixpkgs=channel:nixos-unstable -p haskell.compiler.ghc962 -p haskell.packages.ghc962.haskell-language-server

```

Unfortunately, for some GHC versions (even on the stable channel) it compiles HLS from source which takes a very long time.

---

<div class="post-metadata">

**Author:** ![hellwolf](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hellwolf/32/3020_2.png) [@hellwolf](https://discourse.haskell.org/u/hellwolf)\
**Post date:** [August 13, 2023, 9:33am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/7 "2023-08-13T09:33:51Z")

</div>

> [@jaror](#):
>
> Unfortunately, for some GHC versions (even on the stable channel) it compiles HLS from source which takes a very long time.

This indeed can be a pain point.

I have thought having a pinned nixpkgs branch maintained by someone, where its caching can be ensured, so that no one would need to recompile them for recent versions of two latest major release GHCs. But perhaps the cost can be an issue for caching things for the community.

---

<div class="post-metadata">

**Author:** ![angerman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/angerman/32/892_2.png) [@angerman](https://discourse.haskell.org/u/angerman)\
**Post date:** [August 14, 2023, 1:52am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/8 "2023-08-14T01:52:10Z")

</div>

We have built something somewhat related with our [devx shell](https://github.com/input-output-hk/devx). It used [haskell.nix](https://github.com/input-output-hk/haskell.nix) to get the compilers, cabal, hls (and some other tools); and is cached on [cache.zw3rk.com](http://cache.zw3rk.com).

You can use them with

```haskell
nix develop github:input-output-hk/devx#ghc8107 --no-write-lock-file --refresh

```

which provide a shell with ghc, cabal, hls, hlint, …

There is also a [guide](https://github.com/input-output-hk/devx/blob/main/docs/direnv.md) on how to use it with direnv, and make it work with VSCode, emacs, and vim.

There is also a [note](https://github.com/input-output-hk/devx#vscode-devcontainer--github-codespace-support) on getting DevContainer/CodeSpaces to work.

We’ve also got a corresponding speed-optimised [GitHub Action](https://github.com/input-output-hk/actions/tree/latest/devx), which we [use in ci](https://github.com/input-output-hk/devx/blob/0e3aa4ae96f708c6f5a68257d10d4d09de3efca4/.github/workflows/build-and-test.yml#L41-L48) to test the various combinations we have to build the [hello](https://hackage.haskell.org/package/hello) package.

As this builds on the logic in haskell.nix, we can do (limited) cross compilation (e.g. to windows), and static targets. However I will note that there may still be residual bugs.

Maybe this is helpful to someone.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 12, 2023, 1:34pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/9 "2023-11-12T13:34:32Z")

</div>

That devx shell works great. A few observations:

- I was able to install GHC 9.8.1 with HLS support using only binaries in less than 2 minutes or so. I haven’t been able to do that yet using any other approach.

- I had to add some lines to my `configuration.nix`:

- It seems to download a whole new OS including packages like `git`, `gcc`, and even `systemd`. That seems a bit overkill.

- It also installs an isolated cabal and I needed to do `cabal update` first.

- I don’t know how to add additional system dependencies. For example what if I want to use [sbv](https://hackage.haskell.org/package/sbv) and need Z3 installed? Or perhaps more interesting, what if there really is a C dependency like gi-gtk?

- The cabal version seems to be 3.10.1.0 currently, while I had hoped to get 3.10.2.0 (or maybe it doesn’t include cabal and that is just the version I already had installed?).

- What I really want is to install a few common versions of GHC and corresponding HLS globally such that I can use `with-compiler: ...` in `cabal.project` files to have cabal automatically pick up the right compiler version without me having to bother with `direnv` for most packages.

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 12, 2023, 3:03pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/10 "2023-11-12T15:03:40Z")

</div>

> [@Liamzy](#):
>
> I’m sort of attached to the GHCup workflow

I’m guessing it’s actually the cli interface?

I believe you could somehow build an entirely different installation logic behind the same cli interface.

It will lose some properties like simplicity of where files are placed, maybe also different space requirements. But you’ll be able to get a different configuration experience.

---

<div class="post-metadata">

**Author:** ![chreekat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/chreekat/32/2669_2.png) [@chreekat](https://discourse.haskell.org/u/chreekat)\
**Post date:** [November 15, 2023, 7:50am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/11 "2023-11-15T07:50:27Z")

</div>

> [@Liamzy](#):
>
> especially given NixOS’s hostility to outside toolchains

I’d prefer the word “incompatibility” to “hostility” — toolchains are used in Nixpkgs wherever they don’t destroy the value Nix brings.

That said, Nix and NixOs are definitely hard to figure out and aren’t compatible with every workflow.

What I’ve recently learned is _embrace flakes_ — if you’re gonna have a bad time, you might as well have the best bad time available. I’ve gotten as far as creating a template with all the best practices I know for packaging Cabal packages on Nix. Now I run

```
nix flake init -t github:chreekat/nix-templates#haskell-generic

```

whenever I want to instantly get going. Using a different compiler is as easy as changing which branch of NixOS I pull from, assuming I’m within a reasonable range for production use. Once the flake.nix is initialized, it’s a one line change.

> **[GitHub - chreekat/nix-templates](https://github.com/chreekat/nix-templates)**
>
> Contribute to chreekat/nix-templates development by creating an account on GitHub.

If the compiler I want isn’t on a NixOS release, then this doesn’t work. Working on the bleeding edge is one of the use cases I don’t use NixOS for, nor indeed any distro. But I do still use `nix-shell` for the dev environment when skating on the bleeding edge.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 15, 2023, 9:26am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/12 "2023-11-15T09:26:18Z")

</div>

> [@chreekat](#):
>
> If the compiler I want isn’t on a NixOS release

For me it is much more about HLS and whether or not it is cached. Building it from source cost me more than half an hour if I remember it right, so I’d really like to avoid that. And that is much more common, for example the HLS for GHC 9.6.3 is not in the (nixpkgs/hydra) cache let alone the one for GHC 9.8.1.

---

<div class="post-metadata">

**Author:** ![angerman](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/angerman/32/892_2.png) [@angerman](https://discourse.haskell.org/u/angerman)\
**Post date:** [November 15, 2023, 10:33am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/13 "2023-11-15T10:33:43Z")

</div>

@jaror we are trying to address this. I hope to have some good answers to the points you raised. The biggest issue with haskell.nix (and thus devx) we run into is that adding new compilers and support all the targets we do, is often _a lot_ of work. Just adding 9.4.8 has been quite some work :-/

I think for most items we can probably try to make them easier. For globally installed GHCs though I don’t see this working easily. That’s something that GHCup is much better at.

Adding additional system dependencies I think _should_ work by entering another sub shell. After all it’s all cabal + ghc really so as soon as they are available in the environment it should work. We haven’t found a good way to augment flake shells yet.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 15, 2023, 10:45am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/14 "2023-11-15T10:45:49Z")

</div>

I should clarify that the devx/haskell.nix cache does work great. I was talking about the normal nixpkgs/hydra cache.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [January 28, 2024, 2:07pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/15 "2024-01-28T14:07:45Z")

</div>

> [@angerman](#):
>
> Adding additional system dependencies I think _should_ work by entering another sub shell.

I have now tried this for the `gi-gtk` package, but there seemed to be issues with mismatched glibc versions. I got errors like this:

```plaintext
Preprocessing library for haskell-gi-base-0.26.4..
running dist/build/Data/GI/Base/BasicConversions_hsc_make failed (exit code 1)
rsp file was: "dist/build/Data/GI/Base/hsc2hscall37022-3.rsp"
output file:"dist/build/Data/GI/Base/BasicConversions.hs"
command was: dist/build/Data/GI/Base/BasicConversions_hsc_make >dist/build/Data/GI/Base/BasicConversions.hs
error: dist/build/Data/GI/Base/BasicConversions_hsc_make: /nix/store/aw2fw9ag10wr9pf0qk4nk5sxi0q0bn56-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/2if9iy5cy0bicwafllpa2aiq30v26app-glib-2.78.1/lib/libglib-2.0.so.0)

```

And after adding `glibc` manually to the list of dependencies I still got this error:

```plaintext
Preprocessing library for haskell-gi-base-0.26.4..
running dist/build/Data/GI/Base/BasicConversions_hsc_make failed (exit code 127)
rsp file was: "dist/build/Data/GI/Base/hsc2hscall46493-3.rsp"
output file:"dist/build/Data/GI/Base/BasicConversions.hs"
command was: dist/build/Data/GI/Base/BasicConversions_hsc_make >dist/build/Data/GI/Base/BasicConversions.hs
error: dist/build/Data/GI/Base/BasicConversions_hsc_make: error while loading shared libraries: __vdso_gettimeofday: invalid mode for dlopen(): Invalid argument

```

I do not encounter this issue when using `haskell.compiler.ghc963` from a normal nix shell. This is the complete shell that seems to work:

```plaintext
nix-shell -p haskell.compiler.ghc963 pango pkg-config gobject-introspection gtk4 atk pcre2 xorg.libXdmcp util-linux libselinux.dev libsepol.dev pcre fribidi.dev libthai.dev libdatrie.dev

```

---

<div class="post-metadata">

**Author:** ![tbidne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tbidne/32/2949_2.png) [@tbidne](https://discourse.haskell.org/u/tbidne)\
**Post date:** [January 28, 2024, 11:37pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/16 "2024-01-28T23:37:50Z")

</div>

Shot in the dark, but whenever I have C / system libs problems, my first thought is `LD_LIBRARY_PATH`:

```haskell
pkgs.mkShell {
  buildInputs = deps;

  -- glibc
  LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib/:$LD_LIBRARY_PATH";

  -- or for adding other deps
  -- LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath deps}:$LD_LIBRARY_PATH";
};

```

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [January 29, 2024, 4:59am UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/17 "2024-01-29T04:59:08Z")

</div>

Is this still related to the topic?

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [January 29, 2024, 3:38pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/18 "2024-01-29T15:38:56Z")

</div>

I think the main question of this topic is “How can we get a GHCup(-like) workflow on NixOS?”

For me that includes:

- Quick access to new releases, e.g. 9.8 now.
- Use normal cabal workflow including the ability to use C dependencies

One of the suggestions was to use the devx shell, but I’m encountered some ways in which it doesn’t quite behave as well as GHCup would on other platforms.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [January 29, 2024, 3:42pm UTC](https://discourse.haskell.org/t/jerry-rigging-ghcup-on-nixos/7295/19 "2024-01-29T15:42:22Z")

</div>

> [@angerman](#):
>
> Maybe you can outline what workflow you want to use?

I guess @Liamzy never answered this question and I did kind of take over the discussion from there.

@Liamzy if you want to keep this thread strictly on the topic of making GHCup work on NixOS then I can split out my part of the discussion to another thread.
