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 }:
let
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; };
});
in
{
packages = forAllSystems ({ pkgs }: {
default = pkgs.haskellPackages.developPackage {
name = "hello-flake-haskell";
root = ./.;
};
});
};
}
❯ cat package.yaml
name: hello-flake-haskell
version: 0.1.0
dependencies:
- base
executables:
hello-flake-haskell:
main: Main.hs
❯ cat stack.yaml
packages:
- .