From 1d79997fe148d2c7790f728394ab259600ffbb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amy=20de=20Buitl=C3=A9ir?= Date: Mon, 15 Sep 2025 18:31:23 +0100 Subject: [PATCH] temp --- index.html | 4 +- .../recipes/devshell/haskell-flake/flake.nix | 45 ++++++---------- .../recipes/devshell/haskell-flake/main.adoc0 | 53 ++++++++++--------- source/recipes/devshell/haskell-pkg/Main.hs | 6 +-- .../recipes/devshell/haskell-pkg/main.adoc0 | 6 +-- .../devshell/haskell-pkg/tempwork/Main.hs | 6 --- .../devshell/haskell-pkg/tempwork/flake.lock | 6 +-- 7 files changed, 55 insertions(+), 71 deletions(-) delete mode 100644 source/recipes/devshell/haskell-pkg/tempwork/Main.hs diff --git a/index.html b/index.html index c2b6bde..51b2d17 100644 --- a/index.html +++ b/index.html @@ -4894,7 +4894,7 @@ 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 it.

+

Here’s a short Haskell program that uses the new flake.

Main.hs
@@ -5644,7 +5644,7 @@ Hello from your flake!
diff --git a/source/recipes/devshell/haskell-flake/flake.nix b/source/recipes/devshell/haskell-flake/flake.nix index b093b2a..331af5e 100644 --- a/source/recipes/devshell/haskell-flake/flake.nix +++ b/source/recipes/devshell/haskell-flake/flake.nix @@ -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 ]; + }; + }; + } + ); } diff --git a/source/recipes/devshell/haskell-flake/main.adoc0 b/source/recipes/devshell/haskell-flake/main.adoc0 index 14b1f51..5f4a8a1 100644 --- a/source/recipes/devshell/haskell-flake/main.adoc0 +++ b/source/recipes/devshell/haskell-flake/main.adoc0 @@ -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 <