My own system packages in NixOS

Posted on 2024-04-27

I haven’t blogged about my cool command line tool before, but mclare has. The idea is to show the status of multiple processes at the same time, using a bloom filter for layout.

It works great, but I want to make it a system wide package in NixOS.

I’ve bounced off this several times before, let’s see how it goes.

What is it?

We have a Haskell command line program in a git repository.

I figure we can start with one that already works, utdemir’s nix-tree.

Let’s steal the flake.nix from nix-tree and drop it into the bloohm repo.

It doesn’t build.

error: Package ‘serialport-0.5.5’ in /nix/store/2z3llj8h7kwc3s6xw49zpy5vvqqimyr3-source/pkgs/development/haskell-modules/hackage-packages.nix:267788 is marked as broken, refusing to evaluate.

It seems that the serialport library is marked as “broken” in the nix packages collection.

How does that happen? How are Haskell libraries marked broken?

How / why are Haskell libraries marked broken?

A short duck search later I find something on the NixOS discourse, How to work with broken Haskell packages.

There’s a link to the Haskell section of the nix manual, and from there to the list of broken packages.

Searching inside that page for serialport turns up:

- serialport # failure in job https://hydra.nixos.org/build/233201348 at 2023-09-02

As far as I can tell, the serialport library tests don’t pass unless you have an arduino running the test code attached to a serial port. That’s not gonna happen on a Nix builder, and I don’t know how to fix that.

How can I use a library marked broken?

I can ugly-hack my way around that by adding allowBroken = true which makes me sad.

pkgs = import nixpkgs {
  inherit system;
  overlays = [ overlay ];
  config = { allowBroken = true; }; # THIS MAKES ME SAD
};

How can I make that available in my configuration.nix?

I know I need to use an overlay, but after reading about overlays and how to call them, I gave up and used nix profile install '.#' .

This caused me a bit of extra excitement when I upgraded my package, I can’t reinstall an already installed package.

I got an error telling me to run this command:

nix profile remove git+file:///home/shae/build/bloohm#defaultPackage.x86_64-linux

but that failed, and I had to remove the nix store path directly:

> nix profile remove '/nix/store/74s361g85hxm4c1iw2bkvbprv6xvnjpc-bloohm-1.0.0.0'
removing 'git+file:///home/shae/build/bloohm#defaultPackage.x86_64-linux'

That’s good enough for now, hopefully I’ll learn enough about overlays to make this a system package.

What’s the conclusion?

I updated bloohm to use Nix Flakes, and I published a new version to the official Haskell repository!

And there’s something wrong with the build grumble I’ll get back to that later.