Skip to content

Commit

Permalink
docs: usage section in readme
Browse files Browse the repository at this point in the history
Also fix some misspellings.
  • Loading branch information
AntonHakansson committed Jan 28, 2024
1 parent 2d371b1 commit 8bba632
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
65 changes: 59 additions & 6 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#+html: <div align=center>
#+html: <h2 align=center>org-nix-shell</h2>
#+html: <p>Buffer-local nix-shell environment in org-mode.</p>
#+html: <p>Buffer-local nix-shell environments in org-mode.</p>
#+html: <img src='img/showcase-alt.png'>
#+html: </div>

This package is experimental; expect bugs and breaking changes.

Use nix shells directly in org-mode and org-babel src blocks.
=org-nix-shell= works by loading a nix shell environment using [[https://direnv.net/][direnv]].
Use nix shells directly in org-mode source blocks. =org-nix-shell= works by seamlessly
inheriting a nix shell environment using [[https://direnv.net/][direnv]] before executing org-babel source blocks.

* Quickstart

Expand All @@ -28,9 +26,63 @@ Use nix shells directly in org-mode and org-babel src blocks.
Enable =org-nix-shell-mode= and evaluate or export the buffer.
See [[file:demo.org][demo.org]] with examples for Python and C.

* Usage

First create a nix shell in a named source block.

#+begin_src org
,#+name: <name>
,#+begin_src nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [ python3 ];
}
,#+end_src
#+end_src

Source blocks with a =:nix-shell <name>= header argument will use the nix shell
environment specified by =<name>=; where =<name>= is the corresponding named source block
in the same buffer. Other source blocks should be unaffected and you can explicitly set
=:nix-shell 'nil= to not depend on any nix shell.

To use the nix shell above we can do:

#+begin_src org
,#+begin_src python :nix-shell <name>
print("hello from python")
,#+end_src
#+end_src

There are three ways to configure the =:nix-shell= header property; also see [[https://orgmode.org/manual/Using-Header-Arguments.html][Using Header
Arguments (The Org Manual)]]. In increasing order of priority they are:

** Buffer Scope

#+begin_src org
,#+property: header-args: :nix-shell <name>
#+end_src

** Subtree Scope

#+begin_src org
,* sample header
:PROPERTIES:
:header-args: :nix-shell <name>
:END:
#+end_src

** Source Block Scope

#+begin_src org
,#+begin_src python :nix-shell <name>
print("hello from python")
,#+end_src
#+end_src


* Installation

Make sure [[https://direnv.net/][direnv]] is installed on your system ([[https://github.com/nix-community/nix-direnv#installation][nix-community/nix-direnv#Installation]]).
Make sure [[https://nixos.org/manual/nix/stable/command-ref/nix-shell][nix-shell]] and [[https://direnv.net/][direnv]] is installed on your system ([[https://github.com/nix-community/nix-direnv#installation][nix-community/nix-direnv#Installation]]).

** Manual

Expand All @@ -42,6 +94,7 @@ Then evaluate:
(add-hook 'org-mode-hook 'org-nix-shell-mode)
#+end_src

** TODO Melpa
** Straight

#+begin_src elisp
Expand Down
4 changes: 2 additions & 2 deletions org-nix-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
;; Version 0.3.0 (lots of breaking changes)
;; - Dropped dependency on envrc package. Instead we get the shell environment from
;; nix-shell using direnv's dump command. No more out-of-tree directory with .envrc.
;; This gives us a noticable performance win.
;; This gives us a noticeable performance win.
;;
;; - Removed `org-nix-shell-get-direnv-path', `org-nix-shell-envrc-format' and
;; `org-nix-shell-src-block-name'. Instead we tangle nix shells to org-babel's
;; temoporary directory.
;; temporary directory.
;;
;; Version 0.2.0 (lots of breaking changes)
;; - Source blocks must explicitly set ':nix-shell <named-src-block>' header argument to
Expand Down

0 comments on commit 8bba632

Please sign in to comment.