[Haskell-cafe] garn: a Nix/Cabal/Stack alternative
Julian Arni
jkarni at gmail.com
Sun Dec 3 16:06:14 UTC 2023
Dear list,
garn is a new take on Nix - configured in Typescript rather than the Nix
language, and with a nicer and simpler CLI (thanks optparse-applicative!).
The repository is https://github.com/garnix-io/garn, and the website is
https://garn.io/.
I'm mentioning it here because we just added better Haskell support, which
makes it now a plausible alternative to managing your Haskell projects with
Nix, Stack or Cabal. An example Haskell project:
import * as garn from "https://garn.io/ts/v0.0.18/mod.ts";
import * as pkgs from "https://garn.io/ts/v0.0.18/nixpkgs.ts";
export const project = garn.haskell.mkHaskellProject({
description: "My project",
src: ".",
executables: ["server", "openapi-generation"]
overrideDependencies: {
"servant": "0.19.1"
},
ghcVersion: "ghc94"
}).addExecutable("format")`${pkgs.ormolu}/bin/ormolu --mode inplace
$(find . -name '*.hs')`
Which allows for `garn build project` to build the project, and `garn enter
project` to be in a devshell with cabal, ghc94 and all the dependencies
installed, and `garn run project.format` for formatting all files with
ormolu.
(`garn init` is capable of generating most of that file for you.)
# Comparisons
First, compared to all of the options below, garn is much less mature -
there'll
be rougher edges or features not yet supported. It's also still changing
very quickly,
and backwards compatibility is not, for now, a priority.
- Cabal: Like Cabal, garn still uses a cabal file, and in fact expects you
to
develop with cabal. garn brings in the dependencies itself and makes them
known to ghc/cabal, and they're snapshot-based rather than
resolver-based. In
addition, garn makes it easy to include system (non-Haskell)
dependencies, it
sandboxes builds and tests for better reproduciblity (making CI in
particular
quite easy); it allows for shared caches; it supports scripts for project
janitoring and management; and it supports devshells.
- Stack: Like Stack, garn uses a snapshot-based approach to dependencies. In
fact, it's based on the stackage releases. It also supports overriding
versions from Hackage, but not yet from git. Unlike Stack, it allows
specifying system dependencies (non-Haskell dependencies); it sandboxes
builds and tests for better reproduciblity (making CI in particular quite
easy); it allows for shared caches; it supports scripts for project
janitoring and management; and it supports devshells.
- Nix: the focus of garn has been a simplified and more productive user
experience when compared to Nix. A typed language means you can get
autocompletion, documentation, and type errors in your editor, for
example.
And, even if Typescript is by no means perfect, it's much easier to
program
in than Nix, so it becomes more fun to abstract away functionality (e.g.:
an
addGhcidToProject function). garn "transpiles" to Nix, and Nix can be
embedded in garn, so the choice is not binary.
# Feedback
If you try it out, please let us know what you think, or if you run into any
roadblocks. You can email me at this address, or open issues on GitHub, or
join
the Discord channel at https://discord.com/invite/XtDrPsqpVx.
It also happens to be partly written in Haskell; hopefully that makes it
more
easy and fun to get involved!
Cheers,
Julian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20231203/5113ee66/attachment.html>
More information about the Haskell-Cafe
mailing list