Search code examples
nixnixosnix-shell

What's the shortest `shell.nix` equivalent of the following cmdline arguments?


What's the shortest shell.nix equivalent of the following cmdline arguments?

nix-shell -p "haskell.packages.ghc865.ghcWithPackages (p: [p.ghci-pretty])"

This works, but it's verbose:

# contents of shell.nix file
# run with the following cmd:
# nix-shell shell.nix
{ nixpkgs ? import <nixpkgs> {} }:
let
  inherit nixpkgs;
  inherit (nixpkgs) haskellPackages;
  haskellDeps = a: with a; [
    ipprint
    base
    hscolour
    ghci-pretty
  ];
  ghc = nixpkgs.haskellPackages.ghcWithPackages haskellDeps;

  nixPackages = [
    haskellPackages.cabal-install
    ghc
  ];
in
nixpkgs.stdenv.mkDerivation {
  name = "profile_name";
  buildInputs = nixPackages;
}

Solution

  • You can just copy your command line verbatim like so:

    { pkgs ? import <nixpkgs> {} }:
    let
      ghc = pkgs.haskell.packages.ghc865.ghcWithPackages (p: [ p.ghci-pretty ]);
    in
    pkgs.mkShell {
      buildInputs = [ ghc ];
    }