Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building project1 with cabal fails with dependency error #20

Open
m-renaud opened this issue Jul 13, 2017 · 14 comments
Open

Building project1 with cabal fails with dependency error #20

m-renaud opened this issue Jul 13, 2017 · 14 comments

Comments

@m-renaud
Copy link

When trying to build project1 using the "Building with cabal" instructions from the project0 readme I get an error about it being unable to resolve dependencies.

Steps to reproduce

$ git clone https://github.com/Gabriel439/haskell-nix.git
$ cd haskell-nix/project1/
$ nix-build release0.nix
<snip:1>
$ ./result/bin/project1
Hello, world!
# Success! Works with nix-build.
$ nix-shell -A project1 release0.nix
$ cabal configure
Resolving dependencies...
Warning: solver failed to find a solution:
Could not resolve dependencies:
trying: project1-1.0.0 (user goal)
next goal: turtle (dependency of project1-1.0.0)
Dependency tree exhaustively searched.
Trying configure anyway.
Configuring project1-1.0.0...
cabal: Encountered missing dependencies:
turtle -any

So nix-build is able to resolve the turtle dependency but cabal configure is not. The steps above work when building and running project0 though.

Shell Output

snip:1 Output from nix-build release0.nix (irrelevant lines removed)
Full output at https://gist.github.com/m-renaud/b497478c059a79112393aeb015739730

these derivations will be built:
  /nix/store/lxk22wmjmwf2xadrw7pm37k80m9lcnql-project1-1.0.0.drv
<dropped>
Configuring project1-1.0.0...
Dependency base <5: using base-4.9.1.0
Dependency turtle -any: using turtle-1.3.6
Using Cabal-1.24.2.0 compiled by ghc-8.0
Using compiler: ghc-8.0.2
<dropped>
Installing executable(s) in
/nix/store/81gy6a8m1iin193507qyr580i2mj6n77-project1-1.0.0/bin
<dropped>

Versions

$ nix-build --version
nix-build (Nix) 1.11.11
$ nix-shell -A project1 release0.nix --run "cabal --version"
cabal-install version 1.24.0.2
compiled using version 1.24.2.0 of the Cabal library 
$ nix-shell -A project1 release0.nix --run "ghc --version"
The Glorious Glasgow Haskell Compilation System, version 8.0.2
@m-renaud
Copy link
Author

Looked into this some more today. On one machine that I have that's running Ubuntu 16.04 I need to enter nix-shell, run cabal install, and then run cabal configure, then everything works.

Strangely, on another machine I have that's running Ubuntu 14.04 I need to run cabal install from outside nix-shell and then run cabal configure from within nix-shell. If I try to run cabal install inside nix-shell then it fails (I don't have that machine on me right now so I don't have the exact error message).

In hindsight, of course you need to run cabal install but I haven't used cabal directly in quite some time.

But anyways, if the docs included instructions to run cabal install before configure then that would clear things up.

@Gabriella439
Copy link
Owner

The root of the problem is that you need to use project1.env instead of project1, like this:

$ nix-shell -A project1.env release0.nix

Then cabal configure and cabal build will work inside that nix-shell

@m-renaud
Copy link
Author

Ah interesting. That's non-intuitive that if you use the incorrect attribute the nix shell will starts successfully but commands will fail. Your explanation in #19 really helped as well.

I think I assumed that the -A argument for nix-build and nix-shell would be the same. My understanding now is that starting a shell with attribute project1.env will drop you into the environment that all the Haskell deps live in (since all Haskell package derivations have an env attribute where everything lives). Starting a shell with project1 on the other hand will not put you in an environment that contains the packages of any sub-records within that expression (env for example).

Is my understanding somewhat correct? (Apologies if these are more Nix questions and less "Haskell Nix" questions).

@Gabriella439
Copy link
Owner

I don't know the reason why there are two separate derivations for building the project and the shell and I don't know why the default derivation (i.e. project1 without the .env) doesn't work as an argument to nix-shell

@zoranbosnjak
Copy link

I have just reinstalled nix (under ubuntu 16.04) and have the same problem. I have used argument project1.env as suggested, but the problem remains. It does however work well on another machine, same ubuntu 16.04, but with older nix version 1.11.9 and cabal version 1.24.0.2.
It looks like something is different with the current version of cabal and/or nix.

$ cd project1
$ nix-env --version
nix-env (Nix) 1.11.15
$ nix-shell -A project1.env release0.nix
$ cabal --version
cabal-install version 2.0.0.0
compiled using version 2.0.0.2 of the Cabal library 
$ cabal configure
Resolving dependencies...
Warning: solver failed to find a solution:
Could not resolve dependencies:
trying: project1-1.0.0 (user goal)
unknown package: turtle (dependency of project1-1.0.0)
fail (backjumping, conflict set: project1, turtle)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: project1, turtleTrying configure
anyway.
Configuring project1-1.0.0...
cabal: Encountered missing dependencies:
turtle -any

@Gabriella439
Copy link
Owner

@zoranbosnjak: What is the output of ghc-pkg list when run from inside the nix-shell?

@zoranbosnjak
Copy link

$ cd project1
$ nix-shell -A project1.env release0.nix
$ ghc-pkg list
/nix/store/nkcbv48v229p0k545bj4ip2dnrwxymsn-ghc-8.0.2-with-packages/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

@Gabriella439
Copy link
Owner

What is the output of these commands?

$ git status
$ cat project1/release0.nix
$ cat project1/default.nix

@zoranbosnjak
Copy link

The status is clean.
I have run some more tests (by pinning nixpkgs release on another server) and found out that the problem was present on nixpkgs release f2a76b6c292866e887684a2e7cf0b1e75ffb80cf and fixed with release 89f5d52cf44baec14a7f542a605243777b16e7a5 or later. It looks like my initial test was performed on unfortunate moment when the nixpkgs was at one of the problematic releases.

How can I check what version of nixpkgs is in use (if I don't explicitly pin the version)?

@Gabriella439
Copy link
Owner

@zoranbosnjak: Not that I know of. The problem is that the nixpkgs channel doesn't appear to have revision information stored in it

You can get the path to the <nixpkgs> path by doing this:

$ nix-instantiate --eval --expr '<nixpkgs>'

... which (if you are not pinning nixpkgs) will usually be the same as ~/.nix-defexpr/channels/nixpkgs

@cumber
Copy link

cumber commented Sep 23, 2017

@zoranbosnjak The root of a channel should have a file svn-revision in it (which actually identifies a git revision). e.g.

$ cat $(nix-instantiate --eval --expr '<nixpkgs>')/svn-revision
116054.a75265924f

The second part of that is the git commit hash in the nixpkgs repository (or a prefix of it, but a unique one)

@vyp
Copy link

vyp commented Sep 23, 2017

@zoranbosnjak nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion

@zoranbosnjak
Copy link

Thanks for all useful answers!
It is clear now, that the reason for my problem was nixpkgs state (and not the cabal/nix version). According to git log, the problem was introduced with nixpkgsrelease 7f8ff024372f985e96b438fa5591d9b43fc6e7bd and fixed (reverted) with release 89f5d52cf44baec14a7f542a605243777b16e7a5. My nixpkgs is at release d0d905668c010b65795b57afdf7f0360aac6245b, which is between the 2 releases.

Just one more question...
How can I update nixpkgs of my profile to a specific git release?
nix-channel --update does not provide any option to specify a release. It would probably update to the latest (?) release.

@vyp
Copy link

vyp commented Sep 24, 2017

nix-channel --update will update just your channel. You can see what git revision each channel is at by looking at the branches at https://github.com/NixOS/nixpkgs-channels.

For actually setting nixpkgs to a specific git revision, check out NixOS/nixpkgs#27994. Although I suggest not setting it to anything newer than the unstable branches at https://github.com/NixOS/nixpkgs-channels so that you still get binary downloads, instead of having to compile everything (assuming you would want that), and a basic automated level of testing (from my knowledge channels only get updated if a particular set of their packages build successfully, even if there are newer nixpkgs commits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants