Created: June 1, 2022 10:57 PM
Learned computational linguistics at grad school with Haskell, but had no relevant experience with building software and dealing with dependencies. 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.
At first go, googles “Nix tutorial”, read a few of the results, but only understands what problem Nix is trying to solve at a very high level: structure of packages in Nix store, the packages are hashed, there is a custom language around setting things up, but most of the details were elusive. Can't say how Nix is different from Docker after this quick research.
Likes to go to the heart of the matter when learning, and goes to nixos.org on the next try. Jumps to the Learn page immediately wihtout looking at the front page. Finds the page 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. - Are shells other than Bash supported? Wondering as a Fish user because the page only mentions Bash
-
Moving to article Towards reproducibility
Finds the article confusing at first, because the articles 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.
NOTE In the notes, it says that "
--pure
explains it", but looking at thenix-shell
man page, this statement doesn't make sense. Some context is missing here so I left this part out.NOTE Also skipped this part,
- reproducible executables - what does this mean? - is this python code? - confused by the example - looks like it installed python, but then running python commands - (seems to ignore the note, which is not highlighted) - goes fairly slowly thorugh next steps - open “getting started with nix template” in tab
because I don't know which article it refers to. Set up a development environment maybe?
-
Skims Explore page, perceives 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" froom the text itself, and then quickly scrolls past garbabe 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 elicits 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 switches to Nix Language section in the Nixmanual after some friendly advice. Personal takeaways after reading it:
-
Makes sense why it is called a functional language
-
Finds interesting 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.)
NOTE Don't know what these resources are.
- presentation:
- JSON with functions
- use minimal example for C project with/without dependencies
- presentation:
-
At the end of the session, asks what some of the Nix files (such as shell.nix
, default.nix
, flake.nix
, etc.) are for, and what "flakes" are.
Parting feedback questions and answers:
-
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.
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"
-
Settles on using the result https://nix-tutorial.gitlabpages.inria.fr/nix-tutorial/installation.html#uninstalling-nix
-
Gets errors after following instructions:
error: Operation not permitted error: Resource busy
-
Runs installer shell command in Bash, and clicks "yes" to all prompts in quick successions.
error: backup files already exist
-
Stumped about how to clean it up, and missing the hints, but 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, find 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
.
NOTE Couldn't figure out from the transcript whether this last step worked or not.
https://gist.github.com/toraritte/bacb86097c7eaa9d90e54f77a9f344e3/revisions#diff-e51995527b67da27256e226a8cb69a9d9434051ce6bc2cea2a3d7641db20d46dR31-R32
Yes, maybe this is a slip-up, forget it.
https://gist.github.com/toraritte/bacb86097c7eaa9d90e54f77a9f344e3/revisions#diff-e51995527b67da27256e226a8cb69a9d9434051ce6bc2cea2a3d7641db20d46dR34-R46
It refers to this section: https://nix.dev/tutorials/ad-hoc-developer-environments#reproducible-executables. On nixos.org the note on what the
nix-shell
shebang line does is not highlighted.https://gist.github.com/toraritte/bacb86097c7eaa9d90e54f77a9f344e3/revisions#diff-e51995527b67da27256e226a8cb69a9d9434051ce6bc2cea2a3d7641db20d46dR74-R78
This was an impromptu introduction to the Nix language that consisted of typing things into a text file.
https://gist.github.com/toraritte/bacb86097c7eaa9d90e54f77a9f344e3/revisions#diff-e51995527b67da27256e226a8cb69a9d9434051ce6bc2cea2a3d7641db20d46dR139-R140
I forgot. I think it worked, but it doesn't really matter. The interaction shows that it was really confusing.