Skip to main content

Nix Progress (Part 2)

I have made more progress on Nix configuration since yesterday’s Nix Progress blog entry.

GHC 9.0.1

I made one more attempt to start a shell with GHC 9.0.1 using the HEAD revision of nixpkgs yesterday, and it worked! 4d4fdc32

nixpkgs Revisions

Divam’s TTC pull request uses the following revisions:

Through experimentation, I determined why the nix/default revision is used for nix-gitignore. When older revisions are used, loading the Nix expression results in an error. I suspect that this is due to an API change. The issue is avoided by using a recent revision for nix-gitignore and using a possibly different revision for Haskell packages. I do not really understand why, but the default must be compatible with GHC 9.0.1 or the build of the GHC 9.0.1 shell fails! I think that using a different revision might have been the cause of build failures yesterday.

Some revisions are used for more than one compiler version. For example, GHC 8.2.2 works fine using the nix-versions revision for GHC 8.4.4, so the nix-versions revision for GHC 8.2.2 is not used. I think that the reason for doing this is to minimize the number of packages that have to be installed. Nice!

I updated the revision for GHC 9.0.1 to the one that was successful for me. Since I have had so many failures when using arbitrary revisions, I am using the nix-versions revision for GHC 8.10.4 with ghc8104 and ghc884.

Refactoring

Once I got things working, I could refactor and make improvements.

I created shell-VERSION.nix files to make it easy to run a Nix shell with the specified compiler version. Each file looked like the following:

import ./shell.nix {
  pkgs = import ./nix/ghc-9.0.1 {};
  compiler = "ghc901";
}

Unless using the default, both pkgs and compiler need to be specified as arguments to shell.nix, and the specified compiler must be supported by the specified pkgs. To improve this, I put the mapping from compiler to pkgs inside of shell.nix. Since only the compiler needs to be specified, it is easy to specify the argument using nix-shell and all of the shell-VERSION.nix files can be removed.

The nix-thunk software is nice, but it is overkill for this simple use case. I refactored shell.nix to define the nixpkgs revisions directly. This greatly simplifies the configuration, allowing me to remove the whole nix directory. It greatly simplifies maintenance as well.

What’s Next?

I will work on the Nix configuration for LiterateX next. The configuration will be a bit different because the project includes an executable as well as a library. I will also work on the Nix configuration for the animation, which has system dependencies.

Once that is done, I will work on the Nix configuration for the other projects. I expect/hope that it will be easy after doing so for both TTC and LiterateX.

If there are no recommendations for further change to the Nix configuration, I will make minor releases for all projects.

Author

Travis Cardwell

Published

Tags
Related Blog Entries