Ambiguity when parsing version string with buildDotnetModule

Here is the error:

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/stdenv/generic/make-derivation.nix:395:7:

          394|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          395|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          396|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: toInt: Ambiguity in interpretation of "05" between octal and zero padded integer.

[jadelynnmasker@ananda:~/Code/nixpkgs/callan-hodgskin]$ nix-shell --show-trace
warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'buildInputs' of derivation 'nix-shell'

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/stdenv/generic/make-derivation.nix:395:7:

          394|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          395|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          396|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       … while evaluating derivation 'invention-0-unstable-2024-05-10'
         whose name attribute is located at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'versionForDotnet' of derivation 'invention-0-unstable-2024-05-10'

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/build-support/dotnet/build-dotnet-module/default.nix:163:3:

          162|   # The actual version attr is saved in InformationalVersion, which accepts an arbitrary string
          163|   versionForDotnet = if !(lib.hasAttr "version" args) || args.version == null
             |   ^
          164|   then null else let

       … from call site

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/build-support/dotnet/build-dotnet-module/default.nix:165:18:

          164|   then null else let
          165|     components = lib.pipe args.version [
             |                  ^
          166|       lib.splitVersion

       … while calling 'pipe'

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/lib/trivial.nix:61:15:

           60|   */
           61|   pipe = val: functions:
             |               ^
           62|     let reverseApply = x: f: f x;

       … while calling 'reverseApply'

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/lib/trivial.nix:62:27:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                           ^
           63|     in builtins.foldl' reverseApply val functions;

       … while calling anonymous lambda

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/build-support/dotnet/build-dotnet-module/default.nix:168:20:

          167|       (lib.filter (x: (lib.strings.match "[0-9]+" x) != null))
          168|       (lib.filter (x: (lib.toInt x) < 65535)) # one version component in dotnet has to fit in 16 bits
             |                    ^
          169|     ];

       … from call site

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/pkgs/build-support/dotnet/build-dotnet-module/default.nix:168:24:

          167|       (lib.filter (x: (lib.strings.match "[0-9]+" x) != null))
          168|       (lib.filter (x: (lib.toInt x) < 65535)) # one version component in dotnet has to fit in 16 bits
             |                        ^
          169|     ];

       … while calling 'toInt'

         at /nix/store/b7s2krf1lfdvawsczmhkfmf9rzam3qf4-nixos-stable-20240506/lib/strings.nix:1039:11:

         1038|   */
         1039|   toInt = str:
             |           ^
         1040|     let

       error: toInt: Ambiguity in interpretation of "05" between octal and zero padded integer.

According to this readme, when targeting a non-standard versioning, you are supposed to use the format 0-unstable-YYYY-MM-DD, but I get this error when I try to do so. Not sure if it’s a bug or what.

I should clarify, I am trying to contribute a dotnet library & game that hasn’t been packaged in linux yet, and I am using a shell.nix to pull this package in to test.

{ pkgs ? import <nixpkgs> {
    config.allowUnfree = true;
  }
}:

let
  invention = import ./invention/default.nix {
    inherit (pkgs) lib fetchFromGitLab buildDotnetModule;
  };
in
pkgs.mkShell {
  buildInputs = [
    pkgs.dotnet-sdk
    pkgs.makeWrapper
    invention
  ];
}

removing the leading zero seems to fix the issue

You should post your invention drv. This snippet does not contain the critical part.

Here is default.nix:

{ lib
, fetchFromGitLab
, buildDotnetModule
}:
buildDotnetModule rec {
  pname = "invention";
  version = "0-unstable-2024-05-10";

  src = fetchFromGitLab {
    owner = "hodgskin-callan";
    repo = "Invention";
    rev = "f228ca2ab74c28dc6146d138a76f09492ebb6bd2";
    hash = "sha256-kw61sn6QmjEZPxv5QtcaS3DWUaLshD3+1vQalAduyEk=";
  };

  nugetDeps = ./deps.nix;

  projectFile = "InvGen/InvGen.csproj";

  meta = {
    description = ''
      Develop native apps for iOS, Android, Windows and WebAssembly with 100%
      code sharing using Visual Studio and C#.NET.
    '';
    homepage = "https://gitlab.com/hodgskin-callan/Invention";
    license = lib.licenses.mit;
    platforms = lib.platforms.linux;
    maintainers = [
      {
        name = "Jade Lynn Masker";
        email = "donottellmetonottellyou@gmail.com";
      }
    ];
  };
}

Again, changing it to 0-unstable-2024-5-10 “works” (It still doesn’t compile yet: the error is irrelevant to this issue)

That drv evals fine for me when callPackageing it and using this little hack to avoid needing a deps file:

  nugetDeps = builtins.toFile "foo" "_: [ ]";

For the module to build, I needed ./deps.nix and I had to rename TargetFrameworks to TargetFramework in "InvGen/InvGen.csproj", but I had no Ambiguity error:

invention/default.nix
{ lib
, fetchFromGitLab
, buildDotnetModule
}:
buildDotnetModule {
  pname = "invention";
  version = "0-unstable-2024-05-10";

  src = fetchFromGitLab {
    owner = "hodgskin-callan";
    repo = "Invention";
    rev = "f228ca2ab74c28dc6146d138a76f09492ebb6bd2";
    hash = "sha256-kw61sn6QmjEZPxv5QtcaS3DWUaLshD3+1vQalAduyEk=";
  };

  nugetDeps = ./deps.nix;

  projectFile = "InvGen/InvGen.csproj";

  preBuild = ''
    sed -i "s/TargetFrameworks/TargetFramework/g" "InvGen/InvGen.csproj"
  '';

  meta = {
    description = ''
      Develop native apps for iOS, Android, Windows and WebAssembly with 100%
      code sharing using Visual Studio and C#.NET.
    '';
    homepage = "https://gitlab.com/hodgskin-callan/Invention";
    license = lib.licenses.mit;
    platforms = lib.platforms.linux;
    maintainers = [
      {
        name = "Jade Lynn Masker";
        email = "donottellmetonottellyou@gmail.com";
      }
    ];
  };
}
invention/deps.nix
# This file was automatically generated by passthru.fetch-deps.
# Please dont edit it manually, your changes might get overwritten!

{ fetchNuGet }: [
  (fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.1.0"; sha256 = "08vh1r12g6ykjygq5d3vq09zylgb84l63k49jc4v8faw9g93iqqm"; })
  (fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies"; version = "1.0.2"; sha256 = "0i42rn8xmvhn08799manpym06kpw89qy9080myyy2ngy565pqh0a"; })
  (fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies.net48"; version = "1.0.2"; sha256 = "10ry214g6v4s57vmk1pyqz8z3fsqxl44qyn68y0rrfjcpn29sh5m"; })
  (fetchNuGet { pname = "NETStandard.Library"; version = "2.0.3"; sha256 = "1fn9fxppfcg4jgypp2pmrpr6awl3qz1xmnri0cygpkwvyx27df1y"; })
  (fetchNuGet { pname = "Newtonsoft.Json"; version = "13.0.1"; sha256 = "0fijg0w6iwap8gvzyjnndds0q4b8anwxxvik7y8vgq97dram4srb"; })
  (fetchNuGet { pname = "StringSyntaxPolyfill"; version = "1.1.0"; sha256 = "0mr7i1kk511x7nwykkqfnhk1a9skiyccvphr6wx91nxa5xksmaw6"; })
]

Also, I can’t help but notice that you’re in the ~/Code/nixpkgs/callan-hodgskin directory. If you’re in the nixpkgs repo, packages should be added to the pkgs directory.

For example:

  • I put invention.nix and deps.nix in ~/nixpkgs/pkgs/by-name/in/invention/
$ tree pkgs/by-name/in/invention/
pkgs/by-name/in/invention/
├── default.nix
└── deps.nix

1 directory, 2 files
  • Added the following line in ~/nixpkgs/pkgs/top-level/all-packages.nix:
  invention = callPackage ../by-name/in/invention  { };
  • Inside ~/nixpkgs, I built the module with:
$ nix-build . -A invention
  • Finally, the result was the following:
$ tree ./result/
./result/
└── lib
    └── invention
        ├── InvGen.exe
        ├── InvGen.exe.config
        ├── InvGen.pdb
        ├── InvGen.xml
        ├── Inv.Library.dll
        ├── Inv.Library.pdb
        ├── Inv.Library.xml
        ├── Inv.Windows.dll
        ├── Inv.Windows.pdb
        ├── Inv.Windows.xml
        └── Newtonsoft.Json.dll

3 directories, 11 files
1 Like

Hey thanks! I wasn’t in the repo, it was just a folder named nixpkgs btw.

Do you have any tips about setting up an environment for building and testing nixpkgs/ contributing? I found the (very detailed) contributing guides on the nixpkgs repo, but it would be my first time doing any major contribution to any project.

Also, I noticed your deps.nix says it was generated by passthru.fetch-deps. What is that tool, and how is it used?

Thanks again!

1 Like

Simply clone nixpkgs, cd into it, do your changes and then nix-build -A yourpackagehere.

1 Like

Well, what you were doing initially wasn’t wrong, really. I built the module using the shell as well and it worked, but only after I had the deps.nix from fetch-deps. Before that, I tried the following:

pkgs.mkShell {
  buildInputs = [
    pkgs.dotnet-sdk
    pkgs.makeWrapper
-   invention
+   invention.fetch-deps
  ];
}

But it complained that it didn’t find the destination file to put deps.nix.

So, although you can build packages using a shell environment, it’s probably best to use the nixpkgs repo in situations where you need helper tools, like fetch-deps, which you can run with:

$ nix-build -A invention.fetch-deps

I know that things can be a bit overwhelming at first, but the best thing you can do is try to limit the scope of what you’re looking for and to divide the problem/task into smaller parts.

For example, you might want to look at the NixOS Wiki first or the specific entry in the nixpkgs docs.

I also found out that searching in the nixpkgs GitHub repo is great if you want to look for something specific. For instance, searching for dotnet fetch shows you the script where fetch-deps is used, where it is in the docs and some other examples.

There are a lot of things to learn in nix. Thankfully, there are a lot of nice learning material, like the ones in awesome-nix and Learn Nix that you can try.

I wish you the best with your nix journey and if you’re ever stuck, don’t hesitate to ask for help again.

1 Like