Skip to content

Nix integration is not supported in new-build. #4646

Open

Description

@ElvishJerricco

At least, the cabal-install one can compile with the current latest release tag (with GHC 8.2.1) does not support it.

Activity

  1. ElvishJerricco commented on Jul 31, 2017

    @ElvishJerricco
    Author

    It seems --config-file also does not work in new-build. Is there common global command line option logic not being used?

  2. 23Skidoo commented on Jul 31, 2017

    @23Skidoo
    Member
  3. ttuegel commented on Jul 31, 2017

    @ttuegel
    Member

    I intentionally did not implement Nix integration for the new-build command because it was yet somewhat unstable. Nix integration will be of limited utility with new-build, although it will be useful to manage foreign dependencies. Unfortunately, I do not expect I will have time to implement this feature soon.

  4. hvr commented on Jul 31, 2017

    @hvr
    Member

    Re --config-file, see #4649

  5. ElvishJerricco commented on Aug 3, 2017

    @ElvishJerricco
    Author

    @ttuegel What are the challenges involved in implementing this? Do you think it's a reasonable goal for someone like me who has never contributed to Cabal before?

  6. dcoutts commented on Aug 3, 2017

    @dcoutts
    Contributor

    What is the goal exactly for nix integration with new-build?

    To translate into nix exprs? To build C deps using nix? To do the whole build using the cabal CLI but use nix under the hood to do the builds?

  7. ElvishJerricco commented on Aug 3, 2017

    @ElvishJerricco
    Author

    In a cabal2nix issue, I briefly outlined a common workflow with Nix+Cabal that I use for single-package projects quite often. The goal (to me) would be to have Nix provide you with the GHC version and all your haskell dependencies, while allowing Cabal to do the incremental development work. The main reason is that Nix builds are much more suited for production than they are for development, while Nix shells are fantastic for development. So cabal new-build --enable-nix would enter a nix-shell to find the GHC it needs, which has a package database with all the necessary packages already present, and it would use that GHC to give you incremental compilation across packages in your project.

  8. dcoutts commented on Aug 3, 2017

    @dcoutts
    Contributor

    So having all of a project's non-local dependencies installed via nix means translating the project plan into nix exprs and using nix to execute that. It's hardly any more work to also be able to make nix exprs for building the local deps too, which would be super-useful for CI.

    BTW, I don't think single-package nix exprs really make sense for us, a project corresponds to a particular set of packages with particular configuration for them all. Or to put it another way, cabal new-build's nix integration / cabal2nix should really be whole-project not single package.

  9. ElvishJerricco commented on Aug 3, 2017

    @ElvishJerricco
    Author

    Not quite. The purpose of cabal2nix is to generate a Nix expression that just trusts whatever your nixpkgs.haskellPackages provides as its package set. This workflow does not use Cabal's dependency planning system whatsoever. Nixpkgs acts a bit like Stackage in this regard, and Cabal just becomes a great command line interface for incremental development over that.

  10. dcoutts commented on Aug 3, 2017

    @dcoutts
    Contributor

    Ok, whereas for cabal new-build, it'd ignore nixpkgs.haskellPackages and do exactly what your cabal.project file specifies (which itself can of course use stackage or any other collection) including the solver/planner.

  11. ElvishJerricco commented on Aug 3, 2017

    @ElvishJerricco
    Author

    No I don't think so. The point of using Nix with Haskell is to use Nix to define all your dependencies in a package set. Cabal should be doing no planning / solving, as that work is meant to be done by the nix expressions.

    I would expect it to work exactly how it does currently with cabal build. Currently, if my nix-shell provides a GHC with all my Haskell dependencies, I can do cabal configure from within that shell to configure cabal to use the dependencies from that environment, and I can use cabal build to do a local build depending on that nix environment.

  12. dcoutts commented on Aug 3, 2017

    @dcoutts
    Contributor

    Ok, so that's a completely different requirement and it's incompatible with cabal new-build and project files. We cannot use new-build to get nix to install all the deps when nix uses its own choice of configuration of those packages because then there is no guarantee that the configuration matches up with what we need for this project.

    The project file (+ solving & elaboration) determines the configuration of all the Haskell dependencies all the way down. It does not just pick versions but all details of the configuration (which it then hashes nix-style). We cannot arbitrarily substitute differently configured deps and expect it to work. The fact that the old build's nix integration code did this is no evidence that such a thing is possible. That approach was not deterministic and was easy to break for exactly these kinds of reasons.

  13. dcoutts commented on Aug 3, 2017

    @dcoutts
    Contributor

    There are three levels of integration I can imagine:

    1. Just use nix to build non-Haskell deps, like ghc and C libs etc, just as we might try to do with RPM or DEB based systems. Ie just treat it like any ordinary dumb system package manager.

    2. Generate nix expr(s) for the cabal project based on the exact config that the cabal new-build code would choose natively. This would work essentially by translating the new-build install plan into a nix expr. This would be a separate mode and would have no other CLI integration. It would be useful for doing CI for cabal projects via nix.

    3. Do 2. above but also include CLI integration so that under the hood the new-* commands use nix to execute the translated plan, rather than executing the plan directly as they do now. This would also allow entering a nix shell with all deps in the right configuration, but it'd also allow just running cabal commands directly and it'd use nix to build non-local deps.

  14. ElvishJerricco commented on Aug 3, 2017

    @ElvishJerricco
    Author

    To be totally clear, the point here isn't to use new-build for its Nix style build infrastructure. It's almost exclusively just needed as a means to build multi-package projects against a Nix environment, rather than any environment solved by Cabal. This is consistent with the workflow that is possible today with cabal build, which also uses Cabal exclusively for local incremental compilation and configuration, without any solving.

    I also don't believe it should be incompatible. I can actually emulate the desired effect just by manually entering a nix-shell and running the Cabal commands in there myself. new-build is more than happy to use whatever GHC you throw at it, including the packages that come with it. And it will correctly fail when one of those packages is outside the constraints in the cabal files. The point of this issue is merely that --enable-nix should enter that Nix shell itself.

  15. 36 remaining items

  16. Gabriella439 commented on Sep 5, 2019

    @Gabriella439
    Contributor

    If people don't object I'll try to summarize the discussion so far as somebody who has used all three of cabal/stack/Nix extensively:

    • Nix's Haskell support works similar to Stack, meaning:
      • Nixpkgs maintains a curated set of packages (analogous to a Stack resolver)
      • You can override a package within that package set to use a different version from Hackage (analogous to the extra-deps section of a stack.yaml file)
      • You can also add or override packages from GitHub or use a local source checkout of the package (similar to the packages section of a stack.yaml file)
      • Users typically prefer not to use Cabal's solver but can if they really want to (similar to Stack)
    • Nix's Haskell support differs from Stack in the following way:
      • Stack forces cabal to use its pinned dependencies using a giant cabal.config file (like this one)
      • Nix forces cabal to use its pinned dependencies by generating a wrapped GHC whose global package database contains those dependencies
    • Running all cabal-install commands inside of a nix-shell works with V1 commands and appears to work with V2 commands, too
      • I say "appears" because I haven't used V2 commands extensively in my own Nix+Haskell development, and I've only done some light testing
    • The V1 commands support a nix: True ~/.cabal/config flag which allowed the same commands to work outside of a nix-shell
      • It sounds like a small thing, but it's extremely convenient for Nix users
      • It also reduces user error since Cabal's Nix integration will regenerate the nix-shell any time you run cabal configure (either explicitly or implicitly as part of another cabal command that detected a configuration change)
    • The request here is to support the same nix: True configuration option for the V2 commands

    Feel free to correct me if I got anything wrong

  17. gbaz commented on Sep 5, 2019

    @gbaz
    Collaborator

    One further issue is that cabal v2 commands will always fetch and install packages that aren't in the db into the store, so you can't ensure you're only using the "closed universe" of packages made available into the custom pkgdb that nix builds. There are workarounds that can/should be integrated into nix scripts. In particular, setting a custom cabal_config env variable (as per here: #5322) can be used to prevent cabal from installing additional packages from hackage.

  18. j6carey commented on Sep 5, 2019

    @j6carey

    Following on the comments of @Gabriel439 and @gbaz :

    When I enter a nix-shell and then use cabal new-* (v2 commands), build tools required by my .cabal file seem to be built by cabal even if they are available from the nix-shell environment. In particular, any patches applied by Nix when building those build tools have no effect. Using v1 commands does not seem to have the same problem.

  19. quasicomputational commented on Sep 5, 2019

    @quasicomputational
    Contributor

    @gbaz, new in cabal-install 3.0, reject-unconstrained-dependencies allows you to restrict the solver to a closed set. It'd be a little bit cumbersome to repurpose for this, though - I guess you'd want to generate a cabal.project (or perhaps a freeze file?) with every package in the pkgdb that Nix creates.

  20. Ericson2314 commented on Sep 6, 2019

    @Ericson2314
    Collaborator

    IMO https://github.com/input-output-hk/haskell.nix is the future, and a much better friend of Cabal and stack in particular, and any future work on nix-cabal integration should focus on that.

    One goal in that regard is that Nix and Cabal should be able to hash files in the same way. I think the best thing to do is teach them both git tree hashes. Once we reach the point where hackage builds, patched hackage builds, and local builds are all cached with comparable keys, things will start to move smoothly.

  21. neongreen commented on Dec 3, 2019

    @neongreen

    The only goal of the existing Nix integration is:

    If we are doing a local build, and a Nix expression exists in the same directory as the .cabal file,
    then run cabal inside a nix-shell of that expression.

    Until this is solved in Cabal proper, you can use a workaround: nix-cabal.

    Installation:

    curl https://raw.githubusercontent.com/monadfix/nix-cabal/master/nix-cabal -o $HOME/.local/bin/nix-cabal
    chmod u+x $HOME/.local/bin/nix-cabal

    Then whenever I want a project to use nix-cabal, I create a .dir-locals.el file in the project root and Emacs picks nix-cabal up:

    ;; .dir-locals.el
    
    ((haskell-mode
      . ((haskell-process-type . cabal-new-repl)
         (haskell-process-path-cabal . "nix-cabal"))))

    In the shell, you just use nix-cabal foo instead of cabal foo, although you'll suffer the overhead of entering the nix-shell every time.


    Another solution is lorri. It runs a background daemon that keeps nix-shell warm, and uses direnv to automatically enter nix-shell whenever you are in the project directory. It is somewhat finicky, though.

  22. jneira commented on Mar 23, 2022

    @jneira
    Member

    I think facts has demonstrated nix integration in v2 build is at best a very low priority enhancement.
    This issue has a very interesting discussion on the topic but i would close it if you all dont mind. If anyone still thinks the nix integration should be done please raise a hand.

  23. Ericson2314 commented on Mar 23, 2022

    @Ericson2314
    Collaborator

    Last I checked (years ago) Cabal's (and Stack's) Nix integration wasn't really what I wanted as a Nix user anyways, so I don't mind if they whither away and are replaced with something more proper later.

  24. rnhmjoj commented on Mar 23, 2022

    @rnhmjoj

    Personally I've defined cabal = nix-shell --run "cabal $@" and this seems to be doing what I need, mostly. I still think it would be nicer to have this, so one can simply add nix: True to cabal/config.

  25. Ericson2314 commented on Mar 24, 2022

    @Ericson2314
    Collaborator

    Mmm while that is better than nothing, it is so far from adequate Nix support it feels like false advertising to call that nix: True to me.

  26. added
    cabal-install: v2-build system
    on Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked: info-neededcabal-install: nix integrationcabal-install: v2-build systemhistoricalstatus: consider closingtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions