derivation
Nixにおけるbuildの単位である
Nixにおけるbuildの仕様書のようなもの
どんな入力から、どんなビルド手順で、何を作るかを完全に記述した純粋なデータ構造のこと
その記述から決定的に /nix/store/<hash>-<name> というパスが計算される
雑に捉えるなら
Nixにおけるpackageのこと
Nixが利用するpackageはderivationの形式で提供、共有される
3段階あるが、これらをふわっと全部「derivation」と呼びがち
https://gyazo.com/fbb90b5bb61bac3c9671ed8e6448a3f3 https://stackoverflow.com/a/58243537
① Nix式
人間がNix式で書くやつ
人間がstdenv.mkDerivationなどでNix式を書く
これをnix-instantiateで評価すると、②になる
② store derivation (.drv)
これが本物のderivationmrsekut.icon*2
Nix式で書かれたものを、完全に展開・固定された低レベルの仕様
/nix/store/xxxx-foo.drv に置かれる
これをλ nix-store --realiseすると、③になる
③ store derivation outputs
ビルド成果物
#WIP
新しくderivationを定義する
builtins.derivationを使う
3つの必須項目を指定しさえすればderivationを作れる
code:nix-repl
nix-repl> d = derivation { name = "myname"; builder = "mybuilder"; system = "mysystem"; }
nix-repl> d
«derivation /nix/store/z3hhlxbckx4g3n9sw91nnvlkjvyw754p-myname.drv»
具体例
Nixでderivationを定義して、簡単なCプログラムをbuildしてみる
derivationのattributes
builtins.derivationの返り値であるsetsの各attrを見るmrsekut.icon
builtins.attrNamesでどんなattrを持っているか確認できる
code:nix-repl
nix-repl> d = builtins.derivation {..}
nix-repl> builtins.attrNames d
"all" "builder" "drvAttrs" "drvPath" "name" "out" "outPath" "outputName" "system" "type"
この辺はbuiltins.derivationの必須3項目と同じ
name
builder
system
all
drvAttrs
builder, name, systemの基本事項
drvPath
.drvfileのpath
/nix/store/<hash-name>.drv
out
自分自身
d == d.out
outPath
output paths
nix store上のbuild path
/nix/store/<hash-name>
outputName
type
type = "derivation"というNix内で特別扱いされるfieldになっている
このsetsがderivationであることを表す
https://nixos.org/guides/nix-pills/our-first-derivation.html#idm140737320422816
Fixed Output Derivations
ってなに #??
https://comono.id/posts/2020-03-20-how-nix-instantiation-works/
https://nixos.org/guides/nix-pills/nix-store-paths.html
https://discourse.nixos.org/t/using-fixed-output-paths-for-a-derivation/6338
https://github.com/NixOS/nix/issues/2270
参考
Nix Pills 6
https://nixos.org/manual/nix/unstable/expressions/derivations.html
https://stephank.nl/p/2020-06-01-a-nix-primer-by-a-newcomer.html#:~:text=ahead%20through%20manuals.-,Derivation,-A%20special%20type