@@ -2082,7 +2172,7 @@ and highlight some of the things I found confusing when I began using flakes.
@@ -2173,7 +2263,7 @@ Reference Manual.
- Although you probably won’t need to use it, there is another syntax for
+ Although you probably won’t need to use it, there is another syntax for
flake references that you might encounter. This example
@@ -2226,7 +2316,7 @@ dependency defined in the previous example.
That depends on the programming languages your software is written in,
the build system you use, and more. There are Nix functions and tools
that can simplify much of this, and new, easier-to-use ones are released
-regularly. We’ll look at some of these in the next section.
+regularly. We’ll look at some of these in the next section.
@@ -2243,7 +2333,7 @@ detail.
Flakes are written in the Nix programming language, which is a
functional language. As with most programming languages, there are many
ways to achieve the same result. Below is an example you can follow when
-writing your own flakes. I’ll explain the example in some detail.
+writing your own flakes. I’ll explain the example in some detail.
@@ -2290,7 +2380,7 @@ dependencies in the input section should also be listed at the beginning
of the outputs section ❷.
- Now it’s time to look at the content of the output section. If we want
+ Now it’s time to look at the content of the output section. If we want
the package to be available for multiple systems (e.g.,
“x86_64-linux”, “aarch64-linux”, “x86_64-darwin”, and
“aarch64-darwin”), we need to define the output for each of those
@@ -2302,7 +2392,7 @@ outputs for each one.
The devShells variable specifies the environment that should be
-available when doing development on the package. If you don’t need a
+available when doing development on the package. If you don’t need a
special development environment, you can omit this section. At ❹ you
would list any tools (e.g., compilers and language-specific build tools)
you want to have available in a development shell. If the compiler needs
@@ -2325,7 +2415,7 @@ were written or updated recently.
The apps variable identifies any applications provided by the flake.
In particular, it identifies the default executable ❻ that nix run
-will run if you don’t specify an app.
+will run if you don’t specify an app.
Below is a list of some functions that are commonly used in
@@ -2337,7 +2427,7 @@ this section.
The standard environment provides mkDerivation, which is especially
useful for the typical ./configure; make; make install scenario.
-It’s customisable.
+It’s customisable.
Python
@@ -2357,7 +2447,7 @@ standard environment version), developPackage, callCabal2Nix<
Now that we have a better understanding of the structure of flake.nix,
-let’s have a look at the one we saw earlier, in the hello-flake repo.
+let’s have a look at the one we saw earlier, in the hello-flake repo.
If you compare this flake definition to the colour-coded template
presented in the previous section, most of it should look familiar.
@@ -2397,13 +2487,13 @@ presented in the previous section, most of it should look familiar.
- This flake.nix doesn’t have a devShells section, because development
-on the current version doesn’t require anything beyond
+ This flake.nix doesn’t have a devShells section, because development
+on the current version doesn’t require anything beyond
the “bare bones” linux commands. Later we will add a feature that requires
additional development tools.
- Now let’s look at the section I labeled SOME UNFAMILIAR STUFF and
+ Now let’s look at the section I labeled SOME UNFAMILIAR STUFF and
see what it does.
@@ -2430,8 +2520,8 @@ see what it does.
This flake uses mkDerivation ❶ which is a very useful
general-purpose package builder provided by the Nix standard
-environment. It’s especially useful for the typical
-./configure; make; make install scenario, but for this flake we don’t
+environment. It’s especially useful for the typical
+./configure; make; make install scenario, but for this flake we don’t
even need that.
@@ -2446,7 +2536,7 @@ unpacked.
The buildPhase variable is a sequence of Linux commands to build the
package. Typically, building a package requires compiling the source
-code. However, that’s not required for a simple shell script. So
+code. However, that’s not required for a simple shell script. So
buildPhase consists of a single command, :,
which is a no-op or “do nothing” command.
@@ -2466,7 +2556,7 @@ Nix standard environment and the external dependencies identified in the
inputs section of the flake.
- I’ve mentioned the Nix standard environment before, but I didn’t explain
+ I’ve mentioned the Nix standard environment before, but I didn’t explain
what it is. The standard environment, or stdenv, refers to the
functionality that is available during the build and install phases of a
Nix package (or flake). It includes the commands listed
@@ -2551,7 +2641,7 @@ cannot rely on them.
8.1. The Nix development shell
- Let’s make a simple modification to the script. This will give you an
+ Let’s make a simple modification to the script. This will give you an
opportunity to check your understanding of flakes.
@@ -2565,15 +2655,15 @@ opportunity to check your understanding of flakes.
The flake.nix file specifies all of the tools that are needed during
development of the package. The nix develop command puts us in a shell
-with those tools. As it turns out, we didn’t need any extra tools
-(beyond the standard environment) for development yet, but that’s
+with those tools. As it turns out, we didn’t need any extra tools
+(beyond the standard environment) for development yet, but that’s
usually not the case. Also, we will soon need another tool.
A development environment only allows you to develop the package.
-Don’t expect the package outputs (e.g. executables) to be available
-until you build them. However, our script doesn’t need to be compiled,
-so can’t we just run it?
+Don’t expect the package outputs (e.g. executables) to be available
+until you build them. However, our script doesn’t need to be compiled,
+so can’t we just run it?
@@ -2582,11 +2672,11 @@ bash: line 16: hello-flake: command not found
- That worked before; why isn’t it working now? Earlier we used
+ That worked before; why isn’t it working now? Earlier we used
nix shell to enter a runtime environment where hello-flake was
available and on the $PATH. This time we entered a development
-environment using the nix develop command. Since the flake hasn’t been
-built yet, the executable won’t be on the $PATH. We can, however, run
+environment using the nix develop command. Since the flake hasn’t been
+built yet, the executable won’t be on the $PATH. We can, however, run
it by specifying the path to the script.
@@ -2607,7 +2697,7 @@ Hello from your flake!
- Rather than typing the full path to the executable, it’s more convenient
+ Rather than typing the full path to the executable, it’s more convenient
to use nix run.
@@ -2617,7 +2707,7 @@ Hello from your flake!
- Here’s a summary of the more common Nix commands.
+ Here’s a summary of the more common Nix commands.
@@ -2639,7 +2729,7 @@ by flake.nix).
nix shell
|
-Enters a runtime shell where the flake’s executables are
+ | Enters a runtime shell where the flake’s executables are
available on the $PATH. |
@@ -2649,7 +2739,7 @@ available on the $PATH.
nix run
|
-Runs the flake’s default executable, rebuilding the package
+ | Runs the flake’s default executable, rebuilding the package
first if needed. Specifically, it runs the version in the Nix store, not
the version in result. |
@@ -2659,7 +2749,7 @@ the version in result.
8.2. Introducing a dependency
- Now we’re ready to make the flake a little more interesting.
+ Now we’re ready to make the flake a little more interesting.
Instead of using the echo command in the script, we can use the Linux cowsay
command.
Here’s the hello-flake file, with the modified line highlighted.
@@ -2673,7 +2763,7 @@ cowsay "Hello from your flake!"
- Let’s test the modified script.
+ Let’s test the modified script.
@@ -2683,15 +2773,15 @@ cowsay "Hello from your flake!"
What went wrong? Remember that we are in a development shell. Since
-flake.nix didn’t define the devShells variable, the development
+flake.nix didn’t define the devShells variable, the development
shell only includes the Nix standard environment. In particular, the
cowsay command is not available.
To fix the problem, we can modify flake.nix.
-We don’t need to add cowsay to the inputs section because it’s included in nixpkgs,
+We don’t need to add cowsay to the inputs section because it’s included in nixpkgs,
which is already an input.
-However, we also want it to be available in a develoment shell.
+However, we also want it to be available in a development shell.
The highlighted modifications below will accomplish that.
@@ -2751,9 +2841,9 @@ The highlighted modifications below will accomplish that.
Now we restart the development shell and see that the cowsay command is
-available and the script works. Because we’ve updated source files
-but haven’t git commited the new version, we get a warning message
-about it being “dirty”. It’s just a warning, though; the script runs
+available and the script works. Because we’ve updated source files
+but haven’t git commited the new version, we get a warning message
+about it being “dirty”. It’s just a warning, though; the script runs
correctly.
@@ -2793,7 +2883,7 @@ warning: Git tree '/home/amy/codeberg/nix-book/source/modify-hello-flake/hello-f
Note, however, that nix run rebuilt the package in the Nix store and
ran that. It did not alter the copy in the result directory, as
-we’ll see next.
+we’ll see next.
@@ -2817,13 +2907,13 @@ cowsay "Hello from your flake!"
- Let’s git commit the changes and verify that the warning goes away. We
-don’t need to git push the changes until we’re ready to share them.
+ Let’s git commit the changes and verify that the warning goes away. We
+don’t need to git push the changes until we’re ready to share them.
$ git commit hello-flake flake.nix -m 'added bovine feature'
-[main eb4d08c] added bovine feature
+[main c264cad] added bovine feature
2 files changed, 7 insertions(+), 1 deletion(-)
$ nix run
________________________
@@ -2840,8 +2930,8 @@ $ nix run
8.3. Development workflows
- If you’re getting confused about when to use the different commands,
-it’s because there’s more than one way to use Nix. I tend to think of it
+ If you’re getting confused about when to use the different commands,
+it’s because there’s more than one way to use Nix. I tend to think of it
as two different development workflows.
@@ -2861,15 +2951,15 @@ as two different development workflows.
- In the high-level workflow, I don’t use a development shell because I
-don’t need to directly invoke development tools such as compilers and
+ In the high-level workflow, I don’t use a development shell because I
+don’t need to directly invoke development tools such as compilers and
linkers. Nix invokes them for me according to the output definition in
flake.nix.
Occasionally I want to work at a lower level, and invoke compiler,
linkers, etc. directly. Perhaps want to work on one component without
-rebuilding the entire package. Or perhaps I’m confused by some error
+rebuilding the entire package. Or perhaps I’m confused by some error
message, so I want to temporarily bypass Nix and work directly with
the compiler. In this case I temporarily switch to a low-level
workflow.
@@ -2888,7 +2978,7 @@ I need (e.g. compilers, linkers, documentation generators).
Directly invoke the executable. Note that the location of the
-executable depends on the development tools – It probably isn’t
+executable depends on the development tools – It probably isn’t
result!
@@ -2898,7 +2988,7 @@ executable depends on the development tools – It probably isn’t
I generally only use nix build if I just want to build the package but
-not execute anything (perhaps it’s just a library).
+not execute anything (perhaps it’s just a library).
@@ -2939,7 +3029,7 @@ Initialized empty Git repository in /home/amy/codeberg/nix-book/source/new-flake
9.1.1. A simple Haskell program
- Next, we’ll create a simple Haskell program.
+ Next, we’ll create a simple Haskell program.
Main.hs
@@ -2964,14 +3054,14 @@ Initialized empty Git repository in /home/amy/codeberg/nix-book/source/new-flake
9.1.2. (Optional) Testing before packaging
- Before we package the program, let’s verify that it runs. We’re going to
-need a Haskell compiler. By now you’ve probably figured out that we can write a
-flake.nix and define a development shell that includes Haskell. We’ll
+ Before we package the program, let’s verify that it runs. We’re going to
+need a Haskell compiler. By now you’ve probably figured out that we can write a
+flake.nix and define a development shell that includes Haskell. We’ll
do that shortly, but first I want to show you a handy shortcut. We can
-lauch a temporary shell with any Nix packages we want. This is
-convenient when you just want to try out some new software and you’re
-not sure if you’ll use it again. It’s also convenient when you’re not
-ready to write flake.nix (perhaps you’re not sure what tools and
+launch a temporary shell with any Nix packages we want. This is
+convenient when you just want to try out some new software and you’re
+not sure if you’ll use it again. It’s also convenient when you’re not
+ready to write flake.nix (perhaps you’re not sure what tools and
packages you need), and you want to experiment a bit first.
@@ -2994,7 +3084,7 @@ packages you need), and you want to experiment a bit first.
The command used here is nix-shell with a hyphen, not nix shell
with a space; those are two different commands. In fact there are
hyphenated and non-hyphenated versions of many Nix commands, and yes,
-it’s confusing. The non-hyphenated commands were introduced when support
+it’s confusing. The non-hyphenated commands were introduced when support
for flakes was added to Nix. I predict that eventually all hyphenated
commands will be replaced with non-hyphenated versions. Until then, a
useful rule of thumb is that non-hyphenated commands are for for working
@@ -3025,7 +3115,7 @@ You can come back to this section later to learn more.
- Let’s enter a shell with the Glasgow Haskell Compiler ("ghc") and try to run the program.
+ Let’s enter a shell with the Glasgow Haskell Compiler ("ghc") and try to run the program.
@@ -3200,7 +3290,7 @@ executable hello-flake-haskell
At this point, I would normally write flake.nix and use Nix to build the program.
I’ll cover that in the next section.
-However, it’s useful to know how to build the package manually in a Nix envronment,
+However, it’s useful to know how to build the package manually in a Nix environment,
without using a Nix flake.
When you’re new to Nix, this can help you differentiate between problems in your flake definition
and problems in your Cabal file.
@@ -3220,7 +3310,7 @@ Rather than launch another shell-within-a-shell, let’s exit create a new o
$ exit
$ nix-shell -p "[ cabal-install (haskellPackages.ghcWithPackages (pkgs: with pkgs; [ hostname ]))]"
$ cabal build
-Warning: The package list for 'hackage.haskell.org' is 21 days old.
+Warning: The package list for 'hackage.haskell.org' is 24 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
@@ -3313,7 +3403,7 @@ different are the development shell and the package builder.
The above definition will work for most of your haskell projects;
simply change the description and the package name in packages.default.
-Let’s try out the new flake.
+Let’s try out the new flake.
@@ -3323,7 +3413,7 @@ error: getting status of '/nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source/fla
- Why can’t it find flake.nix? Nix flakes only “see” files that are
+ Why can’t it find flake.nix? Nix flakes only “see” files that are
part of the repository. We need to add all of the important files to the
repo before building or running the flake.
@@ -3335,24 +3425,24 @@ warning: Git tree '/home/amy/codeberg/nix-book/source/new-flake/haskell-flake/he
warning: creating lock file '/home/amy/codeberg/nix-book/source/new-flake/haskell-flake/hello-haskell/flake.lock'
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/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv
- /nix/store/hi70w0gzjfj213r0xhhva7n617hfa378-hello-flake-haskell-1.0.0.drv
-building '/nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv'...
-error: builder for '/nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv' failed with exit code 1;
+ /nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv
+ /nix/store/8qdbmfms1h0b60aqdxfk28fmdnlkcm1l-hello-flake-haskell-1.0.0.drv
+building '/nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv'...
+error: builder for '/nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv' failed with exit code 1;
last 7 log lines:
- > unpacking source archive /nix/store/fdxvjgdpsfjrkanzbx43g1yxf2b1lp4b-source-hello-flake-haskell
+ > unpacking source archive /nix/store/gg6b20p83m5mqcfp1qr0w37bjhz3k33y-source-hello-flake-haskell
> source root is source-hello-flake-haskell
> Config file path source is default config file.
> Config file not found: /build/source-hello-flake-haskell/.config/cabal/config
> Writing default configuration to
> /build/source-hello-flake-haskell/.config/cabal/config
> /build/source-hello-flake-haskell/./LICENSE: withBinaryFile: does not exist (No such file or directory)
- For full logs, run 'nix log /nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv'.
-error: 1 dependencies of derivation '/nix/store/hi70w0gzjfj213r0xhhva7n617hfa378-hello-flake-haskell-1.0.0.drv' failed to build
+ For full logs, run 'nix log /nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv'.
+error: 1 dependencies of derivation '/nix/store/8qdbmfms1h0b60aqdxfk28fmdnlkcm1l-hello-flake-haskell-1.0.0.drv' failed to build
- We’d like to share this package with others, but first we should do some
+ We’d like to share this package with others, but first we should do some
cleanup. When the package was built (automatically by the nix run
command), it created a flake.lock file. We need to add this to the
repo, and commit all important files.
@@ -3361,7 +3451,7 @@ repo, and commit all important files.
$ git add flake.lock
$ git commit -a -m 'initial commit'
-[master (root-commit) 39ade13] initial commit
+[master (root-commit) 666b827] initial commit
4 files changed, 137 insertions(+)
create mode 100644 Main.hs
create mode 100644 flake.lock
@@ -3378,20 +3468,20 @@ another directory and running it from there.
$ cd ..
$ nix run ./hello-haskell
these 2 derivations will be built:
- /nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv
- /nix/store/hi70w0gzjfj213r0xhhva7n617hfa378-hello-flake-haskell-1.0.0.drv
-building '/nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv'...
-error: builder for '/nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv' failed with exit code 1;
+ /nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv
+ /nix/store/8qdbmfms1h0b60aqdxfk28fmdnlkcm1l-hello-flake-haskell-1.0.0.drv
+building '/nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv'...
+error: builder for '/nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv' failed with exit code 1;
last 7 log lines:
- > unpacking source archive /nix/store/fdxvjgdpsfjrkanzbx43g1yxf2b1lp4b-source-hello-flake-haskell
+ > unpacking source archive /nix/store/gg6b20p83m5mqcfp1qr0w37bjhz3k33y-source-hello-flake-haskell
> source root is source-hello-flake-haskell
> Config file path source is default config file.
> Config file not found: /build/source-hello-flake-haskell/.config/cabal/config
> Writing default configuration to
> /build/source-hello-flake-haskell/.config/cabal/config
> /build/source-hello-flake-haskell/./LICENSE: withBinaryFile: does not exist (No such file or directory)
- For full logs, run 'nix log /nix/store/5ar7vhd4nz8wbqrsgaxqzkh6b4ggvsrv-source-hello-flake-haskell-sdist.tar.gz.drv'.
-error: 1 dependencies of derivation '/nix/store/hi70w0gzjfj213r0xhhva7n617hfa378-hello-flake-haskell-1.0.0.drv' failed to build
+ For full logs, run 'nix log /nix/store/qhb3mvp8i87n58iwi3ldkwpin2m9zgya-source-hello-flake-haskell-sdist.tar.gz.drv'.
+error: 1 dependencies of derivation '/nix/store/8qdbmfms1h0b60aqdxfk28fmdnlkcm1l-hello-flake-haskell-1.0.0.drv' failed to build
@@ -3426,7 +3516,7 @@ Initialized empty Git repository in /home/amy/codeberg/nix-book/source/new-flake
9.2.1. A simple Python program
- Next, we’ll create a simple Python program.
+ Next, we’ll create a simple Python program.
hello.py
@@ -3448,14 +3538,14 @@ Initialized empty Git repository in /home/amy/codeberg/nix-book/source/new-flake
- Before we package the program, let’s verify that it runs. We’re going to
-need Python. By now you’ve probably figured out that we can write a
-flake.nix and define a development shell that includes Python. We’ll
+ Before we package the program, let’s verify that it runs. We’re going to
+need Python. By now you’ve probably figured out that we can write a
+flake.nix and define a development shell that includes Python. We’ll
do that shortly, but first I want to show you a handy shortcut. We can
-lauch a temporary shell with any Nix packages we want. This is
-convenient when you just want to try out some new software and you’re
-not sure if you’ll use it again. It’s also convenient when you’re not
-ready to write flake.nix (perhaps you’re not sure what tools and
+launch a temporary shell with any Nix packages we want. This is
+convenient when you just want to try out some new software and you’re
+not sure if you’ll use it again. It’s also convenient when you’re not
+ready to write flake.nix (perhaps you’re not sure what tools and
packages you need), and you want to experiment a bit first.
@@ -3478,7 +3568,7 @@ packages you need), and you want to experiment a bit first.
The command used here is nix-shell with a hyphen, not nix shell
with a space; those are two different commands. In fact there are
hyphenated and non-hyphenated versions of many Nix commands, and yes,
-it’s confusing. The non-hyphenated commands were introduced when support
+it’s confusing. The non-hyphenated commands were introduced when support
for flakes was added to Nix. I predict that eventually all hyphenated
commands will be replaced with non-hyphenated versions. Until then, a
useful rule of thumb is that non-hyphenated commands are for for working
@@ -3489,7 +3579,7 @@ directly with flakes; hyphenated commands are for everything else.
|