Nixos configuration: `environment.systemPackages` cannot find haskellPackages - haskell

I can find haskell packages via nix-env:
nix-enf -f "<nixpkgs>" -qaP -A haskellPackages
...
yet when I try and install them using environment.systemPackages in /etc/nixos/configuration.nix:
environment.systemPackages = with pkgs; [
haskellPackages.haskellPlatform
];
I get the error:
error: attribute 'haskellPlatform' missing, at /etc/nixos/configuration.nix:54:5
Any ideas? I am intending on using xmonad and want to do haskell dev'.

haskellPlatform has been removed with the update to GHC 7.8.2, see the mailing list thread for more details.
You should be able to install any package found via nix-enf -f "<nixpkgs>" -qaP -A haskellPackages to environment.systemPackages.
Searching for haskellPackages.haskellPlatform with nix-env should result in the same kind of error that you get during the rebuild:
nix-env -f "<nixpkgs>" -qaP -A haskellPackages.haskellPlatform
error: attribute ‘haskellPlatform’ in selection path ‘haskellPackages.haskellPlatform’ not found
Any valid haskell package can be installed in the environment, for example xmobar:
environment.systemPackages = with pkgs; [
haskellPackages.xmobar
];

Related

Nix unable to build Haskell with packages

When I try to run
nix-shell -p "haskellPackages.ghcWithPackages (p: [p.brick])"
I receive the following error
these derivations will be built:
/nix/store/14r35fzyw3y7mqzdzifbm9sd0599b1cl-ghc-8.6.5-with-packages.drv
building '/nix/store/14r35fzyw3y7mqzdzifbm9sd0599b1cl-ghc-8.6.5-with-packages.drv'...
/nix/store/k7yalpjh53xra535xaip1pfq6q4jgsc0-stdenv-linux/setup: line 822: /build/env-vars: No such file or directory
unpacking sources
/nix/store/k7yalpjh53xra535xaip1pfq6q4jgsc0-stdenv-linux/setup: line 822: /build/env-vars: No such file or directory
variable $src or $srcs should point to the source
builder for '/nix/store/14r35fzyw3y7mqzdzifbm9sd0599b1cl-ghc-8.6.5-with-packages.drv' failed with exit code 1
Notice that this does not happen if I pass an empty list of packages, so nix-shell itself works.
I tried to reinstall nix-env -i ghc but the error persists

Trying to follow declarative package management fails

I am trying to achieve a simple declarative package management solution.
I have a clean nixos installation on virtualbox (thanks to this vagrant solution )
I am following the following subsection in the nixos manual
I do
mkdir -p ~/.config/nixpkgs/
vi ~/.config/nixpkgs/config.nix
such that cat ~/.config/nixpkgs/config.nix would now give:
{
packageOverrides = pkgs: with pkgs; {
myPackages = pkgs.buildEnv {
name = "my-packages";
paths = [ aspell bc coreutils gdb ffmpeg nixUnstable emscripten jq nox silver-searcher ];
};
};
}
And now,
nix-env -iA nixpkgs.myPackages outputs:
error: attribute ‘nixpkgs’ in selection path ‘nixpkgs.myPackages’ not found
I have also tried
nix-env -f. -iA nixpkgs.myPackages
nix-env -iA nixos.myPackages
nix-env -f. -iA nixos.myPackages
And all fail similarly.
What is a simple example of a package declaration in nixos? In this case, it seems like it tries to achieve a certain set of packages installed for a given user . I would not mind a declaration that applies to all users, but would prefer something for a given user (for future use).
EDIT: Here is the outputs when trying to get nix-info
[vagrant#nixbox:~]$ nix-shell -p nix-info --run nix-info
error: undefined variable ‘nix-info’ at (string):1:66
(use ‘--show-trace’ to show detailed location information)
[vagrant#nixbox:~]$ nix-shell -p nix-info --run nix-info --show-trace
error: while evaluating the attribute ‘nativeBuildInputs’ of the derivation ‘shell’ at /nix/store/5cd5ac78p0yy47yi5ml12s690bl5lsh8-nixos-16.09.1389.d7a3160/nixos/pkgs/build-support/trivial-builders.nix:10:14:
while evaluating ‘optionals’ at /nix/store/5cd5ac78p0yy47yi5ml12s690bl5lsh8-nixos-16.09.1389.d7a3160/nixos/lib/lists.nix:185:21, called from /nix/store/5cd5ac78p0yy47yi5ml12s690bl5lsh8-nixos-16.09.1389.d7a3160/nixos/pkgs/stdenv/generic/default.nix:204:16:
while evaluating ‘chooseDevOutputs’ at /nix/store/5cd5ac78p0yy47yi5ml12s690bl5lsh8-nixos-16.09.1389.d7a3160/nixos/lib/attrsets.nix:463:22, called from /nix/store/5cd5ac78p0yy47yi5ml12s690bl5lsh8-nixos-16.09.1389.d7a3160/nixos/pkgs/stdenv/generic/default.nix:161:22:
undefined variable ‘nix-info’ at (string):1:66
[vagrant#nixbox:~]$

How can I install a Haskell library to be accessible via GHCi with Nixos?

I've managed to install ghc with nix-env -i ghc.
I'd like to install a Haskell library now, how should this be done? For example the turtle (https://hackage.haskell.org/package/turtle) library.
I've run nix-env -f "<nixpkgs>" -iA haskellPackages.turtle, however running ghci and import Turtle fails:
Prelude> import Turtle
<no location info>: error:
Could not find module ‘Turtle’
It is not a module in the current program, or in any known package.
Output of ghc-pkg list:
/nix/store/fvf278s3lqsjv488ahhdi8jx6i0qzsr9-ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
Cabal-1.24.2.0
array-0.5.1.1
base-4.9.1.0
binary-0.8.3.0
bytestring-0.10.8.1
containers-0.5.7.1
deepseq-1.4.2.0
directory-1.3.0.0
filepath-1.4.1.1
ghc-8.0.2
ghc-boot-8.0.2
ghc-boot-th-8.0.2
ghc-prim-0.5.0.0
ghci-8.0.2
haskeline-0.7.3.0
hoopl-3.10.2.1
hpc-0.6.0.3
integer-gmp-1.0.0.1
pretty-1.1.3.3
process-1.4.3.0
rts-1.0
template-haskell-2.11.1.0
terminfo-0.4.0.2
time-1.6.0.1
transformers-0.5.2.0
unix-2.7.2.1
xhtml-3000.2.1
This works differently on NixOS because of purity. NixOS' GHC will only look at its own immutable installation directory and the packages that have been installed by the user with cabal install.
What you can do is install into your user profile a GHC wrapper that supplies a nice set of packages when you run ghci.
Create a file my-ghc.nix:
(import <nixpkgs> {}).haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
lens
aeson
turtle
])
Uninstall your previous attempt, to avoid name collisions:
nix-env -e ghc turtle
Install the wrapped GHC:
nix-env -if my-ghc.nix
You may edit the file in the future and re-run that command.
When I am working on a project, I prefer to use cabal2nix and nix-shell. (For an introduction, see Oliver Charles' blog post)
As an alternative Robert's answer, one can use a nix-shell environment by creating a shell.nix file with contents of:
{ pkgs ? import <nixpkgs> {} }:
let myGhc = pkgs.haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
turtle
]);
in
pkgs.mkShell {
buildInputs = [ myGhc ];
}
And entering this environment with nix-shell.
Alternatively this single command nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [pkgs.turtle])".

XMonad on Nix - cannot find xmonad-contrib

I am trying to use nix on ubuntu, with XMonad as my window manager.
I have this working well on one host using nixOS, but I have a second device that isn't yet ready for nixOS. nix on top of Ubuntu is mostly working well there, but xmonad cannot find contributory libraries.
The relevant packages are installed:
$ nix-env -q | grep xmonad
xmonad-0.13
xmonad-contrib-0.13
xmonad-extras-0.12.1
But recompiling my xmonad.hs, it cannot find the contrib libs:
$ xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs
xmonad.hs:32:1: error:
Failed to load interface for ‘XMonad.Layout.NoBorders’
Use -v to see a list of the files searched for.
...
Please check the file for errors.
The relevant files are installed:
$ ls /nix/store/*xmonad-contrib*/lib/**/NoBorders*
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.hi
By adding xmonad-contrib to my nixpkgs config.nix, I have gotten these libs added to the ghc package registry:
$ cat ~/.config/nixpkgs/config.nix
with (import <nixpkgs> {});
{
packageOverrides = pkgs: with pkgs; {
myHaskellEnv = pkgs.haskellPackages.ghcWithPackages (haskellPackages: with haskellPackages; [ xmonad-contrib ]);
};
}
$ nix-env -iA nixpkgs.myHaskellEnv
$ ghc-pkg list | grep xmonad
xmonad-0.13
xmonad-contrib-0.13
$
with this, this ghc(i) works well:
$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/ghc ~/.xmonad/xmonad.hs
[1 of 1] Compiling Main ( /home/martyn/.xmonad/xmonad.hs, /home/martyn/.xmonad/xmonad.o ) [flags changed]
Linking /home/martyn/.xmonad/xmonad ...
But even the version of xmonad in that dir cannot find the libs:
$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs
xmonad.hs:32:1: error:
Failed to load interface for ‘XMonad.Layout.NoBorders’
Use -v to see a list of the files searched for.
I can work around this by compiling using the ghc as above, and moving the output by hand to ~/.xmonad/xmonad-x86_64-linux, and running that. But this is a wee bit hacky, and surely shouldn't be necessary?
A friend solved this for me offline, I reproduce this here for others with the same issue.
Essentially, we need to use xmonad-with-packages, and list the packages, rather than ghc-with-packages.
To achieve this, we provide our own xmonad, referenced from within ~/.nixpkgs/config.nix:
{
packageOverrides = pkgs_: with pkgs_; {
xmonad = import ./xmonad { nixpkgs = pkgs_; };
};
}
And fill out ~/.nixpkgs/xmonad/default.nix thus:
{ nixpkgs ? import <nixpkgs> {} }:
nixpkgs.xmonad-with-packages.override {
packages = hPkgs: with hPkgs; [ xmonad-contrib ];
}
This installs an xmonad that knows where to find its libraries, and everything's good!

Installation of Haskell Package Euterpea fails on NixOs

Unfortunately, the installation of the haskell package 'Euterpea' fails on NixOS:
The Nixpkgs manual states that all haskell packages registered on hackage (which the Euterpea package is) are included in the nix package manager and have to be installed like this:
nix-env -f "<nixpkgs>" -iA haskellPackages.Euterpea
After some downloading and compiling, the following error occurs, and the process is interrupted:
[ 7 of 46] Compiling Euterpea.IO.MIDI.MidiIO ( Euterpea/IO/MIDI/MidiIO.lhs, dist/build/Euterpea/IO/MIDI/MidiIO.o )
Euterpea/IO/MIDI/MidiIO.lhs:153:25:
Not in scope: ‘Heap.extractHead’
Euterpea/IO/MIDI/MidiIO.lhs:160:34: Not in scope: ‘Heap.head’
builder for ‘/nix/store/wc8d02s0kin4l0siwixlylssizfsrzgx-Euterpea-1.1.1.drv’ failed with exit code 1
error: build of ‘/nix/store/wc8d02s0kin4l0siwixlylssizfsrzgx-Euterpea-1.1.1.drv’ failed
Does anyone have an idea how to fix this?
The problem here is that Euterpea does not compile against the more-recent versions of its dependencies available in nixpkgs. Here is an expression that can succcessfully build Euterpea (tested on current nixpkgs unstable):
Write the following nix expression into a file called euterpea.nix:
# let's get nixpkgs into scope
with (import <nixpkgs> {});
let
lib = haskell.lib;
# build a "package set" (collection of packages) that has the correct versions of the dependencies
# needed by Euterpea
customHaskellPackages = haskellPackages.override (old: {
overrides = self: super: {
heap = self.callHackage "heap" "0.6.0" {};
PortMidi = self.callHackage "PortMidi" "0.1.5.2" {};
stm = self.callHackage "stm" "2.4.2" {};
};
});
in {
# this is a ghc wrapper that has only Euterpea as its visible packages
ghc = customHaskellPackages.ghcWithPackages (pkgs: [ pkgs.Euterpea ]);
# this is just the output of the build for Euterpea
pkg = customHackagePackages.Euterpea;
# for convenience, also expose the package set that we build against
pkgset = customHaskellPackages;
}
Then you can run the following commands:
$ nix-build euterpea.nix -A ghc # build a GHC with the Euterpea package included
/nix/store/mjlp6rxcsiv5w8ay1qp0lrj8m40r3cyl-ghc-8.0.1-with-packages
$ result/bin/ghci # result contains a GHC installation that has Euterpea, so we can run GHCI from it
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/.ghci
λ: import Euterpea
λ:
Leaving GHCi.
$ nix-env --install --file euterpea.nix -A ghc # we can also install this ghc into our user environment
installing ‘ghc-8.0.1-with-packages’
building path(s) ‘/nix/store/7jwrwxaxyig6hf747rsan5514gw7qi51-user-environment’
created 5840 symlinks in user environment
$

Resources