Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildDotnetModule: cannot set argument installPath relative to $out #368936

Closed
UlyssesZh opened this issue Dec 28, 2024 · 4 comments
Closed

buildDotnetModule: cannot set argument installPath relative to $out #368936

UlyssesZh opened this issue Dec 28, 2024 · 4 comments
Labels
0.kind: bug Something is broken 6.topic: dotnet Language: .NET

Comments

@UlyssesZh
Copy link
Contributor

Describe the bug

The default value of the installPath argument to the buildDotnetModule function is $out/lib/${pname}. While the default value seems good, if you manually set it to $out/lib/${pname}, it will actually be interpreted as /build/source/$out/lib/${pname}, and the $out here is literal (it is a dir with a literal dollar sign in its name). This prevents setting anything relative to $out as installPath.

Steps To Reproduce

Steps to reproduce the behavior:

Take this hello world example (the postInstall line is for debugging purpose):

{
  fetchFromGitHub,
  buildDotnetModule,
  dotnetCorePackages,
} :

buildDotnetModule rec {
  pname = "hello-dotnet";
  version = "0.0.10";
  src = fetchFromGitHub {
    owner = "ofenloch";
    repo = "hello-world";
    rev = version;
    hash = "sha256-tjTeTxwBHIoaA41JplbEVgowiEgPslFVyDdEKkRjnY8=";
  };
  nugetDeps = ./deps.json;
  projectFile = "hello-world.csproj";
  dotnetInstallFlags = [ "-p:PublishSingleFile=false" ];
  executables = [ "hello-world" ];
  dotnet-runtime = dotnetCorePackages.runtime_6_0;
  postInstall = "ls";
  installPath = "$out/lib/${pname}"; # comment out this
}

If you comment out the installPath setting, it builds the package fine. The result structure is this:

$ tree result
result
├── bin
│   └── hello-world
└── lib
    └── hello-dotnet
        ├── hello-world
        ├── hello-world.deps.json
        ├── hello-world.dll
        ├── hello-world.pdb
        ├── hello-world.runtimeconfig.json
        ├── library.dll
        ├── library.pdb
        └── NLog.dll

4 directories, 9 files

However, if you set installPath, the result is like this:

$ tree result
result
└── bin
    └── hello-world

2 directories, 1 file

The files that should be installed in $out/lib/${pname} are not there. You can see from the build log that it is actually installed in a directory literally called $out:

Running phase: installPhase
Executing dotnetInstallHook
  hello-world -> /build/source/$out/lib/hello-dotnet/
'$out'          bin                  hello-world.sln   obj       test
 Dockerfile   data                   lib               scripts
 README.md    hello-world.csproj   nuget.config      src
Finished dotnetInstallHook

Expected behavior

Setting installPath = "$out/lib/${pname}"; shouldn't change the result of the build.

Screenshots

Additional context

Metadata

Notify maintainers

@NixOS/dotnet


Note for maintainers: Please tag this issue in your PR.


Add a 👍 reaction to issues you find important.

@UlyssesZh UlyssesZh added 0.kind: bug Something is broken 6.topic: dotnet Language: .NET labels Dec 28, 2024
@aucub
Copy link
Contributor

aucub commented Dec 28, 2024

local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"

Because installPath is passed as dotnetInstallPath environment variable and not directly as part of the sh script. Will using placeholder meet your needs?

@UlyssesZh
Copy link
Contributor Author

You mean have a placeholder in the script that gets replaced with a string passed as an argument to buildDotnetModule? I think that would work. Would this raise security concerns as script injection is possible?

@aucub
Copy link
Contributor

aucub commented Dec 28, 2024

As is often done.

installPath = "${placeholder "out"}/lib/${pname}";

Would this be correct?

@UlyssesZh
Copy link
Contributor Author

Seems usable.

@aucub aucub closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: dotnet Language: .NET
Projects
None yet
Development

No branches or pull requests

2 participants