flakes
flakes is a way of expression of nix expressions and packages
Flakes - NixOS Wiki
Flakes — nix.dev documentation
Development env using nix flake
nix flake init
this generates flake.nix
we can pass a template
https://nix.dev/manual/nix/2.24/command-ref/new-cli/nix3-flake-init.html
NixOS/templates: Flake templates
MordragT/nix-templates: ❄️ Nix flake templates for: 🦀 Rust, 🦖 Deno, 🐍 Python and 🗒️ reveal.js among others
the-nix-way/dev-templates: Dev environments for numerous languages based on Nix flakes maintainer=@lucperkins
Example flake.nix
flake-parts のテンプレートが便利
system ごとの設定を書き換えるには flake-parts が良いみたい
$ nix flake init -t github:hercules-ci/flake-parts
devenv 使うなら flake-parts + devenv がある
$ nix flake init --template github:cachix/devenv#flake-parts
Flake inputs schema
nix flake - Nix Reference Manual
Practical Nix flake anatomy: a guided tour of flake.nix | Vladimir Timofeenko's blog
url like schema
nix flake - Nix Reference Manual
ローカルの flake を参照するには?
相対パスもできるらしいが、うまくいく方法がわからない。絶対パスはできた
Use a local directory as flake input – NixOS Asia
参照先に変更を入れても反映されない
参照もとで nix flake update する必要がある
ホットリロード的な仕組みはないのだろうか?
--override-input option が使える。こちらはコマンドに渡すものなので、毎回評価される。
nix run - Nix Reference Manual
--override-input <name> <url>
Flake output schema
Flakes - NixOS Wiki
Flake Outputs | NixOS & Flakes Book
path /nix/store/hoge does not exist的なエラーが出たら
そもそもリポジトリにアクセスできているか?
git add 忘れているファイルはないか?
For flakes in git repos, only files in the working tree will be copied to the store.
Therefore, if you use git for your flake, ensure to git add any project files after you first create them.
ref: Flakes - NixOS Wiki
commit したくないが flake に認識させたい
https://nixos.wiki/wiki/Flakes#How_to_add_a_file_locally_in_git_but_not_include_it_in_commits
nix を使っていないプロジェクトで nix の環境を作るには
nix ファイルは別管理して、symlink 貼る方法が良さそう
Using NixOS on a non-Nix team - Help - NixOS Discourse
flake の場合は、git 管理しないといけないので、うまくいかない
環境構築用の flake を registry に登録して、direnv にそれを参照させる方法があるらしい
nikpkgs.follows
nix flake - Nix Reference Manual
Recommendations for use of flakes' input-follows - Help - NixOS Discourse
Installabels
nix - Nix Reference Manual
flake reference
nix flake - Nix 2.28.1 Reference Manual
github:NixOS/nixpkgs#hello のような書き方
# 以降は attribute。すなわち、flake output の attribute を指定することができる。
nix - Nix 2.28.1 Reference Manual
nix flake update
特定の input だけを update
$ nix flake update --update-input name