恢复
我目前正在尝试使用 NixOs 中的 Nix 包管理器安装 dot-net-core-sdk 2.0。
我对 NixOs、Nix、bash 脚本和 ELF 之类的东西都很陌生。但我认为我已经成功地为 dot-net-core-sdk 2.0 创建了有效的 Nix 包描述。
但是,当我尝试创建一个新console
项目时,它抱怨找不到控制台模板:
No templates matched the input template name: console.
故事很长...
我已经定义了我的 Nix 包和构建脚本,如下所示:
dotnet-sdk.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "dotnet-sdk-2.0";
builder = ./builder.sh;
libPath = stdenv.lib.makeLibraryPath
[ lttng-tools kerberos zlib gettext openssl icu libunwind eject stdenv.cc.cc glib ];
src = fetchurl {
url = "https://download.microsoft.com/download/1/B/4/1B4DE605-8378-47A5-B01B-2C79D6C55519/dotnet-sdk-2.0.0-linux-x64.tar.gz";
sha256 = "6059a6f72fb7aa6205ef4b52583e9c041fd128e768870a0fc4a33ed84c98ca6b";
};
}
构建器.sh
source $stdenv/setup
mkdir -p $out/dotnet-sdk
echo "unpacking $src..."
tar xvfa $src -C $out/dotnet-sdk
echo "unpacking dotnet-sdk..."
p=$out/libexec/dotnet
mkdir -p $out/libexec
mv $out/dotnet-sdk $p
ls -lrth $p
patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" --force-rpath --set-rpath $libPath --debug $p/dotnet
echo "libPath"
echo $libPath
mkdir -p $out/bin
ln -s $p/dotnet $out/bin/dotnet
我可以成功构建包
$ sudo nix-build dotnet-sdk.nix
这会产生一个以以下结尾的长输出
...
unpacking dotnet-sdk...
total 136K
-rw-r--r-- 1 nixbld1 nixbld 8.0K Jul 20 23:06 ThirdPartyNotices.txt
-rw-r--r-- 1 nixbld1 nixbld 1.1K Jul 20 23:06 LICENSE.txt
-rwxr-xr-x 1 nixbld1 nixbld 104K Jul 20 23:16 dotnet
drwxr-xr-x 3 nixbld1 nixbld 4.0K Aug 3 19:34 store
drwxr-xr-x 3 nixbld1 nixbld 4.0K Aug 3 19:34 shared
drwxr-xr-x 3 nixbld1 nixbld 4.0K Aug 3 19:34 sdk
drwxr-xr-x 3 nixbld1 nixbld 4.0K Aug 3 19:34 host
drwxr-xr-x 4 nixbld1 nixbld 4.0K Aug 3 19:34 additionalDeps
patching ELF file `/nix/store/f1sankahbj7pss7vjrvbmng9z7gd08a6-dotnet-sdk-2.0/libexec/dotnet/dotnet'
Kernel page size is 4096 bytes
new rpath is `/nix/store/xdv40bsxp4c7m2nw63nrnkadmivczk24-lttng-tools-2.9.3/lib:/nix/store/b7yiqkykhj3lr7dlb3v81rsdasjg32jw-libkrb5-1.15/lib:/nix/store/sg6ri2jj92sbv7f4rvchzr00d24pi4nq-zlib-1.2.11/lib:/nix/store/s70cbg1lh45h3gl6xplz6bi2qdszi2cf-gettext-0.19.8/lib:/nix/store/b6d4mxvj5wdnf28lpww73pllmm0zd2nv-openssl-1.0.2l/lib:/nix/store/03gqmzrbh1pr5izy24gmyw1bfdzpy6q8-icu4c-58.2/lib:/nix/store/f4xflmvgszhrwa1r1jn5fddz8j196qzv-libunwind-1.1/lib:/nix/store/awxn3kfww8hjnd1pyji4zdmmi2x3kvzb-util-linux-2.29.2/lib:/nix/store/lc9cdddv2xv45ighz8znsanjfgkcdgbx-gcc-5.4.0-lib/lib:/nix/store/75pmwxf02m6i4vd3b0iybc3w54xf4r2z-glib-2.50.3/lib'
rpath is too long, resizing...
DT_NULL index is 28
replacing section `.dynamic' with size 560
replacing section `.dynstr' with size 22942
replacing section `.interp' with size 80
this is an executable
using replaced section `.interp'
using replaced section `.dynstr'
using replaced section `.dynamic'
last replaced is 22
looking at section `.interp'
looking at section `.note.ABI-tag'
replacing section `.note.ABI-tag' which is in the way
looking at section `.note.gnu.build-id'
replacing section `.note.gnu.build-id' which is in the way
looking at section `.hash'
replacing section `.hash' which is in the way
looking at section `.dynsym'
replacing section `.dynsym' which is in the way
looking at section `.dynstr'
looking at section `.gnu.version'
first reserved offset/addr is 0x8a38/0x408a38
first page is 0x400000
needed space is 36624
needed space is 36680
needed pages is 1
changing alignment of program header 2 from 2097152 to 4096
changing alignment of program header 3 from 2097152 to 4096
clearing first 38856 bytes
rewriting section `.dynamic' from offset 0x19da8 (size 544) to offset 0x270 (size 560)
rewriting section `.dynstr' from offset 0x4308 (size 22320) to offset 0x4a0 (size 22942)
rewriting section `.dynsym' from offset 0x1d10 (size 9720) to offset 0x5e40 (size 9720)
rewriting section `.hash' from offset 0x1298 (size 2680) to offset 0x8438 (size 2680)
rewriting section `.interp' from offset 0x1238 (size 28) to offset 0x8eb0 (size 80)
rewriting section `.note.ABI-tag' from offset 0x1254 (size 32) to offset 0x8f00 (size 32)
rewriting section `.note.gnu.build-id' from offset 0x1274 (size 36) to offset 0x8f20 (size 36)
rewriting symbol table section 3
libPath
/nix/store/xdv40bsxp4c7m2nw63nrnkadmivczk24-lttng-tools-2.9.3/lib:/nix/store/b7yiqkykhj3lr7dlb3v81rsdasjg32jw-libkrb5-1.15/lib:/nix/store/sg6ri2jj92sbv7f4rvchzr00d24pi4nq-zlib-1.2.11/lib:/nix/store/s70cbg1lh45h3gl6xplz6bi2qdszi2cf-gettext-0.19.8/lib:/nix/store/b6d4mxvj5wdnf28lpww73pllmm0zd2nv-openssl-1.0.2l/lib:/nix/store/03gqmzrbh1pr5izy24gmyw1bfdzpy6q8-icu4c-58.2/lib:/nix/store/f4xflmvgszhrwa1r1jn5fddz8j196qzv-libunwind-1.1/lib:/nix/store/awxn3kfww8hjnd1pyji4zdmmi2x3kvzb-util-linux-2.29.2/lib:/nix/store/lc9cdddv2xv45ighz8znsanjfgkcdgbx-gcc-5.4.0-lib/lib:/nix/store/75pmwxf02m6i4vd3b0iybc3w54xf4r2z-glib-2.50.3/lib
/nix/store/f1sankahbj7pss7vjrvbmng9z7gd08a6-dotnet-sdk-2.0
我现在可以在二进制文件上成功执行help
和函数,而不会出现有关丢失对象文件的奇怪错误:version
dotnet
$ result/bin/dotnet --version
2.0.0
然而,当我尝试创建新的控制台应用程序时,出现以下错误:
$ /etc/nixos/dotnet-sdk/result/bin/dotnet new console
No templates matched the input template name: console.
Templates Short Name Language Tags
-------------------------------------------------
我不知道为什么它找不到模板,但我有一个弱假设,也许--force-rpath
当我在构建脚本中使用 patchelf 修改二进制文件时,我在二进制文件中搞砸了一些东西。
我的包配置和构建脚本看起来没问题吗? (例如,问题是否与我的 Nix 包描述和构建脚本无关)
我是否缺少一些明显的东西,例如在使用 patchelf 修改二进制文件时以某种方式提供一些辅助网络核心目录的链接?
我还可以做些什么来使 net core sdk 2.0 在 NixOs 中工作?