{"id":13647678,"url":"https://github.com/Gabriella439/haskell-nix","last_synced_at":"2025-04-22T02:32:27.102Z","repository":{"id":143561905,"uuid":"77855199","full_name":"Gabriella439/haskell-nix","owner":"Gabriella439","description":"Nix and Haskell in production","archived":false,"fork":false,"pushed_at":"2023-09-22T15:53:46.000Z","size":136,"stargazers_count":1153,"open_issues_count":28,"forks_count":116,"subscribers_count":32,"default_branch":"main","last_synced_at":"2025-04-15T00:04:21.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gabriella439.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-02T18:59:50.000Z","updated_at":"2025-04-12T00:46:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"5040d65d-cc04-4467-a262-55c3ce626cff","html_url":"https://github.com/Gabriella439/haskell-nix","commit_stats":null,"previous_names":["gabriel439/haskell-nix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gabriella439%2Fhaskell-nix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gabriella439%2Fhaskell-nix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gabriella439%2Fhaskell-nix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gabriella439%2Fhaskell-nix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gabriella439","download_url":"https://codeload.github.com/Gabriella439/haskell-nix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250028531,"owners_count":21363160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:03:42.322Z","updated_at":"2025-04-22T02:32:26.838Z","avatar_url":"https://github.com/Gabriella439.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# Nix and Haskell in production\n\nThis guide documents how I use Nix for Haskell development.  Feel free to open\nissues or pull requests if you would like to contribute or suggest improvements\n\nThe purpose of this project is to support two Haskell workflows:\n\n* Workflow #1: Nix provisions the development environment\n    * Nix provides all dependencies and the Haskell toolchain\n    * You still build the root project using `cabal` ([overview](https://www.haskell.org/cabal/), [user's guide](https://cabal.readthedocs.io/))\n    * This approach is ideal for development as it supports incremental builds\n* Workflow #2: Nix builds the root project for you\n    * This approach is ideal for continuous integration (especially Hydra)\n\nThe emphasis of this guide is to be as robust as possible and gracefully handle\nwriting Haskell projects at scale.  Some of the suggestions in this guide might\nbe overkill for a small Haskell project but are essential when managing multiple\nprivate Haskell projects across a team of developers.\n\nThis guide is based partly on\n[the Haskell section of the `nixpkgs` manual][nixpkgs-haskell]\nand partly on experience using Nix and Haskell in production at\n[Awake Security][awake].\n\n# Background\n\nNix is not a `cabal` replacement and Nix actually complements `cabal` quite\nwell.  Nix is much more analogous to a `stack` replacement.  `stack` does\nprovide some support for Nix integration, but this document does not cover that.\nInstead, this document describes how to use Nix in conjunction with `cabal` for\nHaskell development\n\nThe main benefits of using Nix over `stack` are:\n\n*   Binary caches\n\n    Nix lets you download precompiled Hackage packages whereas `stack` compiles\n    them on your computer the first time you depend on them\n\n*   Space efficiency\n\n    `stack` creates a copy of each package for each resolver.  This means that\n    if you have two projects with different resolvers then they will not use\n    the same copy of shared dependencies\n\n*   Generality\n\n    Nix is a language-independent build tool.  This means you can use Nix to\n    also build and customize non-Haskell dependencies (like `gtk`).  This\n    uniform language simplifies build tooling and infrastructure.\n\n*   Larger ecosystem\n\n    Nix provides a large ecosystem of tools that integrate with anything that\n    Nix can build, such as Hydra (continuous integration), NixOS (an operating\n    system), and NixOps (a deploy tool)\n\n*   Flexibility\n\n    Nix is a powerful tool in the hands of advanced users.  You can make very\n    deep and sweeping changes to your toolchain, such as recompiling everything\n    with security hardening\n\nThe main disadvantage of using Nix over `stack` are:\n\n*   Verbosity\n\n    Nix derivations for Haskell projects are significantly more complex than\n    their corresponding `stack.yaml` files.  The `release.nix` files in this\n    repository are the Nix analog of a `stack.yaml` file and you can see for\n    yourself the increase in complexity as the examples progress in difficulty.\n\n*   Poor error messages\n\n    Nix is an untyped language with no special Haskell integration, so error\n    messages are unhelpful\n\n*   Nix cannot incrementally compile Haskell libraries\n\n    Note that you can still use Nix to provision a development environment and\n    incrementally compile a Haskell package using cabal. However, if you use Nix\n    to build the package then Nix will build the package from scratch for every\n    minor change. In theory, this could be fixed to have Nix directly support\n    incremental Haskell builds but this has not been done yet.\n\n*   Worse user experience\n\n    Nix does not provide many conveniences that `stack` does such as\n    bootstrapping new projects or \"file watch\"\n\nBoth Nix and `stack` use curated package sets instead of version bounds for\ndependency management.  `stack` calls these package sets \"resolvers\" whereas\nNix calls these package sets \"channels\".  Nix provides stable channels with\nnames like `NixOS-18.09` (analogous to `stack`'s LTS releases) and then an\nunstable channel named `nixpkgs-unstable` (analogous to `stack`'s nightly\nreleases)\n\n# Related guides\n\n* [Nix Haskell Monorepo Tutorial](https://github.com/fghibellini/nix-haskell-monorepo) -\n  Guide on how to scale Nix development to a larger repository containing all of\n  a company's internally-developed Haskell packages\n\n# Related tools\n\nBefore continuing, I'd like to mention some other tools for mixing Haskell with\nNix:\n\n* [`tinc`](https://github.com/sol/tinc/blob/nixpkgs/NIX.md) - this uses\n  `cabal`'s solver to select which Haskell packages to use instead of the\n  curated Haskell package set from `nixpkgs`\n* [`styx`](https://github.com/jyp/styx) - This tool provides a `stack`-like\n  interface to managing Haskell dependencies using Nix\n* [`haskell-overridez`](https://github.com/adetokunbo/haskell-overridez) -\n  Tool that automates dependency management as described in this guide\n\n# Setup\n\nBefore you begin, you must install Nix if you haven't already:\n\n```bash\n$ curl -L https://nixos.org/nix/install | sh\n```\n\nYou must also install `cabal2nix` and `nix-prefetch-git`:\n\n```bash\n$ nix-env --install cabal2nix\n$ nix-env --install nix-prefetch-git\n```\n\nYou also need to install `cabal` if you haven't done so already.  You can either\nuse your installed `cabal` or you can use `nix` to install `cabal` for you:\n\n```bash\n$ nix-env --install cabal-install\n```\n\nMake sure that you have a fairly recent version of `cabal` installed since these\nexamples will use GHC 8 which requires version 1.24 or later of `cabal`.  You\ncan check what version you have installed by running:\n\n```bash\n$ cabal --version\n```\n\nFinally, run `cabal update` if you haven't done so already\n\n# Organization\n\nThis tutorial is split into several tutorial projects in the `project*/`\nsubdirectories.  Read the `README.md` file in each subdirectory in\norder to follow the tutorial:\n\n* [Project 0 - Nix basics][proj0]\n* [Project 1 - Dependency management][proj1]\n* [Project 2 - Non-Haskell dependencies][proj2]\n* [Project 3 - Customizing Haskell projects ][proj3]\n* [Project 4 - Advanced dependency management][proj4]\n\n[awake]: https://awakesecurity.com/\n[nixpkgs-haskell]: https://nixos.org/nixpkgs/manual/#haskell\n[proj0]: ./project0/README.md\n[proj1]: ./project1/README.md\n[proj2]: ./project2/README.md\n[proj3]: ./project3/README.md\n[proj4]: ./project4/README.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGabriella439%2Fhaskell-nix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGabriella439%2Fhaskell-nix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGabriella439%2Fhaskell-nix/lists"}