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

Example nix shell #13

Closed
ghost opened this issue Apr 29, 2021 · 6 comments
Closed

Example nix shell #13

ghost opened this issue Apr 29, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 29, 2021

It is not clear how to use this library. Is this the correct way:

let
  pkgs = import <nixpkgs> {};
  fenix = pkgs.callPackage "${
      fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz"
    }/packages.nix" { };
in
  pkgs.mkShell {
    buildInputs = [
      fenix.default.rustc
    ];
  }

This nix shell produces the following error: https://gist.github.com/fctorial/5a7257a1c6a450802e55c590f3f2c4e1

@figsoda
Copy link
Member

figsoda commented Apr 30, 2021

should be fixed by f247696

@ghost
Copy link
Author

ghost commented Apr 30, 2021

@figsoda Yes that error is gone. Can you tell me how to add support for x86_64-linux-musl target?

@figsoda
Copy link
Member

figsoda commented Apr 30, 2021

There is a cross compiling with naersk example in the examples section. The example is targetting aarch64-unknown-linux-gnu, but targeting x86_64-unknown-linux-musl would be pretty similar except you don't need to configure the linker.

If you just want to use it with nix shell,

with fenix; # or rust-nightly if you are using the overlay, or fenix.packages.x86_64-linux if you are using flakes
combine [
  minimal.rustc
  minimal.cargo
  targets.x86_64-unknown-linux-musl.latest.rust-std
]

should work

@ghost
Copy link
Author

ghost commented Apr 30, 2021

@figsoda I tried it and the executables built using this config are crashing with segmentation fault:

$ cat shell.nix
let
  pkgs = import <nixpkgs> {};
  fenix = import "${
      fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz"
    }/packages.nix";
in
  pkgs.mkShell {
    buildInputs = [
      (with fenix;
      combine [
        minimal.rustc
        minimal.cargo
        targets.x86_64-unknown-linux-musl.latest.rust-std
      ])
    ];
  }
$ nix-shell

[nix-shell:~/src/pgs/sql]$ cargo new app
     Created binary (application) `app` package

[nix-shell:~/src/pgs/sql]$ cd app

[nix-shell:~/src/pgs/sql/app]$ cargo run --target=x86_64-unknown-linux-musl
   Compiling app v0.1.0 (/home/fctorial/src/pgs/sql/app)
    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
     Running `target/x86_64-unknown-linux-musl/debug/app`
Segmentation fault (core dumped)

[nix-shell:~/src/pgs/sql/app]$

@figsoda
Copy link
Member

figsoda commented Apr 30, 2021

Not sure what the problem is

It worked on my machine
~/hello
❯ cargo init
     Created binary (application) package

~/hello on  main [?]
❯ nix-shell
these 3 derivations will be built:
  /nix/store/3l6bam1py5v2gy173yqqjzdmayk41pnm-rustc-nightly-with-std-2021-04-30.drv
  /nix/store/cmgbhxa1sj80x78bk1y47a52g10li5mp-rust-std-nightly-2021-04-30.drv
  /nix/store/9wpfxn390nq3m5qd6jarkr4yrhi9znh4-rust-nightly-mixed.drv
these 3 paths will be fetched (90.96 MiB download, 418.95 MiB unpacked):
  /nix/store/57pxaivl23abqbn1wismqlf6vyl6diiz-cargo-nightly-2021-04-30
  /nix/store/fr97y4fx7abiczx7f3ivvclybz65js24-rust-std-nightly-2021-04-30
  /nix/store/qlcvwqc7hrpa2v5v8i0f42qjbhqqa8qc-rustc-nightly-2021-04-30
copying path '/nix/store/fr97y4fx7abiczx7f3ivvclybz65js24-rust-std-nightly-2021-04-30' from 'https://nix-community.cachix.org'...
copying path '/nix/store/57pxaivl23abqbn1wismqlf6vyl6diiz-cargo-nightly-2021-04-30' from 'https://nix-community.cachix.org'...
copying path '/nix/store/qlcvwqc7hrpa2v5v8i0f42qjbhqqa8qc-rustc-nightly-2021-04-30' from 'https://nix-community.cachix.org'...
building '/nix/store/cmgbhxa1sj80x78bk1y47a52g10li5mp-rust-std-nightly-2021-04-30.drv'...
unpacking sources
unpacking source archive /nix/store/pqy93a24zrflyzzjr1kmrw5i79i659za-rust-std-nightly-x86_64-unknown-linux-musl.tar.gz
source root is rust-std-nightly-x86_64-unknown-linux-musl
setting SOURCE_DATE_EPOCH to timestamp 1619729013 of file rust-std-nightly-x86_64-unknown-linux-musl/version
patching sources
configuring
no configure script, doing nothing
building
no Makefile, doing nothing
installing
patching script interpreter paths in install.sh
install.sh: interpreter directive changed from "#!/bin/bash" to "/nix/store/68c5b0h2w2ab57sbas1b4m073ik8hlm5-bash-4.4-p23/bin/bash"
install: creating uninstall script at /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/uninstall.sh
install: installing component 'rust-std-x86_64-unknown-linux-musl'

    rust std installed.

patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-3b4724f13fd9b314.so
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/libtest-3661a07a52ba28ac.so
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/Scrt1.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbegin.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtend.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crt1.o
patchelf: wrong ELF type
shrinking /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o
patchelf: wrong ELF type
patching script interpreter paths in /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30
checking for references to /build/ in /nix/store/gadih0crhgq40x8hcd7gz8qxwiysywvl-rust-std-nightly-2021-04-30...
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
patchelf: wrong ELF type
building '/nix/store/3l6bam1py5v2gy173yqqjzdmayk41pnm-rustc-nightly-with-std-2021-04-30.drv'...
building '/nix/store/9wpfxn390nq3m5qd6jarkr4yrhi9znh4-rust-nightly-mixed.drv'...

[nix-shell:~/hello]$ cargo run --target x86_64-unknown-linux-musl
   Compiling hello v0.1.0 (/home/figsoda/hello)
    Finished dev [unoptimized + debuginfo] target(s) in 2.42s
     Running `target/x86_64-unknown-linux-musl/debug/hello`
Hello, world!

@figsoda
Copy link
Member

figsoda commented Apr 30, 2021

Seems like nixos or musl issue:
rust-lang/rust#74757
rust-lang/rust#81987
NixOS/nixpkgs#94228

@ghost ghost closed this as completed Apr 30, 2021
This issue was closed.
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

1 participant