Please, can you help expand the documentation on shellFor
Anton-Latukha opened this issue · 3 comments
In Nixpkgs section, shellFor
seems important to load the HIE
into environment.
(wrapper) Nixpkgs available info
shellFor
use documentation is nonexistent in Nixpks, all we have is raw written at creation explanation, with one example in the source code:
# Returns a derivation whose environment contains a GHC with only
# the dependencies of packages listed in `packages`, not the
# packages themselves. Using nix-shell on this derivation will
# give you an environment suitable for developing the listed
# packages with an incremental tool like cabal-install.
# In addition to the "packages" arg and "withHoogle" arg, anything that
# can be passed into stdenv.mkDerivation can be included in the input attrset
#
# # default.nix
# with import <nixpkgs> {};
# haskellPackages.extend (haskell.lib.packageSourceOverrides {
# frontend = ./frontend;
# backend = ./backend;
# common = ./common;
# })
#
# # shell.nix
# let pkgs = import <nixpkgs> {} in
# (import ./.).shellFor {
# packages = p: [p.frontend p.backend p.common];
# withHoogle = true;
# buildInputs = [ pkgs.python ];
# }
#
# -- cabal.project
# packages:
# frontend/
# backend/
# common/
#
# bash$ nix-shell --run "cabal new-build all"
# bash$ nix-shell --run "python"
./pkgs:master◦>rg shellFor
pkgs/development/haskell-modules/generic-builder.nix
516: # All this information is intended just for `shellFor`. It should be
556: # Attributes for the old definition of `shellFor`. Should be removed but
pkgs/development/haskell-modules/make-package-set.nix
274: # (import ./.).shellFor {
288: shellFor = { packages, withHoogle ? false, ... } @ args:
pkgs/test/default.nix
25: haskell-shellFor = callPackage ./haskell-shellFor { };
pkgs/test/haskell-shellFor/default.nix
3:haskellPackages.shellFor {
nixos/doc/manual/release-notes/rl-2003.xml
938: Haskell <varname>env</varname> and <varname>shellFor</varname> dev shell environments now organize dependencies the same way as regular builds.
So in Nixpkgs there essentially no trivial or any working examples of how to use it.
HNix has a have pretty neatty setup: https://github.com/haskell-nix/hnix
All it has is:
shell.nix
####
{} @ attrs: (import ./. attrs).env
I played around and so far did not found a way to make attached shellFor
work there.
Not everyone knows how to use shellFor
, Internet has only a couple of threads that mention it.
What would be good, to point the uses for shellFor
code section, at least where it goes (for example shell.nix
, and how).
Thank you.
I'm a bit low on time right now, but for hnix's structure it could work like this (I'll add an explanation to all-hies readme later):
diff --git a/default.nix b/default.nix
index f683f9b..0d2c61b 100644
--- a/default.nix
+++ b/default.nix
@@ -1,7 +1,7 @@
{
# Compiler in a form ghc8101 == GHC 8.10.1, just remove spaces and dots
# 2020-07-05: By default using default GHC for Nixpkgs, see https://search.nixos.org/packages?query=ghc&from=0&size=500&channel=unstable for current version (currently ghc883 == GHC 8.8.3)
- compiler ? "ghc884"
+ compiler ? "ghc883"
# Deafult.nix is a unit package abstraciton that allows to abstract over packages even in monorepos:
# Example: pass --arg cabalName --arg packageRoot "./subprojectDir", or map default.nix over a list of tiples for subprojects.
@@ -101,7 +101,14 @@
if useRev
# Do not guard with hash, so the project is able to use current channels (rolling `rev`) of Nixpkgs
then import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz") {}
- else import <nixpkgs> {}
+ else import <nixpkgs> {
+ overlays = [
+ (import (fetchTarball {
+ url = "https://github.com/infinisil/all-hies/tarball/09ba836904fa290b5e37d5403150ea0c921661fb";
+ sha256 = "0qbjqv1fkhkx1cffqybz1mfks1jphh0vh3zd8ad2qd6lch4gyys4";
+ }) {}).overlay
+ ];
+ }
// {
# Try to build dependencies even if they are marked broken.
config.allowBroken = true;
@@ -213,7 +220,7 @@ let
# 2020-06-26 Due to a behaviour change in neat-interpolation-0.4, we
# require n-i >= 0.4. dontCheck helps us avoid conflicts with
# neat-interpolation's test dependencies.
- neat-interpolation = pkgs.haskell.lib.dontCheck super.neat-interpolation_0_5_1_1;
+ neat-interpolation = pkgs.haskell.lib.dontCheck super.neat-interpolation_0_5_1;
# 2020-07-23 hnix uses multiple functions that are unavailable in
# data-fix < 0.3.
@@ -270,5 +277,9 @@ let
# composePackage = foldr (if switch then function) (package) ([{switch,function}]) == (functionN .. (function1 package))
composedPackage = pkgs.lib.foldr (onSwitchApplyFunc) package listSwitchFunc;
-in composedPackage
+ env = composedPackage.env.overrideAttrs (old: {
+ nativeBuildInputs = old.nativeBuildInputs ++ [ haskellPackages.hie ];
+ });
+
+in composedPackage // { inherit env; }
Unfortunately I seem to run into haskell/haskell-ide-engine#1520 with this.
❤️ In your wisdom Infinisil
, thank you greatly.
Actually a step forward for me/us and our processes.