{"id":14128241,"url":"https://github.com/pjones/nix-hs","last_synced_at":"2025-10-26T00:30:53.671Z","repository":{"id":50141958,"uuid":"98588021","full_name":"pjones/nix-hs","owner":"pjones","description":"Haskell + nixpkgs = nix-hs","archived":false,"fork":false,"pushed_at":"2021-06-02T22:43:32.000Z","size":149,"stargazers_count":23,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"trunk","last_synced_at":"2025-01-31T12:51:21.664Z","etag":null,"topics":["cabal","direnv","haskell","nixpkgs"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pjones.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-27T23:38:52.000Z","updated_at":"2021-06-02T18:33:26.000Z","dependencies_parsed_at":"2022-09-07T13:50:34.563Z","dependency_job_id":null,"html_url":"https://github.com/pjones/nix-hs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjones%2Fnix-hs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjones%2Fnix-hs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjones%2Fnix-hs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjones%2Fnix-hs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pjones","download_url":"https://codeload.github.com/pjones/nix-hs/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238229940,"owners_count":19437723,"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":["cabal","direnv","haskell","nixpkgs"],"created_at":"2024-08-15T16:01:25.077Z","updated_at":"2025-10-26T00:30:53.304Z","avatar_url":"https://github.com/pjones.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# Haskell + nixpkgs = nix-hs\n\n[![tests](https://github.com/pjones/nix-hs/workflows/tests/badge.svg)](https://github.com/pjones/nix-hs/actions?query=workflow%3Atests)\n[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/pjones/nix-hs?label=release)](https://github.com/pjones/nix-hs/releases)\n[![cachix](https://img.shields.io/badge/cachix-nix--hs-green)](https://app.cachix.org/cache/nix-hs)\n\nA thin layer over the existing [Haskell][] infrastructure in\n[nixpkgs][] which adds all of the tools needed for interactive\ndevelopment.  Here are some of the features that you might find the\nmost useful:\n\n  * An interactive development environment (via `nix-shell`) that\n    includes:\n\n      * GHC (8.8.4, 8.10.4, 9.0.1)\n\n      * `cabal-install` 3.4.0\n\n      * `stack` 2.7.1\n\n      * [hlint][] 3.3.1\n\n      * [haskell-language-server][] 1.1.0\n\n      * [ormolu][ormolu] 0.1.4.1\n\n      * [cabal-fmt][cabal-fmt] 0.1.5.1\n\n      * [stan][stan] 0.0.1.0\n\n      * and a Hoogle database for all of your project's dependencies\n\n    **NOTE:** The following tools do not currently support GHC 9.0.1:\n\n      * haskell-language-server\n\n      * ormolu\n\n      * stan\n\n  * Easy to use system for [overriding Haskell packages](#using-a-broken-package) (e.g., use\n    a package not on Hackage, fix a package marked as broken, etc.)\n    without having to write tons of Nix code.\n\n  * Works seamlessly with [direnv][], [lorri][], and [niv][] if you\n    already have those tools installed.\n\n  * Switch GHC versions by passing an argument to `nix-build` or\n    `nix-shell`.\n\n  * [Strip dependencies](#access-to-binary-only-packages) from a package so you can deploy just a\n    binary without tons of other packages coming along for the ride.\n\n  * Create an interactive development environment [without adding\n    nix-hs](#interactive-environments-without-nix-hs) as a project dependency.\n\n  * Fetch pre-built tools from [the binary cache](#using-the-binary-cache).\n\n## Geting Started\n\nCreate a `default.nix` file that looks something like this:\n\n```nix\n{ pkgs ? import \u003cnixpkgs\u003e { }\n}:\nlet\n  nix-hs =\n    import\n      (fetchTarball\n        \"https://github.com/pjones/nix-hs/archive/release-21.05.tar.gz\")\n      {\n        inherit pkgs;\n      };\nin\nnix-hs {\n  cabal = ./test/hello-world/hello-world.cabal;\n}\n```\n\nAnd a `shell.nix` that looks like this:\n\n```nix\n# Load an interactive environment:\n(import ./. {}).interactive\n```\n\nThat's it!  Now `nix-build` and `nix-shell` just work!\n\n## Configuration\n\nIn addition to the `cabal` argument to the `nix-hs` function, there\nare other ways to control how your package is built.\n\n### Enable Flags from the Cabal File\n\nIf you have a flag defined in your package's cabal file you can enable\nit using the `flags` argument:\n\n```nix\nnix-hs {\n  cabal = ./mypackage.cabal;\n  flags = [ \"someflagname\" ];\n}\n```\n\n### Using a Broken Package\n\nIf one of your package's dependencies can't be built you can try\noverriding it:\n\n```nix\nnix-hs {\n  cabal = ./mypackage.cabal;\n\n  overrides = lib: self: super: with lib; {\n    pipes-text = unBreak (dontCheck (doJailbreak super.pipes-text));\n  };\n}\n```\n\nIn the example above, the `overrides` function takes three arguments:\n\n  1. `lib`: An attribute set of library functions.  These are the\n     functions provided by the `pkgs.haskellPackages.lib` set plus a\n     few more that you might find useful such as:\n\n     - `unBreak`: Remove the `broken` flag from a package\n     - `compilerName`: The nixpkgs name of the Haskell compiler\n       being used (e.g. `ghc884`)\n     - `pkgs`: The full nixpkgs package set, after overriding\n\n  2. `self`: The final set of Haskell packages after applying all\n     overrides.  This refers to the future version of the package set\n     so if you're not careful you can fall into infinite recursion.\n     When in doubt use `super` instead.\n\n  3. `super`: The set of Haskell packages that are being modified.\n     Use this attribute set to refer to existing Haskell packages.\n     You can also use `super` to access useful functions such as\n     `callCabal2nix` and `callHackageDirect`.\n\nThe `overrides` function should return an attribute set of Haskell\npackages.  The set of returned packages will be merged into the final\nset used to build your package.\n\nAn example package using the `overrides` function can be found in\n`test/overrides/default.nix`.  The full list of additional `lib`\nfunctions is in `lib/haskell.nix`.\n\n### Working with Multi-Package Cabal Projects\n\nIf you have a project that contains multiple Cabal packages you can\nbuild them all with a single `default.nix`.  The `cabal` argument to\n`nix-hs` can either be a path to a Cabal file *or* an attribute set of\nCabal files:\n\n```nix\nnix-hs {\n  cabal = {\n    package1 = ./package1/package1.cabal;\n    package2 = ./package1/package2.cabal;\n  };\n}\n```\n## Integrating Your Text Editor and Shell\n\nThe best way to let your text editor and shell use the environment\ncreated from Nix is to use [direnv][].  Here's an example `.envrc`\nfile:\n\n```sh\n# Use lorri if it's installed, otherwise load shell.nix:\nif has lorri; then\n  eval \"$(lorri direnv)\"\nelse\n  use nix\nfi\n\n# Reload if these files change:\nwatch_file $(find . -name '*.cabal' -o -name '*.nix')\n```\n\n**NOTE:** Make sure you have a `shell.nix` file that exposes the\n`interactive` attribute of the derivation, like the example above.\n\n## Interactive Environments Without nix-hs\n\nIf you don't want to use `nix-hs` to control your `default.nix` you\ncan still use it for building an interactive development environment.\nJust clone this repository and use the `shell/default.nix` file.\n\nFor example, to drop into an interactive shell:\n\n```\n$ nix-shell /path/to/nix-hs/shell\n```\n\nOr\n\n```\n$ nix-shell --argstr compiler 8.8.3 /path/to/nix-hs/shell\n```\n\nEven better, use [direnv][] so your normal shell and text editor can\nsee all the installed development tools.  Here's an example `.envrc`\nfile:\n\n```sh\nuse nix /path/to/nix-hs/shell\n```\n\n## Access to Binary-Only Packages\n\nThe derivation generated by the `nix-hs` function makes it easy to\naccess a \"binary only\" derivation.  This is perfect for deployments or\nDocker containers where you don't want to bring along all of your\npackage's dependencies (including GHC).\n\nThe `bin` attribute of the derivation gives you access to this binary\nonly derivation.  For example, to create a docker container put the\nfollowing in `docker.nix`:\n\n```nix\n{ pkgs ? import \u003cnixpkgs\u003e { }\n}:\n\nlet\n  mypackage = (import ./. { inherit pkgs; }).bin;\n\nin pkgs.dockerTools.buildImage {\n  name = \"mypackage\";\n  tag  = \"latest\";\n\n  config = {\n    Cmd = [ \"${mypackage}/bin/hello\" ];\n  };\n}\n```\n\n## Using the Binary Cache\n\nIf you don't want to spend all day compiling the tools needed to build\nyour Haskell package and its development environment you can use the\n`nix-hs` cache [on Cachix](https://app.cachix.org/cache/nix-hs).\n\nThe cache is populated after each `git push` via a [GitHub action](https://github.com/pjones/nix-hs/actions).\n\nNOTE: Due to disk space limitations the cache is limited to the\ncurrent LTS version of GHC.\n\n[haskell]: https://www.haskell.org/\n[nixpkgs]: https://nixos.org/nix/\n[direnv]: https://github.com/direnv/direnv\n[lorri]: https://github.com/target/lorri\n[niv]: https://github.com/nmattia/niv\n[ormolu]: https://github.com/tweag/ormolu\n[stan]: https://github.com/kowainik/stan\n[cabal-fmt]: https://github.com/phadej/cabal-fmt\n[haskell-language-server]: https://github.com/haskell/haskell-language-server\n[hlint]: https://github.com/ndmitchell/hlint\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjones%2Fnix-hs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpjones%2Fnix-hs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjones%2Fnix-hs/lists"}