如何更新 nix-shell' 开发环境以在 NixOS 以外的系统上运行?

How can I update `nix-shell` development environment to work on systems other than NixOS?

提问人:Chris O'Brien 提问时间:6/4/2023 最后编辑:Chris O'Brien 更新时间:6/5/2023 访问量:243

问:

我有一个适用于我的 NixOS 机器的工作,它为我正在处理的存储库提供了必要的依赖项。我正在尝试使其多样化,以便其他机器也可以使用它。我已经在同一台机器(HP Dev One)上在 M1 MBP、我的 NixOS 机器和 Pop!_OS 的实时启动上测试了它。nix-shell

这是文件本身:shell.nix

{ 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";
  '';
}

我有一个分支,我在其中添加了 ,并在 M1 上对其进行了测试,如此所述。这似乎至少允许完成,但仍然在 M1 和 Pop!_OS 实时启动时出现此错误:libiconvbuildInputscargo clippycargo build

编辑:添加后,M1不再出现此错误++ 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)

在 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"

我也在 https://discourse.nixos.org/t/how-to-update-a-shell-nix-development-environment-to-work-with-other-systems/28727 上对此进行了讨论,随着讨论的增长,我正在更新两者。

Rust Clang Linker-错误 apple-m1 nix-shell

评论

0赞 Charles Duffy 6/4/2023
你能建立一个最小的可重复的例子,足够短,可以包含在问题本身的文本中吗?一个问题需要能够单独回答,这样即使链接中断,人们仍然可以从中学习。
0赞 Charles Duffy 6/4/2023
(就我个人而言,顺便说一句,我认为使用与 Nix Way 背道而驰并引入了平台依赖性,最好避免使用它以支持 fenix 之类的)。rustup
0赞 Chris O'Brien 6/4/2023
@Charles Duffy,我继续用代码更新了它。我之所以添加,是因为它有点习惯和熟悉。我不反对改变它,但我也不熟悉 fenix。rustup

答: 暂无答案