0

I've got a working nix-shell for my NixOS machine that provides the necessary dependencies for the repository I'm working on. I'm trying to diversify it so that other machines can use it as well. I've tested it on an M1 MBP, my NixOS machine and a live boot of Pop!_OS on the same machine (HP Dev One).

Here is the shell.nix file itself:

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-22.11.tar.gz") {} }:

pkgs.mkShell {
  name = "vrrb-dev";

  nativeBuildInputs = with pkgs; [
    pkg-config
  ];

  buildInputs = with pkgs; [
    # dev tools
    which
    htop
    zlib

    # build dependencies
    clang
    libclang.lib
    rocksdb
    openssl.dev
    rustup
  ] ++ lib.optionals stdenv.isDarwin [
    libiconv
    darwin.apple_sdk.frameworks.Security
    ];

  RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain.toml;

  shellHook = ''
    export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
    export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
    export LIBCLANG_PATH="${pkgs.libclang.lib}/lib";
    export ROCKSDB_LIB_DIR="${pkgs.rocksdb}/lib";
  '';
}

I have a branch where I've added libiconv in the buildInputs, and tested it on the M1, as described here. This seems to at least allow cargo clippy to complete, but cargo build still gives this error on the M1 & Pop!_OS live boot:

EDIT: The M1 is no longer getting this error after adding ++ lib.optionals stdenv.isDarwin [ libiconv darwin.apple_sdk.frameworks.Security ];

M1 MBP:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/Users/eureka/.rustup/toolchains/1.69.0-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/nix/store/...

<shortened to meet max character count but it was all paths>

..."/Users/eureka/.rustup/toolchains/1.69.0-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-90099c6af476d811.rlib" "-lrocksdb" "-lc++" "-framework" "Security" "-lssl" "-lcrypto" "-framework" "Security" "-framework" "Security" "-framework" "CoreFoundation" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/eureka/.rustup/toolchains/1.69.0-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/eureka/Code/vrrb/target/debug/deps/vrrb-cbf8e0f56f41c123" "-Wl,-dead_strip" "-nodefaultlibs" "-undefined" "dynamic_lookup"
  = note: ld: framework not found Security
          clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

On Pop!_OS:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/pop-os/.rustup/toolchains/1.69.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/nix/store...

<Same as above>

..."/home/pop-os/.rustup/toolchains/1.69.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-957b4aff41f8cd46.rlib" "-Wl,-Bdynamic" "-lrocksdb" "-lstdc++" "-lssl" "-lcrypto" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/pop-os/.rustup/toolchains/1.69.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/pop-os/vrrb/target/debug/deps/vrrb-b58fba9b599b43a6" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"

I also have a discussion about this going on at https://discourse.nixos.org/t/how-to-update-a-shell-nix-development-environment-to-work-with-other-systems/28727 and I'm updating both as the discussion grows.

  • Can you build a [mre] short enough to include _in the text of the question itself_? A question needs to be able to be answered standing alone so people can still learn from it even if the links break. – Charles Duffy Jun 04 '23 at 01:50
  • (Personally, btw, I'd argue that using `rustup` is contrary to The Nix Way and introduces platform-dependency, and that one is better off avoiding it in favor of fenix or such). – Charles Duffy Jun 04 '23 at 01:51
  • @Charles Duffy I went ahead and updated it with the code. And I have `rustup` added because it is somewhat customary and familiar. I'm not opposed to changing it but I'm also unfamiliar with fenix. – Chris O'Brien Jun 04 '23 at 05:47

0 Answers0