Nix

Who are we?

Coders Only

We are a registered association in Zürich dedicated to software developers.

What do we do?

  • SoCraTes Day CH
  • Global Day of Coderetreat Bern & Zürich
  • Book study groups (like Crafting Interpreters)
  • Software Craft Study Group
  • Girl Coders get together
  • Coders Monthly
  • Regular meetups

Sponsors

bbv bring! labs ergon finnova house of test megazord

Become a member

$ sh <(curl -L https://codersonly.org/members/join)

Nix

This evening's goals

  • Me being exposed to questions
  • You learning at least something new

Schedule

  1. Introduction to flakes
  2. Creating a flake from a template
  3. Structure of a flake
  4. Create your own flake from scratch
  5. Adding a shell to your flake

Introduction to flakes

https://nixos.wiki/wiki/Flakes

What is a flake?

[...] a standard way to write [...] packages [...] improving reproducibility

The intent of flakes

  • standardizing inputs
  • pinning input versions
  • standardizing outputs

Creating flakes from a template

  1. Choose a template
    https://github.com/NixOS/templates lists a bunch
  2. Run
    $ nix flake init --template templates#trivial
    
  3. Profit!
    ...from your newly created flake.nix file

Using the flake

See the available packages with

$ nix flake show
path:/the/path/to/the/folder?lastModified=someunixtime&narHash=sha256-somehash
└───packages
    └───x86_64-linux
        ├───default omitted (use '--all-systems' to show)
        └───hello omitted (use '--all-systems' to show)

or build a package using

$ nix build .#hello

What's the structure of a flake

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
  };
  outputs = inputs: {
    apps."<system>"."<name>" = {
      type = "app";
      program = "<store-path>";
    };
    devShells."<system>"."<name>" = derivation;
    packages."<system>"."<name>" = derivation;
    templates."<name>" = {
      path = "<store-path>";
      description = "template description goes here";
    };
  };
}

Creating a flake with a shell

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/master";
  };
  outputs = inputs @ {nixpkgs}: let
    pkgs = nixpkgs.legacyPackages.aarch64-darwin;
  in {
    devShells.aarch64-darwin.default = pkgs.mkShell {
      packages = with pkgs; [
        python
      ];
    };
  };
}

Use the shell of the flake

Now you can start that shell using:

$ nix develop .#default

Thank you!

and if you enjoyed this content... consider becoming a member

$ sh <(curl -L https://codersonly.org/members/join)