Dotnet package build: Access to the path '/homeless-shelter/.dotnet' is denied error

So I’m trying to make a package build for a game. I’ve successfully built the package manually using a nix-shell environment and following the build instructions, but when I turned it into a package build for nixpkgs and ran nix-build -A osu-lazer I got this error.

System.UnauthorizedAccessException: Access to the path '/homeless-shelter/.dotnet' is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.IO.FileSystem.CreateDirectory(String fullPath)
   at System.IO.Directory.CreateDirectory(String path)
   at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateDirectory(String path)
   at Microsoft.DotNet.Configurer.FileSystemExtensions.<>c__DisplayClass0_0.<CreateIfNotExists>b__0()
   at Microsoft.DotNet.Cli.Utils.FileAccessRetrier.RetryOnIOException(Action action)
   at Microsoft.DotNet.Configurer.FileSystemExtensions.CreateIfNotExists(IFileSystem fileSystem, String filePath)
   at Microsoft.DotNet.Configurer.FileSentinel.Create()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)
builder for '/nix/store/j764cq6sxbrkvjb46nma7lizr6bv2161-osu-lazer-2020.306.0.drv' failed with exit code 1
error: build of '/nix/store/j764cq6sxbrkvjb46nma7lizr6bv2161-osu-lazer-2020.306.0.drv' failed

I’ve tried changing the $HOME envar to something else (like “.” or “/tmp”) which “fixes” this issue, but then I get a different error related to the loading of NuGet targets

/nix/store/p51d8cay00f9iyj5aybgfl1ha6pv07mv-dotnet-sdk-3.1.102/sdk/3.1.102/NuGet.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/build/source/osu.Desktop/osu.Desktop.csproj]
/nix/store/p51d8cay00f9iyj5aybgfl1ha6pv07mv-dotnet-sdk-3.1.102/sdk/3.1.102/NuGet.targets(123,5): error :   Name or service not known [/build/source/osu.Desktop/osu.Desktop.csproj]

Build FAILED.

/nix/store/p51d8cay00f9iyj5aybgfl1ha6pv07mv-dotnet-sdk-3.1.102/sdk/3.1.102/NuGet.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/build/source/osu.Desktop/osu.Desktop.csproj]
/nix/store/p51d8cay00f9iyj5aybgfl1ha6pv07mv-dotnet-sdk-3.1.102/sdk/3.1.102/NuGet.targets(123,5): error :   Name or service not known [/build/source/osu.Desktop/osu.Desktop.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.32
builder for '/nix/store/20ili9qq4q9c21c0vv9ip6x5nrq7cwrw-osu-lazer-2020.306.0.drv' failed with exit code 1
error: build of '/nix/store/20ili9qq4q9c21c0vv9ip6x5nrq7cwrw-osu-lazer-2020.306.0.drv' failed

We intentionally don’t provide a valid value for $HOME to catch the case where programs install something into it. The second error comes from the fact that nuget tries to download stuff in a sandbox.
There is a way around that as shown in this package: https://github.com/NixOS/nixpkgs/blob/5ea0258458118ce531a0d66c77e2d6179bdce516/pkgs/servers/nosql/eventstore/default.nix#L57

1 Like

Ok, so from what I can see in the evenstore package they have a deps.nix with all the nuget packages and run dotnet restore using that as the source. I also see that the deps.nix file is generated with a script create-deps.sh which parses the output of the restore log dotnet restore -v m myPackage.sln and generates a deps.nix file. I tried copying this shell file and doing the same, but none of the packages are logged when I run dotnet restore -v m osu!.sln. This is the output I get, which means the deps.nix file doesn’t contain any of the nuget packages.

Unfortunately i haven’t had any time to dedicate to packaging dotnet packages. For now i would just follow https://github.com/NixOS/nixpkgs/blob/fd614a72e97dd5dc43f19709d086251e7aa9e1e4/doc/languages-frameworks/dotnet.section.md to create the shell.

For published/build artifacts you may also need to add:

let
  libs = lib.makeLibraryPath [ stdenv.cc.cc libunwind libuuid icu openssl zlib curl ];
in
mkShell {
  ...
  shellHook = ''
    LD_LIBRARY_PATH = ${libs}:$LD_LIBRARY_PATH
  '';

this is necessary because dotnet will dump some libraries and executables which will likely not be able to find the needed libraries

I’ve made a pull request outlining the issues I’m having building the project.