Skip to content

Add useLocalGhcLib project option#2510

Merged
hamishmack merged 2 commits into
masterfrom
hkm/v1-uselocalghclib
May 23, 2026
Merged

Add useLocalGhcLib project option#2510
hamishmack merged 2 commits into
masterfrom
hkm/v1-uselocalghclib

Conversation

@hamishmack
Copy link
Copy Markdown
Collaborator

Surfaces what modules/configuration-nix.nix used to do unconditionally as an opt-in useLocalGhcLib flag. The packages.ghc.src override now only fires when a project actually constrains the ghc package (e.g. ghc-lib-reinstallable).

Four pieces:

  • modules/project-common.nix — add the useLocalGhcLib option (default false).
  • modules/configuration-nix.nix — drop the unconditional packages.ghc.src / packages.ghc.package-description-override overrides; they're moved into the per-project wiring below.
  • modules/stack-project.nix — under useLocalGhcLib, re-apply the packages.ghc.src post-plan override. Stack-to-nix can't use the cabal-project route, so this keeps the existing behaviour for stack users who flip the flag.
  • modules/cabal-project.nix — under useLocalGhcLib, inject a source-repository-package block into cabalProjectLocal pointing at the configured-src + generated GHC tree, and add an inputMap entry so haskell.nix doesn't try to fetch the URL. Cabal then hashes the wrapped repo's content into pkg-src-sha256 and installs lib:ghc like any other reinstallable dep.

Projects that need the previous always-on behaviour now set useLocalGhcLib = true on the project module; everyone else gets a smaller plan-nix and avoids the unconditional configured-src materialisation.

Pulled out of #2504 (hkm/builder-v2).

Surface what `modules/configuration-nix.nix` used to do
unconditionally as an opt-in `useLocalGhcLib` flag, so the
`packages.ghc.src` override only fires when a project actually
constrains the `ghc` package (e.g. `ghc-lib-reinstallable`).

Four pieces:

* `modules/project-common.nix`: add the `useLocalGhcLib` option
  (default `false`).
* `modules/configuration-nix.nix`: drop the unconditional
  `packages.ghc.src` / `packages.ghc.package-description-override`
  overrides — they're moved into the per-project wiring below.
* `modules/stack-project.nix`: under `useLocalGhcLib`, re-apply
  the `packages.ghc.src` post-plan override.  Stack-to-nix can't
  use the cabal-project route, so this keeps the existing
  behaviour for stack users who flip the flag.
* `modules/cabal-project.nix`: under `useLocalGhcLib`, inject a
  `source-repository-package` block into `cabalProjectLocal`
  pointing at the configured-src + generated GHC tree, and add an
  `inputMap` entry so haskell.nix doesn't try to fetch the URL.
  Cabal then hashes the wrapped repo's content into
  `pkg-src-sha256` and installs `lib:ghc` like any other
  reinstallable dep.

Projects that need the previous always-on behaviour now set
`useLocalGhcLib = true` on the project module; everyone else gets
a smaller plan-nix and avoids the unconditional `configured-src`
materialisation.

Pulled out of #2504 (`hkm/builder-v2`).
Flips the new opt-in flag in both test variants and adds a
changelog entry telling users to do the same when they constrain
`lib:ghc`.
@hamishmack hamishmack merged commit 634940e into master May 23, 2026
6666 of 6799 checks passed
hamishmack added a commit that referenced this pull request May 25, 2026
Migrates the in-tree test suite to work under `builderVersion = 2`.
Adds `docs/dev/migrating-to-v2.md` documenting the patterns we hit,
keyed off the symptoms users are likely to see when flipping the
flag on their own projects.

Patterns covered (with file-level examples):

* Library / executable profiling — `.profiled` overlay replaced by
  a sibling project whose `cabalProjectLocal` carries
  `library-profiling: True` / `profiling: True`
  (`test/exe-dlls`, `test/exe-lib-dlls`, `test/gi-gtk`,
  `test/th-dlls`, `test/th-dlls-minimal`, `test/js-template-haskell`,
  `test/cabal-simple-prof`).
* Coverage — module-level `doCoverage` mirrored into
  `cabalProjectLocal` `coverage: True` (`test/coverage`).
* DWARF — `.dwarf` overlay dropped, replaced by
  `compilerSelection = … c.dwarf …` + `debug-info: 2`
  (`test/cabal-simple-debug`).
* Sublib haddock — `documentation: True` in `cabalProjectLocal`;
  output path moved so `find -name <Module.html>` accepts both v1
  and v2 layouts (`test/sublib-docs`).
* Per-package `ghc-options` — `HsOpenSSL` workaround moved from
  `test/modules.nix` to `test/cabal.project.local` (`test/modules.nix`).
* Per-package `extra-lib-dirs` — Windows `test-clib` paths moved
  into `cabalProjectLocal` (`test/th-dlls-minimal`).
* `ghcOptions` scope — moved from per-component to per-package
  (`test/th-dlls`).
* `shellFor` migration — `component.shell` / `component.env` →
  `project.shellFor { exposePackagesVia = "ghc-pkg"; }`
  (`test/with-packages`, `test/shell-for`,
  `test/shell-for-setup-deps`).
* `withHoogle = false` on static — avoids `.dyn_hi` lookup failures
  in hoogle's haddock chain (`test/with-packages`).
* `origSrc` / `origSubDir` workaround — synthesised package-root
  drv with `.git` at the top, source-cleaning disabled via
  `outPath` + `filterPath` (`test/githash`).
* Custom-setup `base` / `directory` — added to explicit
  `setup-depends` (`test/setup-deps`, `test/shell-for-setup-deps`).
* Native-musl `git` — host vs build-build picker keyed on
  `haskellLib.isNativeMusl` to avoid glibc/musl libc mixing
  (`test/githash`).
* Android cross — `test/cabal.project.android` injected
  conditionally (`test/exe-dlls`, `test/exe-lib-dlls`,
  `test/th-dlls`).
* `useLocalGhcLib = true` — earlier change (PR #2510) covered
  separately; referenced in the guide for completeness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant