NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.27k stars 14.25k forks source link

dotnet restore fails when building a package with dotnet lockfiles #347310

Open gepbird opened 1 month ago

gepbird commented 1 month ago

nuget-packageslock2nix utilizes dotnet's packages.lock.json to resolve dependencies rather than using a deps.nix file.

Describe the bug

After https://github.com/NixOS/nixpkgs/pull/327651, the example project doesn't build with the error message: error NU1101: Unable to find package <YOUR_PACKAGE>. No packages exist with this id in source(s): _nix

Steps To Reproduce

Build nuget-packageslock2nix's example project using a version of nixpkgs where the issue is present (also update the flake itself to avoid an unrelated issue): nix build 'github:mdarocha/nuget-packageslock2nix?dir=example' --override-input nixpkgs github:NixOS/nixpkgs/d3ca5027fabc6f3c8df7849fcbb7afaa3903c17b --override-input nuget-packageslock2nix github:mdarocha/nuget-packageslock2nix

Expected behavior

The example project builds, just like using a one commit older nixpkgs: nix build 'github:mdarocha/nuget-packageslock2nix?dir=example' --override-input nixpkgs github:NixOS/nixpkgs/7402aa90cff52a03f14e680346fa4038a1e17e93 --override-input nuget-packageslock2nix github:mdarocha/nuget-packageslock2nix

Additional context

Full build log: https://gist.github.com/gepbird/421dafce0f63854cc834b18ee056de27

Notify maintainers

@corngood

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
fetching path input 'path:/nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source'
 - system: `"x86_64-linux"`
 - host os: `Linux 6.10.9-zen1, NixOS, 24.11 (Vicuna), 24.11.20241004.bc947f5`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Lix, like Nix) 2.91.0
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/gep/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/gep/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/gep/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/gep/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/cfl6rqw64ndbh2m0qapg410jf4xmycia-lix-2.91.0/share`
 - nixpkgs: `/nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source`

Add a :+1: reaction to issues you find important.

anpin commented 1 month ago

For me restore fails, but with a different error error NU1403: Package content hash validation failed for <package_name>. The package is different than the last restore.. I use regular deps.nix generated with nuget-to-nix.

gepbird commented 1 month ago

For me restore fails, but with a different error error NU1403: Package content hash validation failed for <package_name>. The package is different than the last restore.. I use regular deps.nix generated with nuget-to-nix.

@anpin Interesting, I recently updated another dotnet app, regenerated deps.nix, and it builds without any issues. Can you share some details how you got that error?

anpin commented 1 month ago

@gepbird here you go

git clone https://github.com/anpin/restore-with-lock
cd restore-with-lock
nix run .#make-deps
nix build
Cli> Running phase: unpackPhase
Cli> unpacking source archive /nix/store/s1891z4fd3x0kanaz73dw8pfvpricq9j-Cli
Cli> source root is Cli
Cli> Running phase: patchPhase
Cli> Running phase: configureNuget
Cli> The template "NuGet Config" was created successfully.
Cli> Processing post-creation actions...
Cli> Running phase: updateAutotoolsGnuConfigScriptsPhase
Cli> Running phase: configurePhase
Cli> Executing dotnetConfigureHook
Cli>   Determining projects to restore...
Cli> /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for Argu.6.2.4. The package is different than the last restore.
Cli> /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for MessagePack.Annotations.2.5.172. The package is different than the last restore.
Cli> /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for System.Configuration.ConfigurationManager.4.4.0. The package is different than the last restore.
Cli> /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for System.Security.Cryptography.ProtectedData.4.4.0. The package is different than the last restore.
Cli> /build/Cli/Cli.fsproj : error NU1403:
Cli>   Failed to restore /build/Cli/Cli.fsproj (in 366 ms).
error: builder for '/nix/store/z1brbiayrw9c2gzi5d55jsrshr7fk292-Cli-0.0.1.drv' failed with exit code 1;
       last 10 log lines:
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Executing dotnetConfigureHook
       >   Determining projects to restore...
       > /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for Argu.6.2.4. The package is different than the last restore.
       > /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for MessagePack.Annotations.2.5.172. The package is different than the last restore.
       > /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for System.Configuration.ConfigurationManager.4.4.0. The package is different than the last restore.
       > /build/Cli/Cli.fsproj : error NU1403: Package content hash validation failed for System.Security.Cryptography.ProtectedData.4.4.0. The package is different than the last restore.
       > /build/Cli/Cli.fsproj : error NU1403:
       >   Failed to restore /build/Cli/Cli.fsproj (in 366 ms).
       For full logs, run 'nix log /nix/store/z1brbiayrw9c2gzi5d55jsrshr7fk292-Cli-0.0.1.drv'.
gepbird commented 1 month ago

@anpin big thanks for the reproduction repo, I see your error.

However it is caused by a different PR: https://github.com/NixOS/nixpkgs/pull/343837 (2c97d67f62326476785189e226bfa7bdb27bfd7b)

To reproduce it on the first bad commit: nix shell github:anpin/restore-with-lock --override-input nixpkgs github:NixOS/nixpkgs/2c97d67f62326476785189e226bfa7bdb27bfd7b First error is: error NU1403: Package content hash validation failed for Argu.6.2.4. The package is different than the last restore.

Going back one nixpkgs commit, that error message changes: nix shell github:anpin/restore-with-lock --override-input nixpkgs github:NixOS/nixpkgs/4f47ddf1d781e902441bc642ae018f39b3b3117a Error is: ln: failed to create symbolic link '/build/nuget.XR72Ot/fallback/microsoft.aspnetcore.app.runtime.linux-x64/8.0.8': File exists

The "File exists" error was introduced in the same commit where I have this issue, d3ca5027fabc6f3c8df7849fcbb7afaa3903c17b. To reproduce it you need to run nix run .#make-deps and nix build (as in your previous comment) using the specific nixpkgs commit. For some reason just going into a devshell like previously won't error out. And with the previous commit, 7402aa90cff52a03f14e680346fa4038a1e17e93, your demo app builds without issues.

corngood commented 1 month ago

On latest, I had to add PATH=${dotnet-sdk_8}/bin:$PATH to make nuget-to-nix to work in make-deps. That was a breaking change to avoid ambiguity in the dotnet CLI being used.

After doing that, I can successfully build the project, but only if I remove packages.lock.json.

It makes sense that package validation could fail when packages are patched by nixpkgs, but 'Argu' doesn't seem to have any (substantial) differences.

For reference, this is what's in project.assets.json after make-deps:

  "libraries": {
    "Argu/6.2.4": {
      "sha512": "RuANu8+L1P2HWozmbRXkj6MQGYwP5DL2wdARfBPtRjsLS8TSgwYjOKxMnY5LtjmHLlMBD3u2+MfbAy8xMGg8Qg==",
      "type": "package",
      "path": "argu/6.2.4",
      "files": [
        ".nupkg.metadata",
        ".signature.p7s",
        "argu.6.2.4.nupkg.sha512",
        "argu.nuspec",
        "lib/netstandard2.0/Argu.dll",
        "lib/netstandard2.0/Argu.xml",
        "logo.png"
      ]
    },

and in the build:

  "libraries": {
    "Argu/6.2.4": {
      "type": "package",
      "path": "argu/6.2.4",
      "files": [
        ".nix-patched",
        ".nupkg.metadata",
        "argu.nuspec",
        "lib/netstandard2.0/Argu.dll",
        "lib/netstandard2.0/Argu.xml",
        "logo.png"
      ]
    },