From c820094633ef251d497969d9a603aa2b3d50b1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amy=20de=20Buitl=C3=A9ir?= Date: Mon, 12 Jun 2023 18:32:56 +0100 Subject: [PATCH] clean up afterward --- source/hello-flake-repo.adoc0 | 80 +++++++++++++++++++++++++++++++++ source/modify-hello-flake.adoc0 | 3 +- source/python-flake.adoc0 | 2 +- 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 source/hello-flake-repo.adoc0 diff --git a/source/hello-flake-repo.adoc0 b/source/hello-flake-repo.adoc0 new file mode 100644 index 0000000..5eb2206 --- /dev/null +++ b/source/hello-flake-repo.adoc0 @@ -0,0 +1,80 @@ +== The hello-flake repo + +Let’s clone the repository and see how the flake is defined. + +.... +$ git clone https://codeberg.org/mhwombat/hello-flake +$ cd hello-flake +$ ls +.... + +This is a simple repo with just a few files. Like most git repos, it +includes `LICENSE`, which contains the software license, and `README.md` +which provides information about the repo. + +The `hello-flake` file is the command we were executing earlier. This +particular executable is just a shell script, so we can view it. It’s an +extremly simple script with just two lines. + +.... +$ cat hello-flake +.... + +Now that we have a copy of the repo, we can execute this script +directly. + +.... +$ ./hello-flake +.... + +Not terribly exciting, I know. But starting with such a simple package +makes it easier to focus on the flake system without getting bogged down +in the details. We’ll make this script a little more interesting later. + +Let’s look at another file. The file that defines how to package a flake +is always called `flake.nix`. + +.... +$ cat flake.nix +.... + +If this is your first time seeing a flake definition, it probably looks +intimidating. Flakes are written in a functional language called +Nixfootnote:[For an introduction to the Nix language, see +https://nixos.org/guides/nix-language.html[Nix language basics].]. Yes, +``Nix'' is the name of both the package manager and the language it +uses. We’ll look at this in more detail shortly. For now, I’d like to +focus on the inputs section. + +.... +inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; +.... + +There are just two entries, one for `nixpkgs` and one for `flake-utils`. +The first one, `nixpkgs` refers to the collection of standard software +packages that can be installed with the Nix package manager. The second, +`flake-utils`, is a collection of utilities that simplify writing +flakes. The important thing to note is that the `hello-flake` package +_depends_ on `nixpkgs` and `flake-utils`. + +Finally, let’s look at `flake.lock`, or rather, just part of it. + +.... +$ head -n 40 flake.lock +$# cd .. ; rm -rf hello-flake # clean up +.... + +If `flake.nix` seemed intimidating, then this file looks like an +invocation for Cthulhu. The good news is that this file is automatically +generated; you never need to write it. It contains information about all +of the dependencies for the flake, including where they came from, the +exact version/revision, and hash. This lockfile _uniquely_ specifies all +flake dependencies, (e.g., version number, branch, revision, hash), so +that _anyone, anywhere, any time, can re-create the exact same +environment that the original developer used._ + +No more complaints of ``but it works on my machine!''. That is the +benefit of using flakes. diff --git a/source/modify-hello-flake.adoc0 b/source/modify-hello-flake.adoc0 index ef9747e..2c10438 100644 --- a/source/modify-hello-flake.adoc0 +++ b/source/modify-hello-flake.adoc0 @@ -6,7 +6,8 @@ opportunity to check your understanding of flakes. The first step is to enter a development shell. .... -$ cd ~/tutorial-practice/hello-flake +$# git clone https://codeberg.org/mhwombat/hello-flake +$# cd hello-flake $ nix develop .... diff --git a/source/python-flake.adoc0 b/source/python-flake.adoc0 index a42867e..fe52d80 100644 --- a/source/python-flake.adoc0 +++ b/source/python-flake.adoc0 @@ -4,7 +4,6 @@ At last we are ready to create a flake from scratch! Start with an empty directory and create a git repository. .... -$ cd ~/tutorial-practice $ mkdir hello-python $ cd hello-python $ git init @@ -180,6 +179,7 @@ another directory and running it from there. .... $ cd ~ $ nix run ~/tutorial-practice/hello-python +$# cd .. ; rm -rf hello-python # clean up .... If you move the project to a public repo, anyone can run it. Recall from