Commit Graph

47 Commits

Author SHA1 Message Date
Alexander Vieth 7f3bf673c9 use Hamish's suggestion for faster dedup 2022-08-25 10:15:15 -04:00
Alexander Vieth 872043aadc use attrsets for deduplication
'name' should be unique for haskell packages; not necessarily so for
other things
2022-08-24 10:38:41 -04:00
Alexander Vieth 839515b97d deduplicate build inputs for the shell
https://github.com/input-output-hk/haskell.nix/issues/1297
2022-08-23 11:32:12 -04:00
Yvan Sraka bc1de42afa Fix #1587: the option shell.buildInputs does not exist ... (#1598) 2022-08-18 16:07:27 +02:00
Hamish Mackenzie ce047883ac Fix tool functions (#1570) 2022-08-01 23:57:29 +12:00
Hamish Mackenzie a443611ecf Add evalSystem and evalPackages project args (#1546)
This adds a way to specify the `evalSystem` or `evalPackages` explicitly when calling the `project` functions.

Currently if we want to make a `flake` that supports multiple systems we have few options:

* Require builders for all the supported systems (even just for `nix flake show`).

* Pass `--impure` so that haskell.nix can see `builtins.currentSystem` to set up `pkgs.evalPackages` to use that.  Unfortunately this prevents nix from caching some of the work it does and often results in it recalculating for each supported system when it would otherwise be cached and take no time at all.

* Add an overlay to replace `evalPackages`.  This works, but it is not straight forward.

* Materialize the nix files for the project.

This change allows `evalSystem = "x86_64-linux";` to be passed telling `haskell.nix` to run `cabal` and `nix-tools` on that system.  The user will have to have a builder for that system, but does not need to have builders for the others (unless building outputs for them).
2022-07-28 20:03:05 +12:00
Teo Camarasu 54b86efe7c Avoid duplicated packages in ghc-pkg list (#1530)
Filter out the setup dependencies of `Simple` packages from the shell. Fixes #1518.

Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
2022-06-30 21:16:35 +12:00
Shea Levy bfeea3e894 Allow packages to specify external static plugins 2022-05-02 11:08:42 -04:00
Hamish Mackenzie e9a93540c3 Look for DLLs in /bin directory of pkgconfig deps (#1422)
We include the /bin directory of `component.libs` in `extra-lib-dirs` on windows, but not `components.pkgconfig`.  This causes confusing differences between the behavior depending on how a dependency was specified in the `.cabal` file or added in a module.  If it wounds up in `components.libs` the need for DLLs would propagate correctly, but if it was only in `componets.pkgconfig` DLLs would not be included when building TH code and did not get symlinked to `exe` component output /bin dirs.
2022-04-01 16:35:04 +13:00
Hamish Mackenzie 864c0aff9c Pass enableDWARF to makeConfigFiles to fix -g3 support in nix-shell (#1385) 2022-02-25 01:52:16 +13:00
Michael Peyton Jones c58c5946eb Don't set LANG and LOCALE_ARCHIVE in shellFor (#1341) 2022-01-07 19:01:07 +08:00
Will Fancher e8bfc03091 shellFor: Add withHaddocks and fix ghc-pkg reporting no haddocks for dependencies. (#1279) 2021-11-03 22:29:53 +13:00
Teo Camarasu 3856d2d24d Improve shellFor selectComponents performance (#1146)
* factor out isSelectedComponent

* Optimise `flatLibDepends`

We no longer force the `outPath` attribute to avoid instantiating the
derivation, which is expensive
2021-06-28 16:46:19 +12:00
Teo Camarasu d7e5cface8 Fix: shellFor doesn't filter based on transitive dependencies (#1145)
* Fix shellFor not accounting for transitive dependencies

ensure that the following invariant is enforced:
  `shellFor` never adds the selected packages to its environment

* Fix missing selectedComponentsBitmap attribute

Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
2021-06-21 16:22:48 +12:00
Hamish Mackenzie 618ff607d3 Fix shellFor components argument (#1079) 2021-04-08 15:33:09 +12:00
Hamish Mackenzie 4245567cb1 Add --with-compiler to shellFor cabal cross compile wrapper (#1078) 2021-03-19 17:50:33 +13:00
Hamish Mackenzie bab2eaea62 Enable debug info on linux targets (#1050)
* Add `.debug` to build any component with DWARF dugug info on linux
  (ghc >=8.10.2).
* Pass `enableDWARF` to `shellFor` for to get a shell where all the
  components are the `.debug` ones.
2021-02-22 18:27:36 +13:00
Hamish Mackenzie f056dd34cd Fix the way ExeDependency is handled (#1036)
See https://github.com/input-output-hk/nix-tools/pull/101

We should look up hsPkgs.${pkg-name}.components.exe.${component-name}
instead of including the package as a dependency.

Adding `hsPkgs.${pkg-name}` a tool it is not clear which executable in the package `haskell.nix` should choose.

Haskell.nix did not deal with this well and in fact it could lead to `nix-shell` crashing.  For instance using `shellFor` to make a shell for building `haskell-language-server` with `cabal build` crashed as a dependency on `ghcide` the executable (by the `ghcide-bench` executable) caused infinite recursion.  Allowing `ghcide-bench` to correctly depend just on `components.exes.ghcide` fixes this.

This PR also includes:

* Updated materialized files built with the new nix-tools and latest index-state
* Small update to GHCJS (pins happy) to fix issue that showed up when the materialization was updated
* A fix for the infinite recursion issue when updating materialized files (by adding ghc-boot-packages-unchecked).
* Performance fix for shellFor (checks just the names of component derivations when filtering).
2021-02-12 10:45:23 +13:00
Hamish Mackenzie 2b7d93baf6 Allow package-name:sublib-name in build-depends (#963)
With cabal 3 it should be possible to reference a sublib in the
`build-depends` of a `.cabal` file using `package-name:sublib-name`

The `cabal-sublib` test is updated to include the new type syntax
and a fix is included for the component builder.

We will need to update `plan-to-nix` in `nix-tools` as well.
For now the work around is to use a module to add the sublib to
`depends` (see `test/cabal-sublib/default.nix`).

Without this fix the `cabal-sublib:slib` was not found by
`setup configure` because only `--dependency=slib=cabal-sublib-...`
was passed.  The fix is to also pass
`--dependency=cabal-sublib:slib=cabal-sublib-...`.
2021-01-08 23:11:16 +13:00
Michael Peyton Jones dbff20d0c8 Make haskell.nix quieter (#944)
* Remove unconditional trace for index-state

We already have messages for unusual cases (like using the latest
index-state). This message is unconditional, so quite noisy.
We include the actual index-state in the builer log so it's available if you
want to check it.

* Move source-cleaning warning to builder log

It's not *that* interesting, and someone who cares will likely check the
log.

* Move shellFor trace message to builder log

Not that interesting, really.

Co-authored-by: Hamish Mackenzie <Hamish.Mackenzie@iohk.io>
2020-11-27 14:18:15 +13:00
Hamish Mackenzie c0931c9a56 Replace otherShells with mkShell inputsFrom (#939)
It turns out the `otherShells` arg we added to `shellFor` is very
similar to the `inputsFrom` argument of `mkShell`.  We can use
`inputsFrom` instead having `otherShells` by replacing the use of
`mkDerivation` with `mkShell` in `shellFor`.
2020-11-26 21:15:27 +13:00
Hamish Mackenzie 3689e4fa3d Only include hoogle once in shell (#942)
Currently hoogle gets symlinked into ghcEnv and that is included
in the `nativeBuildInputs` of the shell.  In addition it the same
`hoogle` is included in `buildInputs` directly.

This is not a big problem for nix-shell, but it prevents
the using the following to install the shell in a docker
container:

```
nix-env -f shell.nix -iA buildInputs
nix-env -f shell.nix -iA nativeBuildInputs
```

Gives errors like:
```
error: packages '/nix/store/r3zx73r5y52mqz8p54pxr68pjfc5l0l8-hoogle-local-0.1/bin/hoogle' and '/nix/store/crbhp4wr84fihg9akqh6r6an6s7qb77s-ghc-shell-for-fp-course-ghc-8.8.4-env/bin/hoogle' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' to change the priority of one of the conflicting packages (0 being the highest priority)
```
2020-11-25 18:42:50 +13:00
Hamish Mackenzie e729389f32 Add otherShells arg to shellFor (#937)
Makes it easier to include cross compilation shells.  The
buildInputs and nativeBuildInputs of the shells are added.
2020-11-24 16:28:45 +13:00
Hamish Mackenzie c3f4882bf7 Add cross compile cabal wrapper (#936)
Adds a `${targetPrefix}cabal` script to `shellFor` that passes the
necessary `--with-X` args to `cabal.

Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io>
2020-11-24 13:37:49 +13:00
Eric Wolf 0c3abc8a6d Allow for hoogle to be materialized in shellFor (#902)
Allow for hoogle to be materialized in `shellFor` by using `tools.hoogle` when passed in.

Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@googlemail.com>
2020-10-31 20:46:54 +13:00
Michael Peyton Jones 2db0b60816 Fix dependency filtering for shellFor (#819)
I had to refactor this a bit to understand what was going on, but the
kicker is two changes:
- `removeSelectedInput` was only removing *library* components. This was
fine when we were only looking at the `all` components, since they
always dependend on libraries. But now we're looking at all kinds of
components, and these can, for example, depend on internal libraries.
So we need to filter out dependencies on *any* component, not just a
library component. This fixes https://github.com/input-output-hk/haskell.nix/issues/818
- The filtering on `nativeBuildInputs` was wrong, since it was using the
filtering function that filters *packages*, not the one that filters
*derivations*. I didn't observe this causing a bug but it seems wrong.
2020-08-14 14:06:22 +12:00
Hamish Mackenzie b6de6ef3b8 Remove components.all (#776)
It causes a lot of issues. To make this work:

* `shellFor` is updated to use `getAllComponents` instead of `.all`.
* `getAllComponents` is updated to work on the package rather than
  the package config.
* Tests updated to not use `.library` or `.exes.X` where appropriate.
* Documentation updated.
* Out of date examples removed.

As a bonus `shellFor` now takes a `components` argument that might be
useful for limiting the dependencies of the shell to just the ones
needed for the components you intend to work on.
2020-07-21 16:06:54 +12:00
Hamish Mackenzie 4cac8bd00f Remove internal deps on default ghc and stackage (#738)
Changes to the interface of haskell.nix (from the changelog.md file):

* Removed `sources.nixpkgs-default`, use `sources.nixpkgs` instead.
* Removed `./nixpkgs` directory, use  `(import ./. {}).sources`
  or `./nix/sources.nix` instead.
* Removes V1 interface for details on how to fix old code see:
    https://github.com/input-output-hk/haskell.nix/issues/709
* Removed defaultCompilerNixName.
* cabalProject, cabalProject', hackage-project and hackage-package
  now require a `compiler-nix-name` argument.
* `haskell-nix.tool` and `.tools` now require a `compiler-nix-name` argument.
  New functions `p.tool` and `p.tools` (where p is a project) do not.
  Like `shellFor { tools = ... }` they will use the compiler nix name
  from the project (including stack projects where it is derived from
  the resolver).
* `haskell-nix.alex` and `haskell-nix.happy` have been removed. Use
  `p.tool "alex" "3.2.5"` or `shellFor { tools = { alex = "3.2.5"; } }`.
* `haskell-nix.nix-tools` -> `haskell-nix.nix-tools.ghc883` (it includes
  the hpack exe now).
* `haskell-nix.cabal-install` -> 
  `p.tool "cabal" "3.2.0.0"` or `shellFor { tools = { cabal = "3.2.0.0"; } }`
* `haskell-nix.haskellNixRoots` -> `haskell-nix.roots ghc883` or `p.roots`

Other changes:

Adds hpack executable to the nix-tools derivations.

Adds a `cabal-hpack` test to make sure `hpack` works with
`cabalProject`.

Reduces the number of calls to `cabalProject` (particularly when
checking materialization), by giving internal tools a per-compiler
attribute.

Uses happy 1.19.12 when building newer ghc versions.

Updates cabal-install 3.2.0.0 to use the source from github that
is compatible with ghc 8.10.1.

Updates the docs for callCabalProjectToNix.

Adds a license mapping to fix a common warning.
2020-07-08 22:54:01 +12:00
Guillaume Desforges 7fec2a157c Fix #742 : packages in additional in shellFor are indeed added and displayed by ghc-pkg list as per documentation specification (#743) 2020-07-03 10:19:53 +12:00
Hamish Mackenzie 5291959d28 Add propagatedBuildInputs to shell (#717)
Now that the pkgconfig inputs are here we need this to make them
show up in the shell.  Also adds gtkglext pkgconfig mapping.
2020-06-21 19:40:14 +12:00
Hamish Mackenzie 9c6eb16428 Fix propagation of pkgconfig and frameworks (#715)
pkgconfig-depends that make use of propagatedBuildInputs and frameworks
are not propagated to the exe component that links them. This seems
to be because our libraries do not not include their dependencies
as `buildInputs`.  To make this work it also seems to be necessary
for pkgconfig depends themselves to be `propagaedBuildInputs`.
2020-06-21 16:40:52 +12:00
Hamish Mackenzie 5ebce0eb3c Make it easier to access executable components (#565)
This overlay helps accessing common executable components.
Typically we want to make these available in a nix-shell
created with shellFor.  In most cases the package name
will be the same as the executable, but we have a
`toolPackageName` mapping to help when it is not.

```
# To get a single tool:
haskell-nix.tool "cabal" "3.2.0.0"

# This does the same thing as:
(haskell-nix.hackage-package {
  name = "cabal-install"
  version = "3.2.0.0"
}).components.exes.cabal

# To get an attr set containing multiple tools:
haskell-nix.tools { cabal = "3.2.0.0"; hlint = "2.2.11"; }

# To add tools to a shell:
shellFor { tools = { cabal = "3.2.0.0"; hlint = "2.2.11"; }; }
```

When used in shellFor the tools will be compiled with the same version
of ghc used in the shell (the build ghc in the case of cross
compilation).

Instead of a version string we can use an attr set containing
arguments that will be passed to `cabalProject`.

For instance to specify the ghc used to compile. Use:

```
haskell-nix.tool "cabal" {
  version = "3.2.0.0";
  ghc = haskell-nix.compiler.ghc883;
}
```
2020-04-29 19:10:14 +12:00
Hamish Mackenzie a39b5a741a Add NIX_GHC_LIBDIR to shellFor (like nixpkgs does) (#559)
Tools like ghcide use this to find the correct global package db.
2020-04-24 15:48:55 +12:00
Hamish Mackenzie 775c8cf756 Fix cross compilation issues for musl and aarch64 (#322)
* Enables tests for Musl and AArch64 (also rasbery pi, but leaves them disabled for now) and includes many fixes for the tests that were broken.

* Makes Musl cross compiler more like native (including making `ghci` and `runghc` work)

* Updates selection of enableShared

* Works around missing configFiles attribute issue

* Use ghc-extra-packages and compiler.nix-name to pick the right extra packages

* Leaves out --cross-compile on hsc2hs for musl

* Fixes haddock and hoogle for musl and disables them for other cross compilers

* Adds ghc 8.8.3

* Static link components (except libraries and `all`) on musl

* Use qemu for the arm cross compile `testWrapper`

* Add isCrossHost and isCrossTarget functions

* Fixes profiling on AArch64

* Disable split sections when compiling for windows (fixes GHC 8.8 cross compile to windows)

* Disable hoogle in cross compiler shells for now
2020-03-04 16:07:01 +13:00
Moritz Angermann f5b150c98a build ghcjs (#382)
Adds `ghcjs` to haskell.nix

Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@googlemail.com>
Co-authored-by: Michael Bishop <cleverca22@gmail.com>
2020-02-09 20:03:22 +08:00
Rodney Lorrimar 686fa37877 shellFor: Fix bug where packages were not excluded from the env (#285)
* tests: Add regression test for shellFor build-tools bug

* tests: Fix regen script

* Regenerate nix expressions for tests

* tests: ghc 8.4.4 -> 8.6.5

* shellFor: Fix bug where packages were not excluded from the env

If a multi-package project had an build-tools dependency between
packages, they would not be correctly removed from the shell's inputs.
2019-11-01 20:08:31 +10:00
Hamish Mackenzie 94f4679618 Add setup-depends to shellFor (#259)
* Add failing test for shellFor with setup-depends

* Add setup-depends to shellFor
2019-10-13 20:01:25 +08:00
Rodney Lorrimar b47a6bb1a2 shellFor: Use CABAL_CONFIG only with exactDeps = true (#255)
* shellFor: Use CABAL_CONFIG only with exactDeps = true

* shells: Put write-ghc-environment-files: never in cabal.config
2019-10-13 19:43:17 +08:00
Hamish Mackenzie fdcb2da2a8 Add default for shellFor packages (#242)
Uses the `isLocal` for property set by `plan-to-nix` and `stack-to-nix`
on packages where the source is referenced in the `cabal.project`
or `stack.yaml` file.
2019-10-01 11:10:11 +13:00
Rodney Lorrimar f81a37eda4 Make sure hoogle is available in ghcWithHoogle (#196) 2019-07-16 10:17:49 +10:00
Rodney Lorrimar 0663a9cd03 Add ghcWithPackages and ghcWithHoogle to hsPkgs (#150)
* Add ghcWithPackages and ghcWithHoogle to hsPkgs

* tests: Add ghcWithHoogle test

* Update changelog
2019-06-21 22:40:08 +10:00
Rodney Lorrimar c6038d4860 shellFor: Update don't overwrite passthru (#180) 2019-06-15 08:24:17 +02:00
Jean-Baptiste Giraudeau 3fb220334f Fix name of shellFor derivation for a single package. (#155) 2019-05-30 22:46:39 +02:00
Rodney Lorrimar c69cf9ed60 shellFor: Add the hoogle index 2019-05-28 10:53:05 +10:00
Rodney Lorrimar bbd0133281 shellFor: Provide correct dependencies
Now the shell provides the dependencies of the given Haskell packages,
and not the packages themselves.

System libraries and Haskell executables are added to the shell.
2019-05-28 09:34:38 +10:00
Rodney Lorrimar 49eb3279e4 shellFor: provide CABAL_CONFIG in shell 2019-05-28 09:34:38 +10:00
Rodney Lorrimar 4ecc0aa041 Add config.hsPkgs.shellFor function
I needed to rearrange a few things to write this function.
2019-05-28 09:34:38 +10:00