Comments (4)
@cumber thanks a lot! I ended up extending your shell.nix
slightly to pin nixpkgs
. So now it looks much cleaner and most importantly uses cabal
packages 👍
{ compiler ? "ghc821"
, withHoogle ? true
}:
let
bootstrap = import <nixpkgs> {};
nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
src = bootstrap.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (nixpkgs) rev sha256;
};
pkgs = import src {};
f = import ./default.nix;
packageSet = pkgs.haskell.packages.${compiler};
hspkgs = (
if withHoogle then
packageSet.override {
overrides = (self: super: {
ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
ghcWithPackages = self.ghc.withPackages;
});
}
else packageSet
);
drv = hspkgs.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
from haskell-nix.
@Gabriel439, so far I ended up including additional hoogle.nix
:
{ compiler ? "ghc821" }:
let
bootstrap = import <nixpkgs> {};
nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
src = bootstrap.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (nixpkgs) rev sha256;
};
pkgs = import src { };
in
with pkgs;
runCommand "shell" {
buildInputs = [
( haskell.packages.${compiler}.ghcWithHoogle ( ps: with ps; [
data-default
] ) )
];
} ""
This file needs to be modified every time dependencies change (at least every time developer needs documentation on another dependency he/she is using). In addition there is a simple hoogle.sh
bash script that simply starts hoogle server:
#!/usr/bin/env bash
nix-shell hoogle.nix --command "hoogle server -p 8080 --local --haskell"
This has a bit of code duplication to re-use pinned nixpkgs
coming from nixpkgs.json
(similar to release.nix
), but this way it at least is connected to exact version developer is using.
This works kind of on the side from shell.nix
, default.nix
and release.nix
. Another thing I was thinking is to modify default.nix
to accept additional boolean flag that will override ghc
with ghcWithPackages
, but then it will also need to add it to buildDepends
which is not so nice, as I would like to keep using the version of default.nix
generated for me by cabal2nix
. So, in the end of the day I think that inconvenience of rebuilding hoogle.nix
when dependencies change is an ok trade off, compare to changing default.nix
.
Though it would still be nice to enclose such things solely in shell.nix
.
You may find example project here.
from haskell-nix.
I've used this as my shell.nix in the past:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", withHoogle ? true }:
let
inherit (nixpkgs) pkgs;
f = import ./default.nix;
packageSet = (
if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler}
);
haskellPackages = (
if withHoogle
then packageSet.override {
overrides = (self: super:
{
ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
ghcWithPackages = self.ghc.withPackages;
}
);
}
else packageSet
);
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
It's designed to import a default.nix produced by cabal2nix . > default.nix
, without needing to manually update anything other than the cabal file. I suspect I'd do something cleaner with overlays if I was writing it now (I haven't used this particular setup for a little while).
The key idea is to override ghcWithPackages
to actually be ghcWithHoogle
, so that when the haskell helper nix code produces the env
attribute containing a suitable build environment, it pulls in a hoogle database as well as just the libraries.
from haskell-nix.
I don't know of an (easy) way to do this.
Normally the way you would do this for a package already in nixpkgs
is to do nix-shell --packages haskellPackages.ghcWithHoogle (pkgs : [ pkgs.someHaskellPackage ])
. However, nix-shell
doesn't have an easy way to change the package set while using the --packages
option. The way we work around this at work is to override nixpkgs
to use our own package set that is the same as nixpkgs
except with our own custom packages injected in.
from haskell-nix.
Related Issues (20)
- project0: README.md: Text talks about LICENSE file being placed, expiriencing different result
- Changing the compiler to ghc784 help needed HOT 10
- Add example of initializing a new project from scratch HOT 5
- Error: file 'nixpkgs' was not found in the Nix search path HOT 5
- Error builing `project1`/`release1` HOT 3
- dhall-nix? HOT 7
- morte-1.7.1 in nixpkgs-19.09 is marked as broken HOT 5
- Re-running `nix-build release0.nix` does not incorporate changes HOT 3
- stack shares builds of deps HOT 1
- Cabal new- commands
- [question] What does jailbreak mean exactly? HOT 1
- Bootstrapping a new project HOT 5
- Setup.hs error with defaultUserHooks HOT 4
- readme: broken link to cabal user's guide
- Development dependencies HOT 2
- Is this project up-to-date? Does the author still use this in production? HOT 1
- shell.nix should modernised.
- running in to "error: attribute 'lib' missing" while trying to nix-build release0.nix HOT 2
- Unable to Build project0 HOT 1
- $ nix-build release0.nix returns an error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haskell-nix.