nix-bundle
nix-bundle copied to clipboard
How to bundle a local derivation
I may be missing something obvious but I can't get nix-bundle to build a bundle for a derivation defined in the local directory.
On other comands like nix-env this works via -f .
Is this possible? How?
Unfortunately there is no -f support right now. You need to use a Nix expression like:
./nix-bundle.sh '(import ./my-nix-file.nix {}).attr' /bin/exe
Ok, this gets me a little closer to get this building but it doesn't recognize the attr part but if I level this off it seems to work until the building of the chroot fails:
building '/nix/store/dmx6kg8s5x4c99pmkyp5jl6mga0hj1nh-nix-user-chroot-2c52b5f.drv'...
unpacking sources
unpacking source archive /nix/store/yhvhnlv9l52vdb7i18q0hpkniyc4r35i-nix-user-chroot
source root is nix-user-chroot
patching sources
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/x7fr0bvnwvqvr3zg60di9jxvfwimcw7m-bash-4.4-p23/bin/bash
g++ -o nix-user-chroot -DNIX_PATH='"nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz"' -DNIX_SSL_CERT_FILE='/no-cert-file.crt' -DENV_HOME='' -DENV_PATH='""' main.cpp
main.cpp: In function 'int main(int, char**)':
<command-line>: error: expected primary-expression before '/' token
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'no' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'cert' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'file' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
main.cpp:202:14: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]
202 | write(fd_setgroups, "deny", 4);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:217:10: warning: ignoring return value of 'int chdir(const char*)', declared with attribute warn_unused_result [-Wunused-result]
217 | chdir("/");
| ~~~~~^~~~~
make: *** [Makefile:6: nix-user-chroot] Error 1
builder for '/nix/store/dmx6kg8s5x4c99pmkyp5jl6mga0hj1nh-nix-user-chroot-2c52b5f.drv' failed with exit code 2
Any clues what is going wrong here?
This is nix-bundle from nixpkgs? I probably need to release / update that.
I think you may need to run unset NIX_SSL_CERT_FILE.
Yeah this is the nix-bundle from nixos-20.03. Sorry I didn't mention that. The unset did change nothing.
I seem to be hitting a similar issue with my derivation:
building '/nix/store/dmx6kg8s5x4c99pmkyp5jl6mga0hj1nh-nix-user-chroot-2c52b5f.drv'...
unpacking sources
unpacking source archive /nix/store/yhvhnlv9l52vdb7i18q0hpkniyc4r35i-nix-user-chroot
source root is nix-user-chroot
patching sources
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/x7fr0bvnwvqvr3zg60di9jxvfwimcw7m-bash-4.4-p23/bin/bash
g++ -o nix-user-chroot -DNIX_PATH='"nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz"' -DNIX_SSL_CERT_FILE='/no-cert-file.crt' -DENV_HOME='' -DENV_PATH='""' main.cpp
main.cpp: In function 'int main(int, char**)':
<command-line>: error: expected primary-expression before '/' token
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'no' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'cert' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
<command-line>: error: 'file' was not declared in this scope
main.cpp:221:31: note: in expansion of macro 'NIX_SSL_CERT_FILE'
221 | setenv("NIX_SSL_CERT_FILE", NIX_SSL_CERT_FILE, 1);
| ^~~~~~~~~~~~~~~~~
main.cpp:202:14: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]
202 | write(fd_setgroups, "deny", 4);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:217:10: warning: ignoring return value of 'int chdir(const char*)', declared with attribute warn_unused_result [-Wunused-result]
217 | chdir("/");
| ~~~~~^~~~~
make: *** [Makefile:6: nix-user-chroot] Error 1
builder for '/nix/store/dmx6kg8s5x4c99pmkyp5jl6mga0hj1nh-nix-user-chroot-2c52b5f.drv' failed with exit code 2
cannot build derivation '/nix/store/2azb6d3v6ylgqhq82qxvras5iqsw53si-startup.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/26gjrgx3ns769ilas0zylxi0sdrnndm6-arx.drv': 1 dependencies couldn't be built
error: build of '/nix/store/26gjrgx3ns769ilas0zylxi0sdrnndm6-arx.drv' failed
/nix/store/4h3ksl5hqg9w0s0hlr0dyc6znj1h560v-nix-bundle-0.3.0/share/nix-bundle/nix-bundle.sh failed. Exiting.
unset NIX_SSL_CERT_FILE did not help here either (originally it was set but empty). I also tried running it outside of a nix-shell environment, but this did not change anything.
And as I wasn't clear, I am using a local (non-nixpkgs) derivation, like so:
$ nix-bundle '(pkgs.haskell.packages.ghc865.callPackage ./package.nix {})' /bin/arxiv-pandoc-exe
I can confirm that the suggested approach works for some of my packages. Should I send a PR documenting the workflow in the Readme closing this issue?
Just ran into this as well, so some documentation would be appreciated