mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-28 01:05:02 +08:00
43 lines
880 B
Text
43 lines
880 B
Text
= A Haskell library package in the nixpkgs repo (without a `.cabal` file)
|
|
|
|
////
|
|
$ mkdir tempwork
|
|
$ cd tempwork
|
|
$ cp ../flake.nix ../Main.hs .
|
|
$ 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.
|
|
|
|
Example: Access the `containers` package from the `haskellPackages` set in the nixpkgs repo.
|
|
|
|
[source,nix,linenums,highlight='11,16']
|
|
.flake.nix
|
|
....
|
|
include::flake.nix[]
|
|
....
|
|
|
|
Here's a short Haskell program that uses it.
|
|
|
|
[source,haskell,linenums]
|
|
.Main.hs
|
|
....
|
|
include::Main.hs[]
|
|
....
|
|
|
|
Here's a demonstration using the program.
|
|
|
|
....
|
|
$# ../../../../../start-shell nix develop <<EOL
|
|
$ runghc Main.hs
|
|
$# EOL
|
|
....
|
|
|
|
////
|
|
Good adoc0 scripts clean up after themselves.
|
|
$ cd .. ; rm -rf tempwork # clean up
|
|
////
|