Skip to content

Latest commit

 

History

History
114 lines (91 loc) · 2.48 KB

demo.org

File metadata and controls

114 lines (91 loc) · 2.48 KB

Demo of org-nix-shell

Load org-nix-shell-mode and then execute the src blocks.

{ pkgs ? import <nixpkgs> {}, pythonPackages ? pkgs.python3Packages }:
pkgs.mkShell {
  buildInputs = [
    pkgs.cowsay
    pythonPackages.sympy
    <<nix-c-dependencies>>
  ];
  shellHook = ''
    echo "Hello from shellHook!"
  '';
  MY_ENVIRONMENT_VAR = "Polyglot notebook in org-mode!";
}

Shell

cowsay "hello from nix-shell"
echo "$MY_ENVIRONMENT_VAR"
eval "$shellHook" # run shellHook
printf "\nNow show me nix-related environment variables:\n\n"
env | grep "NIX_"

Python

from sympy import *
x = symbols('x');
expr = 10**x
print("\\[ \\int" + latex(expr) + " = " + latex(integrate(expr)) + " \\]")

C

pkgs.pkg-config
pkgs.cairo
pkg-config cairo --cflags --libs
const char *filename = "rectangle.png";
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 64, 64);
cairo_t *cr = cairo_create(surface);
cairo_scale(cr, 64, 64);

cairo_set_line_width(cr, 0.1);
cairo_set_source_rgb(cr, 1, 0, 0);
cairo_rectangle(cr, 0.25, 0.25, 0.5, 0.5);
cairo_stroke(cr);

cairo_surface_write_to_png(surface, filename);
cairo_destroy(cr);
cairo_surface_destroy(surface);

printf("%s", filename);

Separate nix-shell

:header-args+: :nix-shell nix-shell-fortune

Here we set the nix-shell in the subtree property to default to nix-shell-fortune.

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  buildInputs = [
    pkgs.fortune
  ];
}
fortune

We can always override the nix-shell per source block.

cowsay "hello from top-level nix-shell"

Or remove it completely

command -v hello && echo "hello installed" || echo "hello not installed"