Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bundle a local derivation #55

Open
mgttlinger opened this issue Nov 22, 2019 · 8 comments
Open

How to bundle a local derivation #55

mgttlinger opened this issue Nov 22, 2019 · 8 comments

Comments

@mgttlinger
Copy link
Contributor

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?

@matthewbauer
Copy link
Member

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

@mgttlinger
Copy link
Contributor Author

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?

@matthewbauer
Copy link
Member

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.

@mgttlinger
Copy link
Contributor Author

Yeah this is the nix-bundle from nixos-20.03. Sorry I didn't mention that. The unset did change nothing.

@bbarker
Copy link

bbarker commented Sep 3, 2020

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.

@bbarker
Copy link

bbarker commented Sep 3, 2020

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

@mgttlinger
Copy link
Contributor Author

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?

@piegamesde
Copy link

Just ran into this as well, so some documentation would be appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants