Nix言語
Nix Expression Languageのこと
Nix向けの関数型DSL
Nix関係の全ての設定やderivationはこのNix Expression Languageで書く
強い動的型付き
遅延評価である
拡張子は.nix
nix repl上で試せる
変わった仕様が多いので込み入ったことをしようとするとハマるかも知れない(悪い意味で)mrsekut.icon
manual
docs
文法など基本事項
Nix言語Attribute Sets
Nix言語における(/)の挙動
Nix言語: 関数
Nix言語: with式
標準関数など
Nixのbuiltin関数
Identifier
-を識別子に使える
a-やa-bという変数を定義できる
packageのnameに-を使うことが多いので便利
Strings
文字列は、"foo"か''foo''のいずれかで書く
'foo'という書き方はできない
''fo"o''のように文字列の内部に"を含めたいときとかに使う
Interpolationは"${foo}"または''${foo}''と書く
このfooの中身は文字列でないといけない
interpolationをescapeするためには以下のように書く
code:nix
nix-repl> "\${foo}"
"${foo}"
nix-repl> ''test ''${foo} test''
"test ${foo} test"
これは覚えられる気がしないmrsekut.icon
Lists
カンマは不要
[ 2 "foo" true (2+3) ]
immutableである
let..in
;が必要
code:nix
let a = "foo"; in a
let a = 3; b = 4; in a + b
https://nixos.org/guides/nix-pills/basics-of-language.html#idm140737320560544
関連
PureNix
https://github.com/purenix-org/purenix
PureScriptを書いて、Nix言語を吐き出す
NixのLSP
NIX-ML
https://github.com/luispedro/nixml
YAMLの形式でNixを書く
参考
Nix Pills 4
他の関数型言語とは異なる部分のみを取り上げて紹介されている
#プログラミング言語
#WIP
文法
<hoge>ってなに?
e.g. let localconfig = import <localconfig>;
inherit statement
inheritってなに?
ここのコードとかに出てくる
関数じゃなくて構文っぽいが(syntax highligh的に)
Nix言語のテスト
https://nixos.org/#asciinema-demo-example_6
できるらしい
https://github.com/nix-community/nixt
Nixt
慣用表現
scriptのpathを取得
${builtins.toString ./.}
あるdir内の、dir名一覧を取得
path: map (d: ./. + "/${d}") (builtins.attrNames (builtins.readDir path)); ref
型
integer, floating point, string, path, boolean and null
simple types
https://nixos.org/manual/nix/stable/#ssec-values
lists
sets
functions
Functo, Monadなどの型を定義しているrepo
https://github.com/chessai/nix-std
#??
良い感じの関数結合ってないの?
.nix内で$USERみたいに、shell変数使いたい
https://qiita.com/hnakano863/items/47ba13633861be35bd83#home-manager-を使うための最低限の文法
https://ryota-ka.hatenablog.com/entry/2018/12/15/000000
https://www.tweag.io/blog/2017-05-23-typing-nix/
https://github.com/tazjin/nix-1p