1. Bio / Persona
Learned computational linguistics at grad school with Haskell, but had no relevant experience with building software and dealing with dependencies.
2. Prior Nix experience
Never used Nix before, but has to get acquainted with it for a Haskell project that uses it. Only has a vague idea what it might be for, and how to use it on MacOS.
3. Approaches to learning Nix
At first go, googles nix tutorial
, reads a few of the results, but only understands what problem Nix is trying to solve at a very high level:
- packages in Nix store,
- packages are hashed,
- there is a custom language to set things up,
but most of the details are elusive. Can’t say how Nix is different from Docker after this quick research.
- NixOS/nixos-hmepage#840 how nix works: reword introduction
- NixOS/nixos-homepage#894 differentiate Nix from Docker
Likes to go to the heart of the matter when learning, and navigates to nixos.org on the next try. Jumps to the Learn tab immediately without looking at the front page. Finds it great, wonders why dismissed it on first pass, and can tell simply by scanning the titles that Nix is about reproducible, declarative builds.
-
Clicks on First Steps with Nix
Finds Nix shell environments cool, and grasps right away how they can be useful, but questions are raised after scanning the page:
- The Nix packages list is useful, but how does one specify a different version of a package?
- What does
nix-env
do? Hasn’t come across it before.- NixOS/nix.dev#17 Antipattern: imperative package management
- Are shells other than Bash supported? Wondering as a Fish user because the page only mentions Bash.
- NixOS/nix#545 Support non-bash shells in nix-shell
-
Moving to article Towards reproducibility
Finds the article confusing at first, because the article claims that the first example is not reproducible, then quickly gives the solution, but never actually explains why the first Nix expression isn’t reproducible. Some research helps to get the gist.
-
In Ad hoc developer environments, finds the Reproducible executables section confusing, because it is not immediately clear what the example script is: looks like a shell script, but then calling Python commands. Seems to ignore the note below which is incorrectly formatted on nixos.org, but is more prominent in the nix.dev version of the article.
-
Skims the Explore page, perceives it as mostly marketing that looks helpful.
-
Onward to How Nix Works.
Looks at the latest pull request (NixOS/nixos-homepage #840), reads it slowly and carefully.
The feature list makes sense (e.g., multiple versions, complete dependencies, atomic upgrades & rollbacks), but can’t figure out the difference between “build-time” and “run-time” from the text itself, and then quickly scrolls past garbage collection.
Presumes that the “Functional Package Language” and the mention of “Nix expressions” refer to the configuration language used in the examples from before. Knows what a “functional language” is, but finds it hard to reason about what “functional” means in the context of a build process; it probably has to do with reproducibility or purity, but what would a build process not being functional mean? Showing the simplest possible Nix expression would be helpful.
Finds the page useful as a whole, and thinks to understand what Nix does, especially after looking at the architecture diagram. All in all, the articles elicit ideas what to look for next.
Moving on from nixos.org to Nix Pills (found in Inria’s “Nix tutorial”) to learn more about the Nix language, but instructor prompts to switch to the Nix Language section in the Nix manual.
- gitlab.inria.fr/nix-tutorial#a9c51354 lead beginners to nix.dev (discussion)
- NixOS/nixos-homepage#855 move Nix Pills to the end of recommendation list, reword logline
Personal takeaways after reading it:
-
Makes sense why it is called a functional language.
-
Finds it interesting that the arguments themselves are things that need to be built (e.g., when using the
fetchurl
package inside the expression). -
stdenv
sounds like a namespace. -
Questions:
-
What is a “builder”?
-
What will run the example expression?
Presumes that Nix will run it with some inputs given to it, but not having full understanding of the process still renders the whole thing confusing.
-
What is the shortest possible introduction to the Nix language? (Prefers reading over watching video.)
- NixOS/nix#6906 add syntax overview from NixOS manual
- NixOS/nix.dev#267 Nix language tutorial
-
What are these Nix files for:
shell.nix
,default.nix
,flake.nix
? -
What are “flakes”?
- NixOS/nix.dev#242 flakes tutorial
-
QUESTION: How confident do you feel when it comes to reading Nix expressions?
ANSWER: The Haskell background does not make it sound scary.
QUESTION: What would you consider to be your next steps towards learning Nix?
ANSWER: Try to figure out what the CI does with the aforementioned Nix files.
4. Using Nix
The Haskell project is already set up with Nix, and first thought is that the continuous integration tool (CI) uses it to run stuff, but has no clue how to start using Nix.
Trying nix-shell
first, after learning that it can be used to set up a local developer environment for the project, but running into an error:
string <> cannot refer to other paths
Assumes that this is a MacOS-specific issue and retries with --show-trace
; the output is more verbose, but unfamiliarity with Nix renders it useless. Perhaps Nix has not been installed correctly and tries to re-install it:
- Goes to download page
- Realizes that Nix may need to be uninstalled first, but how?
-
Search online for
uninstall nix
- there are countless installer issues
- Nix installer workgroup established to get on top of things
-
Settles on using the Uninstall Nix of Inria’s nix-tutorial
-
Gets errors after following the instructions:
error: Operation not permitted error: Resource busy
-
Runs installer shell command in Bash, and clicks “yes” to all prompts in quick succession, but the errors persist still:
error: backup files already exist
-
Stumped about how to clean it up (misses the hints in the error message). It does not say to re-run the installer, so tries
nix-shell
again, but no joy. -
Re-runs installer in Zsh, same error as in Bash.
-
Resolves to re-read the error messages more slowly this time, finds the hints below, and applies the fix.
`cp /etc/bashrc ~/backup_etcbashrc` `cp /etc/bashrc.backup-before-nix ~/bashrcbackup` `mv /etc/bashrc.backup-before-nix /etc/bashrc`
-
After the successful re-installing of Nix, nix-shell
is still throwing errors:
error: probem with SSL CA cert path
Back to Google, where a merged GitHub pull request (NixOS/nix #4023) looks promising, and the issues referenced in it indeed give a hint to try sudo nix-shell
. That seems to do the trick, but some weird packages are seen being installed, and the build does fail eventually. Realizes that the Haskell project is not on the master
branch, and gives sudo nix-shell
another try after switching back to master
.
Session ends here.