{"id":13687986,"url":"https://github.com/srid/haskell-multi-nix","last_synced_at":"2025-03-20T23:31:04.345Z","repository":{"id":61746498,"uuid":"546716975","full_name":"srid/haskell-multi-nix","owner":"srid","description":"A simple demo of Nixifying a multi-package Haskell project","archived":false,"fork":false,"pushed_at":"2025-03-16T14:59:03.000Z","size":24,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T15:28:39.999Z","etag":null,"topics":["cabal","haskell","nix"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-06T14:28:19.000Z","updated_at":"2025-03-16T14:59:06.000Z","dependencies_parsed_at":"2025-03-16T15:36:44.981Z","dependency_job_id":null,"html_url":"https://github.com/srid/haskell-multi-nix","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srid%2Fhaskell-multi-nix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srid%2Fhaskell-multi-nix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srid%2Fhaskell-multi-nix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srid%2Fhaskell-multi-nix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srid","download_url":"https://codeload.github.com/srid/haskell-multi-nix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244710587,"owners_count":20497269,"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","haskell","nix"],"created_at":"2024-08-02T15:01:04.586Z","updated_at":"2025-03-20T23:31:04.340Z","avatar_url":"https://github.com/srid.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# haskell-multi-nix\n\nJust a simple demo of Nixifying a *multi-package* Haskell project.\n\n## Packages\n\nThis project has two local Haskell packages:\n\n1. `foo`: a Haskell library exporting `Foo.fooFunc`.\n2. `bar`: a Haskell executable that depends on `foo`\n\nTo build the `foo` library:\n\n```sh\nnix build .#foo\n```\n\nTo build the `bar` executable:\n\n```sh\nnix build\n```\n\nTo run the executable:\n\n```sh\nnix run\n```\n\n## Dev Shell\n\nThe Nix development shell (`nix develop`) allows you to run the various `cabal` commands on the local packages.\n\nFor example, this will compile and run the main executable:\n\n```sh\nnix develop -c cabal -- run bar\n```\n\n### ghcid\n\nUsing [Multiple Home Units](https://well-typed.com/blog/2022/01/multiple-home-units/) you can use ghcid to auto-recompile and auto-rerun the `bar` program whenever **any** Haskell source changes, including from libraries (`foo`). To do this, you must pass `--enable-multi-repl` along with the list of libraries to reload, which list should be in the correct order. viz.:\n\n```\nghcid -T Main.main -c 'cabal repl --enable-multi-repl bar foo'\n```\n\nNow, try modifying `./foo/src/Foo.hs` and ghcid should instantly re-compile and re-run `bar` with the new changes. A demo can be seen [here](https://x.com/sridca/status/1901283945779544362).\n\n## How it works\n\n### The `nixpkgs` tree\n\nThe [`nixpkgs`](https://github.com/srid/haskell-multi-nix/tree/nixpkgs) release tag uses raw functions from nixpkgs.\n\nThe Haskell infrastructure in nixpkgs provides a package set (an attrset) called `pkgs.haskellPackages`[^ver]. We add two more packages -- `foo` and `bar` (the local packages) -- to this package set. We do this by using the standard nixpkgs overlay API (specifically `extend`, which was created by the implicit `makeExtensible`) defined in [fixed-points.nix](https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix). After having added the local packages, the result is a *new* package set, which is no different *in essense* to the original package set (we can also put our dependency overrides in the same, or different, overlay). Note that any package in a package set can depend on any other packages; thus, it becomes possible to make `bar` depend on `foo` (see \"build-depends\" in `./bar/bar.cabal`) even though they come from the same overlay.\n\n[^ver]: The package set `pkgs.haskellPackages` corresponds to the default GHC version. Non-default GHC versions have their own package sets, for e.g.: `pkgs.haskell.packages.ghc924` is the package set for GHC 9.2.4.\n\n### The `master` tree\n\nThe `master` branch uses [haskell-flake](https://github.com/srid/haskell-flake) which abstracts much of what we explained above, such that your flake.nix is as small as possible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrid%2Fhaskell-multi-nix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrid%2Fhaskell-multi-nix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrid%2Fhaskell-multi-nix/lists"}