Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
takeokunn committed Feb 1, 2025
1 parent a682aba commit b12a674
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 2 deletions.
84 changes: 83 additions & 1 deletion org/fleeting/20250126140928-introduction_org_nix_shell.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,86 @@
#+STARTUP: fold
* Introduction

- org-nix-shellについて
org-nix-shellはOrg関連パッケージの中でもキラーアプリと呼べるもので、個人的に今熱いパッケージの一つです。
簡単な使い方と実際のユースケースを紹介していきます。

* インストール

- GitHub: https://github.com/AntonHakansson/org-nix-shell/blob/main/README.org
- melpa: https://melpa.org/#/org-nix-shell

Melpa経由で入れても良いし、GitHub経由で直接インストールしても良い。
以下のように設定するだけで機能してくれる。

#+begin_src emacs-lisp
(require 'org-nix-shell)

(with-eval-after-load 'org
(add-hook 'org-mode-hook #'org-nix-shell-mode))
#+end_src

* 使い方
** Basic

以下のようにNixを定義して =:nix-shell= で読み込む。

#+begin_src org
,#+name: tmp-shell
,#+BEGIN_SRC nix :noweb yes
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { buildInputs = with pkgs; [ php ]; }
,#+END_SRC

,#+begin_src shell :nix-shell tmp-shell :results output
php --version
,#+end_src
#+end_src

また、以下のURLから古いバージョンを取ってきて実行することも可能。
https://lazamar.co.uk/nix-versions

#+begin_src org
,#+name: php74-shell
,#+BEGIN_SRC nix :noweb yes
let
url =
"https://github.com/NixOS/nixpkgs/archive/4426104c8c900fbe048c33a0e6f68a006235ac50.tar.gz";
pkgs = import (builtins.fetchTarball { inherit url; }) {
system = "<<wandbox-system>>";
};
in pkgs.mkShell { buildInputs = with pkgs; [ php74 ]; }
,#+END_SRC

,#+begin_src php :nix-shell php74-shell :exports both
echo phpversion();
,#+end_src

,#+RESULTS:
: 7.4.4
#+end_src

property指定もできる。

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
** Adviced

複数の処理系を定義しておけば、wandboxのようなことも実現可能になる。



* 所感
必要なものを明示的にインストールして実行できるのでポータビリティが非常に高い。
ブログや運用手順書との相性が非常に良く、文芸的プログラミングのレベルを一つ上にレベルアップすることが可能になった。
182 changes: 182 additions & 0 deletions static/snippets/wandbox.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#+STARTUP: content
#+STARTUP: fold
#+OPTIONS: toc:nil
* Wandbox
** System
#+name: wandbox-system
#+begin_src nix
x86_64-darwin
#+end_src
** PHP
*** 7.2
**** define
#+name: php72-shell
#+BEGIN_SRC nix :noweb yes
let
url =
"https://github.com/NixOS/nixpkgs/archive/df2176f7f3f748974f24916df29bb70763d89734.tar.gz";
pkgs = import (builtins.fetchTarball { inherit url; }) {
system = "<<wandbox-system>>";
};
in pkgs.mkShell { buildInputs = with pkgs; [ php72 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php72-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 7.2.27

*** 7.3
**** define
#+name: php73-shell
#+BEGIN_SRC nix :noweb yes
let
url =
"https://github.com/NixOS/nixpkgs/archive/9d21fe813fd96afd4a08d5437186ebe438546693.tar.gz";
pkgs = import (builtins.fetchTarball { inherit url; }) {
system = "<<wandbox-system>>";
};
in pkgs.mkShell { buildInputs = with pkgs; [ php73 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php73-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 7.3.15
*** 7.4
**** define
#+name: php74-shell
#+BEGIN_SRC nix :noweb yes
let
url =
"https://github.com/NixOS/nixpkgs/archive/4426104c8c900fbe048c33a0e6f68a006235ac50.tar.gz";
pkgs = import (builtins.fetchTarball { inherit url; }) {
system = "<<wandbox-system>>";
};
in pkgs.mkShell { buildInputs = with pkgs; [ php74 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php74-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 7.4.4
*** 8.0
**** define
#+name: php80-shell
#+BEGIN_SRC nix :noweb yes
let
url =
"https://github.com/NixOS/nixpkgs/archive/d1c3fea7ecbed758168787fe4e4a3157e52bc808.tar.gz";
pkgs = import (builtins.fetchTarball { inherit url; }) {
system = "<<wandbox-system>>";
};
in pkgs.mkShell { buildInputs = with pkgs; [ php80 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php80-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 8.0.16
*** 8.1
**** define
#+name: php81-shell
#+BEGIN_SRC nix :noweb yes
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { buildInputs = with pkgs; [ php81 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php81-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 8.1.29
*** 8.2
**** define
#+name: php82-shell
#+BEGIN_SRC nix :noweb yes
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { buildInputs = with pkgs; [ php82 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php82-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 8.2.22
*** 8.3
**** define
#+name: php83-shell
#+BEGIN_SRC nix :noweb yes
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell { buildInputs = with pkgs; [ php83 ]; }
#+END_SRC
**** test
#+begin_src php :nix-shell php83-shell :exports both
echo phpversion();
#+end_src

#+RESULTS:
: 8.3.10
** Test
*** 0 == ""
**** 7.2
#+begin_src php :nix-shell php72-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(true)

**** 7.3
#+begin_src php :nix-shell php73-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(true)

**** 7.4
#+begin_src php :nix-shell php74-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(true)
**** 8.0
#+begin_src php :nix-shell php80-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(false)
**** 8.1
#+begin_src php :nix-shell php81-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(false)
**** 8.2
#+begin_src php :nix-shell php82-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(false)
**** 8.3
#+begin_src php :nix-shell php83-shell :exports both
var_dump(0 == "");
#+end_src

#+RESULTS:
: bool(false)
2 changes: 1 addition & 1 deletion themes/hugo-take-theme

0 comments on commit b12a674

Please sign in to comment.