Skip to content

Instantly share code, notes, and snippets.

@toraritte
Last active August 15, 2022 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toraritte/fb31a6e138d927f6ad29d5af8da44273 to your computer and use it in GitHub Desktop.
Save toraritte/fb31a6e138d927f6ad29d5af8da44273 to your computer and use it in GitHub Desktop.

Nix Learning Journeys

1. Participant #1

Created: June 1, 2022 10:57 PM

1.1 Bio / persona

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.

1.2 The Journey

1.2.1 Approaches to learning about Nix

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.

  • 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.)

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.

1.2.2 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:

  1. Goes to download page

  2. Realizes that Nix may need to be uninstalled first, but how?

  3. Search online for "uninstall nix"

  4. Settles on using the result https://nix-tutorial.gitlabpages.inria.fr/nix-tutorial/installation.html#uninstalling-nix

  5. Gets errors after following instructions:

    error: Operation not permitted
    error: Resource busy
    
  6. Runs installer shell command in Bash, and clicks "yes" to all prompts in quick successions.

    error: backup files already exist
    
  7. 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.

  8. Re-runs installer in Zsh, same error as in Bash.

  9. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment