What does haskellPackages.developPackage do under the hood?

Using the zero-to-nix flake template for Haskell, I packaged a simple Haskell program. Everything works fine, but there’s one thing that confuses me: is it using cabal, stack, or something else to build the program?

The flake uses a package.yaml and stack.yaml file, which makes me think that it’s using Stack to build the Haskell program. However, the flake.nix uses haskellPackages.developPackage, which I thought uses cabal2nix. And looking at the make-package-set.nix source, it does seem like that is true… although I quickly got lost in the weeds when I tried to follow the logic.

❯ cat flake.nix
  description = "a flake for a simple Haskell program";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";

  outputs = { self, nixpkgs }:
      nameValuePair = name: value: { inherit name value; };
      genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);
      allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
      forAllSystems = f: genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      packages = forAllSystems ({ pkgs }: {
        default = pkgs.haskellPackages.developPackage {
          name = "hello-flake-haskell";
          root = ./.;
❯ cat package.yaml
name: hello-flake-haskell
version: 0.1.0

  - base

    main: Main.hs
❯ cat stack.yaml
  - .

cabal2nix itself appears to support package.yaml: cabal2nix/Cabal2nix.hs at 5e183d1ac819ea1beec3da6229d76d4185b026d0 · NixOS/cabal2nix · GitHub (though it doesn’t seem to documented?)


Wow, I never expected that cabal2nix would have anything to do with yaml or hpack! Thank you for clearing up the mystery.

1 Like