[Nix-dev] sbcl image executables and patch-elf

Eike eike at eknet.org
Mon May 11 10:20:27 CEST 2015


Hi there,

I'm making a program in common lisp using sbcl. I then create a
executable image which results in quite a big file since the whole lisp
is packaged up. When I use nix to build this app, the file that ends up
in nix-store is tiny and not working. It seems to me that the patch-elf
process is stripping things off, but that's just a guess.

Here is a mini example. Install sbcl and do this

$ echo '(defun main () (format t "Hello World!~%"))' > hello.lisp
$ sbcl --load hello.lisp --eval '(sb-ext:save-lisp-and-die "hello" :toplevel (lambda() (main) 0) :executable t)'

then there is a 'hello' executable with about 50mb. Running it prints
the message to stdout.

The same process in a 'hello/default.nix' like this:

    { pkgs ? import <nixpkgs> {} }:
    pkgs.stdenv.mkDerivation {
      name = "hello-0.0.1";
      src = ./.;
      buildPhase = ''
        echo '(defun main () (format t "Hello World!~%"))' > hello.lisp
        ${pkgs.sbcl}/bin/sbcl --load hello.lisp --eval '(sb-ext:save-lisp-and-die "hello" :toplevel (lambda() (main) 0) :executable t)'
        ls -lha *
      '';
      installPhase = ''
        mkdir -p $out/bin
        cp hello $out/bin
      '';
    }

Building it with 'nix-build hello' produces this:

    these derivations will be built:
      /nix/store/7f6dp34myppgf3r0nfkdcxkinwp81g16-hello-0.0.1.drv
    building path(s) ‘/nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1’
    building /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1
    unpacking sources
    unpacking source archive /nix/store/dxk9zf3zd78j63g8ysbfsnmwwsf1gb02-hello
    source root is hello
    patching sources
    configuring
    no configure script, doing nothing
    building
    This is SBCL 1.2.5.nixos, an implementation of ANSI Common Lisp.
    More information about SBCL is available at <http://www.sbcl.org/>.

    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.
    [undoing binding stack and other enclosing state... done]
    [saving current Lisp image into hello:
    writing 5680 bytes from the read-only space at 0x20000000
    writing 3120 bytes from the static space at 0x20100000
    writing 50462720 bytes from the dynamic space at 0x1000000000
    done]
    -rw-r--r-- 1 nixbld1 nixbld 410 May 11 08:11 default.nix
    -rwxr-xr-x 1 nixbld1 nixbld 49M May 11 08:11 hello
    -rw-r--r-- 1 nixbld1 nixbld  44 May 11 08:11 hello.lisp
    installing
    post-installation fixup
    patching ELF executables and libraries in /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1
    /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1/bin/hello
    gzipping man pages in /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1
    stripping (with flags -S) in /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1/bin
    patching script interpreter paths in /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1
    /nix/store/2rhdmlbiklrrsh660ix0db415xyi46wn-hello-0.0.1

The hello executable was 49M after building it. But the one in nix-store
is this:

    l -lha result/bin                                                                                                                                                                                           ~
    insgesamt 272K
    dr-xr-xr-x 2 root nixbld 4,0K  1. Jan 1970  .
    dr-xr-xr-x 3 root nixbld 4,0K  1. Jan 1970  ..
    -r-xr-xr-x 6 root root   262K  1. Jan 1970  hello

What' wrong here?

Thanks in advance!
Eike


More information about the nix-dev mailing list