This commit is contained in:
Amy de Buitléir 2025-09-15 18:31:23 +01:00
parent d9eca11a6d
commit 1d79997fe1
7 changed files with 55 additions and 71 deletions

View file

@ -4894,7 +4894,7 @@ Line 12 makes a custom GHC that knows about <code>pandoc-columns</code>,
and line 17 uses the custom GHC as a build input for this flake.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s a short Haskell program that uses it.</p>
<p>Here&#8217;s a short Haskell program that uses the new flake.</p>
</div>
<div class="listingblock">
<div class="title">Main.hs</div>
@ -5644,7 +5644,7 @@ Hello from your flake!</pre>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-15 18:08:41 IST
Last updated 2025-09-15 18:09:24 IST
</div>
</div>
</body>

View file

@ -1,34 +1,21 @@
{
description = "Pandoc build system for maths web";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
haskell-flake.url = "github:srid/haskell-flake";
pandoc-linear-table.url = "/home/amy/github/pandoc-linear-table";
pandoc-logic-proof.url = "/home/amy/github/pandoc-logic-proof";
pandoc-columns.url = "/home/amy/github/pandoc-columns";
pandoc-query.url = "/home/amy/codeberg/pandoc-query";
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs@{ self, nixpkgs, flake-parts, pandoc-linear-table, pandoc-logic-proof, pandoc-columns, pandoc-query, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [ inputs.haskell-flake.flakeModule ];
perSystem = { self', pkgs, ... }: {
haskellProjects.default = {
# use my versions of some Haskell pagkages instead of the nixpkgs versions
packages = {
pandoc-linear-table.source = inputs.pandoc-linear-table;
pandoc-logic-proof.source = inputs.pandoc-logic-proof;
pandoc-columns.source = inputs.pandoc-columns;
pandoc-query.source = inputs.pandoc-query;
};
};
# haskell-flake doesn't set the default package, but you can do it here.
packages.default = self'.packages.pandoc-maths-web;
};
};
outputs = { self, nixpkgs, flake-utils, pandoc-columns }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
customGhc = pkgs.haskellPackages.ghcWithPackages (p: with p; [ extra ]);
in
{
devShells = rec {
default = pkgs.mkShell {
buildInputs = [ customGhc ];
};
};
}
);
}

View file

@ -1,4 +1,4 @@
= Access to a Haskell package defined in a flake
= Access to a Haskell package defined in a flake (without using a `.cabal` file)
////
$ mkdir tempwork
@ -10,43 +10,46 @@ $ 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.
In this example we will access three Haskell packages
(`pandoc-linear-table`, `pandoc-logic-proof`, and `pandoc-columns`)
that are defined as flakes on my hard drive.
We are using `haskell-flake`, so the development environment is
set up automatically; no need to define `devShells`.
[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]
[source,nix,linenums,highlight='5,8,12,17']
.flake.nix
....
include::flake.nix[]
....
Here's a demonstration using the shell.
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
$ cabal info pandoc-columns
$ runghc Main.hs # Works in development environemnt
$# EOL
....
FINISH
FINISH
FINISH
FINISH
FINISH
FINISH
FINISH
FINISH
////
Good adoc0 scripts clean up after themselves.
$ cd .. ; rm -rf tempwork # clean up

View file

@ -1,6 +1,6 @@
import Text.Pandoc.Filters.Columns
import Data.List.Extra
main :: IO ()
main = do
putStrLn "Prove we have access to the pandoc-columns package"
print $ defaultColSpec
print $ lower "ABCDE"
print $ upper "XYZ"

View file

@ -1,10 +1,10 @@
= Access a Haskell library package in the nixpkgs repo (without a `.cabal` file)
= Access a Haskell library package in the nixpkgs repo (without using a `.cabal` file)
////
$ mkdir tempwork
$ cd tempwork
$ cp ../flake.nix ../Main.hs .
$ git add Main.hs flake.nix
$ cp ../flake.nix .
$ git add flake.nix
$ nix develop
$ git add flake.lock
$ git commit -a -m temp

View file

@ -1,6 +0,0 @@
import Text.Pandoc.Filters.Columns
main :: IO ()
main = do
putStrLn "Prove we have access to the pandoc-columns package"
print $ defaultColSpec

View file

@ -53,11 +53,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1757952092,
"narHash": "sha256-BcfTLFCU7elUJ2dwyt0iTjxsz/XLh+8ZygDcFwy6xPE=",
"lastModified": 1757957081,
"narHash": "sha256-7iLovveMGL0xWKV/nBC3L+pgtu/U1ZFdEXz+eCy77GQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fd76dc9e7c68ac7c3941ba2af2bedcd79c5cf4ed",
"rev": "594ab976eb33dca9723f7db7b77892456da50813",
"type": "github"
},
"original": {