Haskell: Difference between revisions

imported>Tobias.bora
No edit summary
imported>Tobias.bora
No edit summary
Line 118: Line 118:


However as I understand I guess that you will not be able to enter the shell before `mylibrary` fully compiles… hence the need for `shellFor` to work simultaneously on multiple projects.
However as I understand I guess that you will not be able to enter the shell before `mylibrary` fully compiles… hence the need for `shellFor` to work simultaneously on multiple projects.
Note that you may want to add tools needed either at compile time or a library at run time. For that, you can use the <code>modifier</code> field that is an arbitrary function to apply to the final haskell package (in particular you can apply the <code>overrideCabal</code> that we saw above). Notably, you can add nativeBuildInputs using [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/lib/compose.nix#L156 pkgs.haskell.lib.addBuildTools] and buildInputs using [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/lib/compose.nix#L159 pkgs.haskell.lib.addExtraLibraries] (for those of you that are curious to see how they are used in the final derivation, see [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/generic-builder.nix#L653 here]):
<syntaxhighlight lang="nix">
let
  pkgs = import <nixpkgs> { }; # pin the channel to ensure reproducibility!
in
pkgs.haskellPackages.developPackage {
  root = ./.;
  modifier = drv:
    pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
      [ cabal-install
        ghcid
      ]);
}
</syntaxhighlight>


You can also get more details in [https://srid.ca/haskell-nix this tutorial] or in [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/make-package-set.nix#L230 pkgs/development/haskell-modules/make-package-set.nix].
You can also get more details in [https://srid.ca/haskell-nix this tutorial] or in [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/make-package-set.nix#L230 pkgs/development/haskell-modules/make-package-set.nix].
Line 239: Line 255:




Note that <code>overrideCabal</code> takes as input the old package and the new attributes of the new package and outputs the new package.
Note that <code>overrideCabal</code> takes as input the old package and the new attributes of the new package and outputs the new package. To see the full list of parameters that can be overridden, you can refer to [https://github.com/NixOS/nixpkgs/blob/0ba44a03f620806a2558a699dba143e6cf9858db/pkgs/development/haskell-modules/generic-builder.nix#L13 this file].  


Because some operations are very common, there exists some functions that call <code>overrideCabal</code> for you. For instance if you only want to disable checks and test suits for a package you can do <code>mypackage = pkgs.haskell.lib.dontCheck super.mypackage</code> and the above code also shows how to mark a package as unbroken. These functions are listed and documented in [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib/compose.nix pkgs/development/haskell-modules/lib/compose.nix].
Because some operations are very common, there exists some functions that call <code>overrideCabal</code> for you. For instance if you only want to disable checks and test suits for a package you can do <code>mypackage = pkgs.haskell.lib.dontCheck super.mypackage</code> and the above code also shows how to mark a package as unbroken. These functions are listed and documented in [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib/compose.nix pkgs/development/haskell-modules/lib/compose.nix].