Coder Social home page Coder Social logo

haskell-multi-nix's Introduction

haskell-multi-nix

Just a simple demo of Nixifying a multi-package Haskell project.

Packages

This project has two local Haskell packages:

  1. foo: a Haskell library exporting Foo.fooFunc.
  2. bar: a Haskell executable that depends on foo

To build the foo library:

nix build .#foo

To build the bar executable:

nix build

To run the executable:

nix run

Dev Shell

The Nix development shell (nix develop) allows you to run the various cabal commands on the local packages.

For example, this will compile and run the main executable:

nix develop -c cabal -- run bar

How it works

The nixpkgs tree

The nixpkgs release tag uses raw functions from nixpkgs.

The Haskell infrastructure in nixpkgs provides a package set (an attrset) called pkgs.haskellPackages1. We add two more packages -- foo and bar (the local packages) -- to this package set. We do this by using the standard nixpkgs overlay API (specifically extend, which was created by the implicit makeExtensible) defined in fixed-points.nix. After having added the local packages, the result is a new package set, which is no different in essense to the original package set (we can also put our dependency overrides in the same, or different, overlay). Note that any package in a package set can depend on any other packages; thus, it becomes possible to make bar depend on foo (see "build-depends" in ./bar/bar.cabal) even though they come from the same overlay.

The master tree

The master branch uses haskell-flake which abstracts much of what we explained above, such that your flake.nix is as small as possible.

Footnotes

  1. The package set pkgs.haskellPackages corresponds to the default GHC version. Non-default GHC versions have their own package sets, for e.g.: pkgs.haskell.packages.ghc924 is the package set for GHC 9.2.4. โ†ฉ

haskell-multi-nix's People

Contributors

hariamoor-professional avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.