mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-28 01:05:02 +08:00
56 lines
1.4 KiB
Text
56 lines
1.4 KiB
Text
= Access to a Haskell package defined in a flake (without using a `.cabal` file)
|
|
|
|
////
|
|
$ mkdir tempwork
|
|
$ cd tempwork
|
|
$ cp ../flake.nix .
|
|
$ git add flake.nix
|
|
$ nix develop
|
|
$ git add flake.lock
|
|
$ git commit -a -m temp
|
|
////
|
|
|
|
Occasionally you might want to run a short Haskell program that depends on a Haskell library,
|
|
but you don't want to bother writing a cabal file.
|
|
In this example we will access a Haskell package called `pandoc-columns`)
|
|
that is defined in a flake in a remote git repo.
|
|
|
|
[NOTE]
|
|
====
|
|
For non-trivial Haskell development projects,
|
|
it's usually more convenient to use `haskell-flake` as described in <<#haskell-flake>>,
|
|
together with the _high-level workflow_ described in <<_development_workflows>>.
|
|
====
|
|
|
|
[source,nix,linenums,highlight='5,8,12,17']
|
|
.flake.nix
|
|
....
|
|
include::flake.nix[]
|
|
....
|
|
|
|
Line 5 adds `pandoc-columns` as an input to this flake.
|
|
Line 8 allows the output function to reference `pandoc-columns`.
|
|
Line 12 makes a custom GHC that knows about `pandoc-columns`,
|
|
and line 17 uses the custom GHC as a build input for this flake.
|
|
|
|
Here's a short Haskell program that uses the new flake.
|
|
|
|
[source,haskell,linenums]
|
|
.Main.hs
|
|
....
|
|
include::Main.hs[]
|
|
....
|
|
|
|
Here's a demonstration using the program.
|
|
|
|
....
|
|
$ runghc Main.hs # Fails; dependency not available
|
|
$# start-shell nix develop <<EOL
|
|
$ runghc Main.hs # Works in development environment
|
|
$# EOL
|
|
....
|
|
|
|
////
|
|
Good adoc0 scripts clean up after themselves.
|
|
$ cd .. ; rm -rf tempwork # clean up
|
|
////
|