diff --git a/index.html b/index.html index d1d15a4..597e153 100644 --- a/index.html +++ b/index.html @@ -172,14 +172,14 @@ @@ -4039,7 +4026,7 @@ including defining environments that you will use more than once.

10.1. Running programs directly (without installing them)

-

10.1.1. A top level package from the Nixpkgs/NixOS repo

+

10.1.1. Run a top level package from the Nixpkgs/NixOS repo

$ nix run nixpkgs#cowsay "Moo!"
@@ -4057,7 +4044,7 @@ including defining environments that you will use more than once.

10.1.2. Flakes

-
A flake defined in a local file
+
Run a flake defined in a local file
$ nix run ~/codeberg/hello-flake
@@ -4066,7 +4053,7 @@ Hello from your flake!
-
A flake defined in a remote git repo
+
Run a flake defined in a remote git repo
$ nix run git+https://codeberg.org/mhwombat/hello-flake
@@ -4093,7 +4080,7 @@ To run a specific branch, use the command below.

-
A flake defined in a zip archive
+
Run a flake defined in a zip archive
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip
@@ -4103,7 +4090,7 @@ Hello from your flake!
-
A flake defined in a compressed tar archive
+
Run a flake defined in a compressed tar archive
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz
@@ -4113,7 +4100,7 @@ Hello from your flake!
-
Other types of flake references
+
Run other types of flake references
@@ -4318,7 +4305,7 @@ sanitized: <strong>some text</strong>

10.4. Development shells

-

10.4.1. A top level package from the Nixpkgs/NixOS repo

+

10.4.1. Access a top level package from the Nixpkgs/NixOS repo

flake.nix
@@ -4385,7 +4372,7 @@ $ cowsay "Moo!"
-

10.4.2. A flake

+

10.4.2. Access a flake

In this example, we will use a flake defined in a remote git repo. However, you can use any of the flake reference styles defined in Section 10.1.2, “Flakes”.

@@ -4503,7 +4490,7 @@ Hello from your flake!
-

10.4.3. A Haskell library package in the nixpkgs repo (without a .cabal file)

+

10.4.3. Access a Haskell library package in the nixpkgs repo (without a .cabal file)

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.

@@ -4598,6 +4585,136 @@ $ runghc Main.hs "I have 3 cats, 2 dogs, and 0 zebras."
+
+
+

10.4.4. Access to a Haskell package on your local computer

+
+

Ex: Access three Haskell packages +(pandoc-linear-table, pandoc-logic-proof, and pandoc-columns) +that are on my hard drive.

+
+
+
flake.nix
+
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
{
+  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";
+  };
+  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;
+      };
+    };
+}
+
+
+
+
+
+

10.4.5. Set an environment variable

+
+

Set the value of the environment variable FOO to “bar”.

+
+
+
flake.nix
+
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
{
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs";
+    flake-utils.url = "github:numtide/flake-utils";
+  };
+
+  outputs = { self, nixpkgs, flake-utils }:
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = import nixpkgs { inherit system; };
+      in
+      {
+        devShells = rec {
+          default = pkgs.mkShell {
+            packages = [ pkgs.cowsay ];
+          };
+        };
+      }
+    );
+}
+
+
+

/// SKIP include::non-flake/main-generated.adoc[leveloffset=+1]

@@ -4648,131 +4765,6 @@ Hello from your flake!
-
-

10.6. Access to a Haskell package on your local computer

-
-

Ex: Access three Haskell packages -(pandoc-linear-table, pandoc-logic-proof, and pandoc-columns) -that are on my hard drive.

-
-
-

10.6.1. In shell.nix

-
-
shell.nix
-
-
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
-12
-13
-14
with (import <nixpkgs> {});
-let
-  pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {};
-  pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {};
-  pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {};
-in
-mkShell {
-  buildInputs = [
-                  pandoc
-                  pandoc-linear-table
-                  pandoc-logic-proof
-                  pandoc-columns
-                ];
-}
-
-
-
-
-
-
-

10.7. Access to a Haskell package on your local computer, with inter-dependencies

-
-

Ex: Access four Haskell packages -(pandoc-linear-table, pandoc-logic-proof, pandoc-columns and pandoc-maths-web) -that are on my hard drive. -The fourth package depends on the first three to build.

-
-
-

10.7.1. In shell.nix

-
-
shell.nix
-
-
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
-12
-13
-14
-15
-16
-17
-18
-19
with (import <nixpkgs> {});
-let
-  pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {};
-  pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {};
-  pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {};
-  pandoc-maths-web = haskellPackages.callCabal2nix "pandoc-maths-web" /home/amy/github/pandoc-maths-web
-                       {
-                         inherit pandoc-linear-table pandoc-logic-proof pandoc-columns;
-                       };
-in
-mkShell {
-  buildInputs = [
-                  pandoc
-                  pandoc-linear-table
-                  pandoc-logic-proof
-                  pandoc-columns
-                  pandoc-maths-web
-                ];
-}
-
-
-
-
-
-
-

10.8. Set an environment variable

-
-

Ex: Set the value of the environment variable FOO to “bar”

-
-
-

10.8.1. In shell.nix

-
-
shell.nix
-
-
1
-2
-3
-4
-5
-6
with (import <nixpkgs> {});
-mkShell {
-  shellHook = ''
-    export FOO="bar"
-  '';
-}
-
-
-
-
-
@@ -4787,7 +4779,7 @@ mkShell { diff --git a/source/recipes/devshell/env-var/main.adoc0 b/source/recipes/devshell/env-var/main.adoc0 new file mode 100644 index 0000000..be66c5e --- /dev/null +++ b/source/recipes/devshell/env-var/main.adoc0 @@ -0,0 +1,33 @@ += Set an environment variable + +//// +$ mkdir tempwork +$ cd tempwork +$ cp ../flake.nix flake.nix +$ git add flake.nix +$ nix develop +$ git add flake.lock +$ git commit -a -m temp +//// + +Set the value of the environment variable FOO to “bar”. + +[source,nix,linenums] +.flake.nix +.... +$# cat flake.nix +.... + +Here's a demonstration using the shell. + +.... +$ echo "FOO=$FOO" +$# ../../../../../start-shell nix develop < {}); -let - pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {}; - pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {}; - pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {}; - pandoc-maths-web = haskellPackages.callCabal2nix "pandoc-maths-web" /home/amy/github/pandoc-maths-web - { - inherit pandoc-linear-table pandoc-logic-proof pandoc-columns; - }; -in -mkShell { - buildInputs = [ - pandoc - pandoc-linear-table - pandoc-logic-proof - pandoc-columns - pandoc-maths-web - ]; -} diff --git a/source/recipes/haskell-local/shell/main.adoc0 b/source/recipes/haskell-local/shell/main.adoc0 deleted file mode 100644 index 95aae8c..0000000 --- a/source/recipes/haskell-local/shell/main.adoc0 +++ /dev/null @@ -1,9 +0,0 @@ -= In `shell.nix` - -[source,nix,linenums] -.shell.nix -.... -include::shell.nix[] -.... - -// TODO Add demo diff --git a/source/recipes/haskell-local/shell/shell.nix b/source/recipes/haskell-local/shell/shell.nix deleted file mode 100644 index abe3d85..0000000 --- a/source/recipes/haskell-local/shell/shell.nix +++ /dev/null @@ -1,14 +0,0 @@ -with (import {}); -let - pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {}; - pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {}; - pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {}; -in -mkShell { - buildInputs = [ - pandoc - pandoc-linear-table - pandoc-logic-proof - pandoc-columns - ]; -} diff --git a/source/recipes/main.adoc b/source/recipes/main.adoc index 2195ec5..35dbecc 100644 --- a/source/recipes/main.adoc +++ b/source/recipes/main.adoc @@ -21,9 +21,3 @@ include::shebang/main.adoc[leveloffset=+1] include::devshell/main.adoc[leveloffset=+1] include::nix-shell/main-generated.adoc[leveloffset=+1] - -include::haskell-local/main.adoc[leveloffset=+1] - -include::haskell-local-deps/main.adoc[leveloffset=+1] - -include::env-var/main.adoc[leveloffset=+1] diff --git a/source/recipes/run/main.adoc0 b/source/recipes/run/main.adoc0 index 679fe85..1d2830c 100644 --- a/source/recipes/run/main.adoc0 +++ b/source/recipes/run/main.adoc0 @@ -1,6 +1,6 @@ = Running programs directly (without installing them) -== A top level package from the Nixpkgs/NixOS repo +== Run a top level package from the Nixpkgs/NixOS repo .... $ nix run nixpkgs#cowsay "Moo!" @@ -9,13 +9,13 @@ $ nix run nixpkgs#cowsay "Moo!" [#flakeref] == Flakes -=== A flake defined in a local file +=== Run a flake defined in a local file .... $ nix run ~/codeberg/hello-flake .... -=== A flake defined in a remote git repo +=== Run a flake defined in a remote git repo .... $ nix run git+https://codeberg.org/mhwombat/hello-flake @@ -35,18 +35,18 @@ To run a specific branch and revision, use the command below. nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main&rev=d44728bce88a6f9d1d37dbf4720ece455e997606 .... -=== A flake defined in a zip archive +=== Run a flake defined in a zip archive .... $ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip .... -=== A flake defined in a compressed tar archive +=== Run a flake defined in a compressed tar archive .... $ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz .... -=== Other types of flake references +=== Run other types of flake references See https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes.