Giter Site home page Giter Site logo

Comments (4)

kuznero avatar kuznero commented on June 30, 2024 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.

kuznero avatar kuznero commented on June 30, 2024 2

@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.

cumber avatar cumber commented on June 30, 2024 1

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.

Gabriella439 avatar Gabriella439 commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.