✨
nix flake check で dotfiles をテストする(Home Manager)
想定読者
- すでにhome-managerでdotfiles構築をしている
- flakeがなにか大体理解している
まえがき
以前、私はNix home-managerをflake環境で使っていながら、テストもせずnix flake updateをGithub Action上で実行していました。
そのため、ローカルリポジトリで更新をするときにエラーで落ちてしまうことがありました。
flake.nixにHome Manager 設定のテストを追加する
Github Actionでテストをする
あとがき
テストを追加することで、home-managerに破壊的変更がされた, 設定のメンテナンスをサボっていて古いなどの理由でローカルでのhome-managerが落ちることを防止することができます。
例:
warning: Git tree '/home/takumi/dotfiles-nix' is dirty
evaluating flake...
checking flake output 'overlays'...
checking overlay 'overlays.default'...
checking flake output 'checks'...
checking derivation checks.x86_64-linux."hm_takumi@sub-laptop"...
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
derivation evaluated to /nix/store/r7h05xa4g9m6sgnzr59r3h4y3p2dvgji-home-manager-generation.drv
checking derivation checks.x86_64-linux."hm_takumi@takumi-Venus-series"...
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
derivation evaluated to /nix/store/q427ki517k5fixvnn2n4a0wbp3afikfz-home-manager-generation.drv
checking flake output 'homeConfigurations'...
checking flake output 'apps'...
checking app 'apps.x86_64-linux.alejandra'...
checking flake output 'formatter'...
checking derivation formatter.x86_64-linux...
derivation evaluated to /nix/store/pqzap3fr5y3pl099r3y7rzblky17sj3c-treefmt.drv
checking flake output 'nixosConfigurations'...
checking NixOS configuration 'nixosConfigurations.um690pro'...
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
running 4 flake checks...
building '/nix/store/3z4farxn09g9v03cx8ixa20n8w21sjr5-home-manager-files.drv'...
building '/nix/store/mcv4vxp7wb7wb5z7clf6pca24l2g3jcx-home-manager-files.drv'...
building '/nix/store/r7h05xa4g9m6sgnzr59r3h4y3p2dvgji-home-manager-generation.drv'...
building '/nix/store/q427ki517k5fixvnn2n4a0wbp3afikfz-home-manager-generation.drv'...
all checks passed!
warning: The check omitted these incompatible systems: aarch64-darwin, aarch64-linux, x86_64-darwin
Use '--all-systems' to check all.
evaluation warningがhome-managerによって出されたエラーになります。
ちなみに、nix flake check --option abort-on-warn trueとすることで警告で停止させることができます。
良いNixライフを!
Discussion