dotnet restore failed when using nix-build, but works when under nix-shell --pure
NickName:xiang0x48 Ask DateTime:2021-10-04T12:40:02

dotnet restore failed when using nix-build, but works when under nix-shell --pure

I'm trying to use nix for building dotnet (sdk 5) projects.

The configuration is something like

stdenv.mkDerivation {
# builder = "${bash}/bin/bash";
# args = [ ./builder.sh ];
name = "mypackage";
src = ./.;
HOME = "/tmp/test-home";
DOTNET_CLI_TELEMETRY_OPTOUT = 1;
nativeBuildInputs = [ nodejs ];
buildInputs = [ dotnet openssl cacert  ];
configurePhase = ''
  export HOME=$PWD/home
  runHook preConfigure
  dotnet nuget list source
  dotnet nuget locals all --list
  dotnet restore
  runHook postConfigure
'';
buildPhase = ''
  export DOTNET_CLI_TELEMETRY_OPTOUT=1
  export DOTNET_NOLOGO=1
  ${dotnet}/bin/dotnet publish ProjectDirectory --self-contained -r linux-x64 -c Release
'';
installPhase = ''
  mkdir -p $out/
'';

};

The HOME attribute in argument for stdenv.mkDerivation is for nix-shell only. Since nix-shell will inherit normal $HOME, I need to set $HOME to another empty directory to mimic behavior of build phase.

  • When using nix-shell and run dotnet restore manually, it works fine.

  • When using nix-build, build failed with following error when running dotnet restore

    Registered Sources:

    1. nuget.org [Enabled] https://api.nuget.org/v3/index.json http-cache: /build/PROJECTNAME/home/.local/share/NuGet/v3-cache global-packages: /build/PROJECTNAME/home/.nuget/packages/ temp: /build/NuGetScratch plugins-cache: /build/PROJECTNAME/home/.local/share/NuGet/plugins-cache Determining projects to restore... /nix/store/fvfyn01fjmawvyn7vlhhrgkzyy6321wl-dotnet-sdk-5.0.202/sdk/5.0.202/NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/build/PROJECTNAME/PET-CT-machine-service.sln] /nix/store/fvfyn01fjmawvyn7vlhhrgkzyy6321wl-dotnet-sdk-5.0.202/sdk/5.0.202/NuGet.targets(131,5): error : Name or service not known (api.nuget.org:443) [/build/PROJECTNAME/PET-CT-machine-service.sln] /nix/store/fvfyn01fjmawvyn7vlhhrgkzyy6321wl-dotnet-sdk-5.0.202/sdk/5.0.202/NuGet.targets(131,5): error : Name or service not known [/build/tomopioneer/PET-CT-machine-service.sln]

What's the difference between nix-build and nix-shell --pure when HOME is manually set?

By reading code from github NixOS/nixpkgs repository, it seems several dotnet packages were using nuget manually and using dotnet restore with local source. Is that necessary?


I've make more tests about api.nuget.org.

running curl https://api.nuget.org/v3/index.json -v, I got:

  • works fine when directly run under terminal of nixos
  • works fine in nix-shell --pure
  • error in nix-build, curl: (6) Could not resolve host: api.nuget.org

Copyright Notice:Content Author:「xiang0x48」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69430978/dotnet-restore-failed-when-using-nix-build-but-works-when-under-nix-shell-pur

More about “dotnet restore failed when using nix-build, but works when under nix-shell --pure” related questions

dotnet restore failed when using nix-build, but works when under nix-shell --pure

I'm trying to use nix for building dotnet (sdk 5) projects. The configuration is something like stdenv.mkDerivation { # builder = "${bash}/bin/bash"; # args = [ ./builder.sh ]; name = "

Show Detail

Can I replicate what nix-build does with nix-shell and cabal build?

I'm using the splendid Haskell library Miso, which recommends using Nix. The README walks us through a simple project which can be built with nix-build. The documentation for Miso hints that I can ...

Show Detail

Aspell dictionaries missing when installed into nix-shell

When I install the Aspell package with the Aspell dictionary for English into my global env using Nix on Mac OSX: $ nix-env -iA nixpkgs.aspell nixpkgs.aspellDicts.en Then Aspell behaves as I would

Show Detail

dotnet restore works locally but fails when building Docker container

If I create a new console application using dotnet classlib -lang f# -o hello-docker, cd into the directory and then run dotnet restore, everything works as expected. However, if I add a Dockerfil...

Show Detail

dotnet restore fail on Ubuntu20.04 while using dotnet-sdk-5.0

I have .NET5.0 application which I'm trying to set up on Ubuntu20.04 under WLS2. When I run dotnet restore command, nuget gives me the following error for all the packages. Determining projects to

Show Detail

dotnet restore fails when using nuget proxy on nexus

I have a nuget proxy on Nexus (v 3.9.0-01) on an internal network. I haven't populated the local Nexus repo myself (and don't know how it was done or if any issues arose), however, I can upload new

Show Detail

nix-shell error - mkdir: cannot create directory '/nix/store/...': Read-only file system

I'm using nix-shell to debug my package. The configure script looks like this: configurePhase = '' mkdir -p $out ... ''; When running via nix-build, this code is OK, but when running with nix.

Show Detail

dotnet restore uses corporate Proxy without configuration

I have no Proxy Configuration in the Project or in my Environment Variables. Still, dotnet restore gets the Proxy configured somehow, but not fully, as i get an 407-ProxyAuthenticationRequired. When

Show Detail

Dotnet Restore Failed on Build Server

I have a little dotnet core application and want to build it on jenkins. In order to make it happen, ive installed dotnet core on the build slave. Locally i can restore with the same command succe...

Show Detail

Dotnet restore Docker fail

There is problem with Docker and command dotnet restore. I have the docker file: FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.micro...

Show Detail