git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Add hook for `nix build`

Open jalil-salame opened this issue 1 year ago • 1 comments

I'd like to test the build of a flake package as part of a hook so I tried calling nix build from inside it which breaks horribly:

pre-commit-run> Build home-manager configuration example.................................Failed
pre-commit-run> - hook id: home-manager-example
pre-commit-run> - exit code: 1
pre-commit-run> warning: you don't have Internet access; disabling some network-dependent features
pre-commit-run> warning: '/nix/var/nix' does not exist, so Nix will use '/build/.local/share/nix/root' as a chroot store
pre-commit-run> error:
pre-commit-run>        … in the condition of the assert statement
pre-commit-run>          at «string»:66:13:
pre-commit-run>            65|           if node.flake or true then
pre-commit-run>            66|             assert builtins.isFunction flake.outputs;
pre-commit-run>              |             ^
pre-commit-run>            67|             result
pre-commit-run>        … while calling the 'isFunction' builtin
pre-commit-run>          at «string»:66:20:
pre-commit-run>            65|           if node.flake or true then
pre-commit-run>            66|             assert builtins.isFunction flake.outputs;
pre-commit-run>              |                    ^
pre-commit-run>            67|             result
pre-commit-run>        (stack trace truncated; use '--show-trace' to show the full trace)
pre-commit-run>        error: unable to download 'https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.571714%2Brev-c3e128f3c0ecc1fb04aef9f72b3dcc2f6cecf370/018d13d4-6560-744b-8254-c10a7ef5adef/source.tar.gz': Couldn't resolve host name (6)

I am expecting this to be closed as wont-fix as it seems to need to either link to the daemon outside the sandbox, or get network access. Both of which are undesirable. If someone has a different idea then be my guest c:

For now I'll work around it by adding the package to packages (although it shouldn't be there).

jalil-salame avatar Jan 17 '24 20:01 jalil-salame

I don't recommend that because commit hooks should be fast (less than a second).

domenkozar avatar Feb 19 '24 07:02 domenkozar