This commit is contained in:
Amy de Buitléir 2025-09-15 14:49:11 +01:00
parent c25a0c2650
commit e2aa713c19
7 changed files with 143 additions and 196 deletions

View file

@ -1900,7 +1900,7 @@ location of the executable, if we&#8217;re curious.</p>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ which hello-flake
/nix/store/qskl8ajlgnl654fhgsmv74yv8x9r3kzg-hello-flake/bin/hello-flake</pre>
/nix/store/y0i81pxnbrg8jpvqp886b4lrzh7wb0ni-hello-flake/bin/hello-flake</pre>
</div>
</div>
<div class="paragraph">
@ -1910,7 +1910,7 @@ directly available.</p>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ exit
$ hello-flake # Won't work outside development shell
$ hello-flake # Fails outside development shell
bash: line 24: hello-flake: command not found</pre>
</div>
</div>
@ -1921,7 +1921,7 @@ that the package remains in the store for future use.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ /nix/store/qskl8ajlgnl654fhgsmv74yv8x9r3kzg-hello-flake/bin/hello-flake
<pre class="nowrap">$ /nix/store/y0i81pxnbrg8jpvqp886b4lrzh7wb0ni-hello-flake/bin/hello-flake
Hello from your flake!</pre>
</div>
</div>
@ -2825,7 +2825,7 @@ Here&#8217;s the modified <code>hello-flake</code> file.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ ./hello-flake # Won't work
<pre class="nowrap">$ ./hello-flake # Fails
./hello-flake: line 3: cowsay: command not found</pre>
</div>
</div>
@ -2974,7 +2974,7 @@ $ exit</pre>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run # Won't work
<pre class="nowrap">$ nix run # Fails
warning: Git tree '/home/amy/codeberg/nix-book/source/modify-hello-flake/hello-flake' is dirty
/nix/store/rnjqkk7a8sz6wrm1qb1hxssy7qlgaa85-hello-flake/bin/hello-flake: line 3: cowsay: command not found</pre>
</div>
@ -3172,7 +3172,7 @@ don&#8217;t need to <code>git push</code> the changes until we&#8217;re ready to
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ git commit hello-flake flake.nix -m 'added bovine feature'
[main a10700e] added bovine feature
[main cb77c4d] added bovine feature
2 files changed, 13 insertions(+), 1 deletion(-)
$ nix run
________________________
@ -3381,7 +3381,7 @@ You can come back to this section later to learn more.</p>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix shell nixpkgs#ghc
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
Main.hs:1:1: error: [GHC-87110]
Could not find module Network.HostName.
@ -3400,7 +3400,7 @@ Let&#8217;s exit that shell and try again, this time adding the <code>hostname</
<div class="content">
<pre class="nowrap">$ exit
$ nix shell nixpkgs#ghc nixpkgs#hostname
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
Main.hs:1:1: error: [GHC-87110]
Could not find module Network.HostName.
@ -3423,7 +3423,7 @@ The package we want is in the <em>package set</em> called <code>haskellPackages<
<div class="content">
<pre class="nowrap">$ exit
$ nix shell nixpkgs#ghc nixpkgs#haskellPackages.hostname
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
Main.hs:1:1: error: [GHC-87110]
Could not find module Network.HostName.
@ -3770,7 +3770,7 @@ warning: creating lock file '"/home/amy/codeberg/nix-book/source/new-flake/haske
• Added input 'haskell-flake':
'github:srid/haskell-flake/2acbf1c9bb7aac38b59dcc3c1bd78911cf37e42c?narHash=sha256-jwZT6Ns4BXlrFHaXjZgZwfhSaw8nTCTKZ8fCDylrONM%3D' (2025-09-14)
• Added input 'nixpkgs':
'github:nixos/nixpkgs/6d7ec06d6868ac6d94c371458fc2391ded9ff13d?narHash=sha256-fEvTiU4s9lWgW7mYEU/1QUPirgkn%2BodUBTaindgiziY%3D' (2025-09-13)
'github:nixos/nixpkgs/88cef159e47c0dc56f151593e044453a39a6e547?narHash=sha256-kYhNxLlYyJcUouNRazBufVfBInMWMyF%2B44xG/xar2yE%3D' (2025-09-14)
warning: Git tree '/home/amy/codeberg/nix-book/source/new-flake/haskell-flake/hello-haskell' is dirty</pre>
</div>
</div>
@ -3788,6 +3788,11 @@ The important thing for now is that the build succeeded.</p>
<div class="content">
<pre class="nowrap">$ nix run
warning: Git tree '/home/amy/codeberg/nix-book/source/new-flake/haskell-flake/hello-haskell' is dirty
these 2 derivations will be built:
/nix/store/b67dd3m503q30yiwfgav3xzz88bb91h4-hello-flake-haskell-source-1.0.0.drv
/nix/store/bgjyjh7282728b2qff37ldygg80zk4m1-hello-flake-haskell-1.0.0.drv
building '/nix/store/b67dd3m503q30yiwfgav3xzz88bb91h4-hello-flake-haskell-source-1.0.0.drv'...
building '/nix/store/bgjyjh7282728b2qff37ldygg80zk4m1-hello-flake-haskell-1.0.0.drv'...
Hello from Haskell inside a Nix flake!
Your hostname is: wombat11k</pre>
</div>
@ -3807,7 +3812,7 @@ We need to add this to the repo, and commit all important files.</p>
<div class="content">
<pre class="nowrap">$ git add flake.lock
$ git commit -a -m 'initial commit'
[master (root-commit) d35f8fd] initial commit
[master (root-commit) c64c57a] initial commit
5 files changed, 170 insertions(+)
create mode 100644 LICENSE
create mode 100644 Main.hs
@ -4009,7 +4014,7 @@ First we&#8217;ll try building the package manually.
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ python -m build # Won't work
<pre class="nowrap">$ python -m build # Fails
/nix/store/iyff8129iampdw13nlfqalzhxy8y1hi9-python3-3.13.6/bin/python: No module named build</pre>
</div>
</div>
@ -4212,7 +4217,7 @@ something like this.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix build # Won't work
<pre class="nowrap">$ nix build # Fails
error: Path 'flake.nix' in the repository "/home/amy/codeberg/nix-book/source/new-flake/python-flake/hello-python" is not tracked by Git.
To make it visible to Nix, run:
@ -4236,7 +4241,7 @@ warning: creating lock file '"/home/amy/codeberg/nix-book/source/new-flake/pytho
• Added input 'flake-utils/systems':
'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09)
• Added input 'nixpkgs':
'github:NixOS/nixpkgs/5ad881b15fb2b63c2f127533ca59f840fcc24c3f?narHash=sha256-P8XdKg87fR5PpCjIgMH%2B05PDwhdmlNrigsvChdHfyaw%3D' (2025-09-14)
'github:NixOS/nixpkgs/dd16e0b60390586a261a4e28fc180a91212fe010?narHash=sha256-yM1FFsRiyESij/lzbdBMCUoFOKMoShHu0CAexnBWzTM%3D' (2025-09-15)
warning: Git tree '/home/amy/codeberg/nix-book/source/new-flake/python-flake/hello-python' is dirty</pre>
</div>
</div>
@ -4254,6 +4259,9 @@ The important thing for now is that the build succeeded.</p>
<div class="content">
<pre class="nowrap">$ nix run
warning: Git tree '/home/amy/codeberg/nix-book/source/new-flake/python-flake/hello-python' is dirty
this derivation will be built:
/nix/store/kr0aywqsm9v8ds4mc909iaan2yaqmjq3-hello-flake-python.drv
building '/nix/store/kr0aywqsm9v8ds4mc909iaan2yaqmjq3-hello-flake-python.drv'...
Hello from inside a Python program built with a Nix flake!</pre>
</div>
</div>
@ -4272,7 +4280,7 @@ We need to add this to the repo, and commit all important files.</p>
<div class="content">
<pre class="nowrap">$ git add flake.lock
$ git commit -a -m 'initial commit'
[master (root-commit) 2af9bd5] initial commit
[master (root-commit) deac9ed] initial commit
4 files changed, 127 insertions(+)
create mode 100644 flake.lock
create mode 100644 flake.nix
@ -4655,7 +4663,7 @@ sanitized: &lt;strong&gt;some text&lt;/strong&gt;</pre>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ cowsay "Moo!" # Won't work; dependency not available
<pre class="nowrap">$ cowsay "Moo!" # Fails; dependency not available
bash: line 17: cowsay: command not found
$ nix develop
$ cowsay "Moo!" # Works in development environment
@ -4780,7 +4788,7 @@ we see that this flake provides both a package and an app called <code>hello</co
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ hello-flake # Won't work; dependency not available
<pre class="nowrap">$ hello-flake # Fails; dependency not available
bash: line 40: hello-flake: command not found
$ nix develop
$ hello-flake # Works in development environment
@ -4885,18 +4893,23 @@ together with the <em>high-level workflow</em> described in <a href="#_developme
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ runghc Main.hs # Won't work; dependency not available
<pre class="nowrap">$ runghc Main.hs # Fails; dependency not available
Main.hs:1:1: error: [GHC-87110]
Could not find module Data.List.Extra.
Could not find module Text.Pandoc.Filters.Columns.
Use :set -v to see a list of the files searched for.
|
1 | import Data.List.Extra
| ^^^^^^^^^^^^^^^^^^^^^^
1 | import Text.Pandoc.Filters.Columns
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$ nix develop
$ runghc Main.hs # Works in development environemnt
"abcde"
"XYZ"</pre>
Main.hs:1:1: error: [GHC-87110]
Could not find module Text.Pandoc.Filters.Columns.
Use :set -v to see a list of the files searched for.
|
1 | import Text.Pandoc.Filters.Columns
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</pre>
</div>
</div>
</div>
@ -5461,7 +5474,7 @@ Hello from your flake!</pre>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-15 14:41:47 IST
Last updated 2025-09-15 14:48:12 IST
</div>
</div>
</body>

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

@ -1,142 +0,0 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1756770412,
"narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "4524271976b625a4a605beefd893f270620fd751",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"haskell-flake": {
"locked": {
"lastModified": 1756607542,
"narHash": "sha256-+99fEAk0HwjYgIW2tEOs7ayBDxnU9NAM5E29ZxgyX40=",
"owner": "srid",
"repo": "haskell-flake",
"rev": "73e3891fb135c679a1c30fae4b101e5b41b8ca61",
"type": "github"
},
"original": {
"owner": "srid",
"repo": "haskell-flake",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1757942231,
"narHash": "sha256-yM1FFsRiyESij/lzbdBMCUoFOKMoShHu0CAexnBWzTM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dd16e0b60390586a261a4e28fc180a91212fe010",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1756911493,
"narHash": "sha256-6n/n1GZQ/vi+LhFXMSyoseKdNfc2QQaSBXJdgamrbkE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c6a788f552b7b7af703b1a29802a7233c0067908",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pandoc-columns": {
"inputs": {
"flake-parts": "flake-parts",
"haskell-flake": "haskell-flake",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1757244346,
"narHash": "sha256-Ewpv8f+CvF0du1egjRJoeOZhKsdoqPkb2ecrwTPI+os=",
"path": "/home/amy/github/pandoc-columns",
"type": "path"
},
"original": {
"path": "/home/amy/github/pandoc-columns",
"type": "path"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"pandoc-columns": "pandoc-columns"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,22 +0,0 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
pandoc-columns.url = "/home/amy/github/pandoc-columns";
};
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; [ pandoc-columns ]);
in
{
devShells = rec {
default = pkgs.mkShell {
buildInputs = [ customGhc ];
};
};
}
);
}

View file

@ -56,9 +56,9 @@ this is done in line 15.
Here's a demonstration using the shell.
....
$ hello-nix # this will fail
$ hello-nix # Fails outside development shell
$# ../../../../../start-shell nix develop <<EOL
$ hello-nix
$ hello-nix # Works inside development shell
$# EOL
....

View file

@ -0,0 +1,77 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"hello-nix": {
"flake": false,
"locked": {
"lastModified": 1757705465,
"narHash": "sha256-sJCQ9+8Dy+QF9ISaupp42+mGbuXtFyqbX85tWzeNPOI=",
"ref": "refs/heads/main",
"rev": "56044f61231c996e4ab795de1da89e5f79db3f4f",
"revCount": 5,
"type": "git",
"url": "https://codeberg.org/mhwombat/hello-nix"
},
"original": {
"type": "git",
"url": "https://codeberg.org/mhwombat/hello-nix"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1757942231,
"narHash": "sha256-yM1FFsRiyESij/lzbdBMCUoFOKMoShHu0CAexnBWzTM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dd16e0b60390586a261a4e28fc180a91212fe010",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"hello-nix": "hello-nix",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -0,0 +1,27 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
hello-nix = {
url = "git+https://codeberg.org/mhwombat/hello-nix";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, hello-nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
helloNix = import hello-nix { inherit pkgs; };
in
{
devShells = rec {
default = pkgs.mkShell {
packages = [ helloNix ];
};
};
}
);
}