Skip to content

buildDotnetModule: add finalAttrs support#331398

Merged
corngood merged 2 commits intoNixOS:masterfrom
MattSturgeon:dotnet-finalAttrs
Aug 8, 2024
Merged

buildDotnetModule: add finalAttrs support#331398
corngood merged 2 commits intoNixOS:masterfrom
MattSturgeon:dotnet-finalAttrs

Conversation

@MattSturgeon
Copy link
Contributor

@MattSturgeon MattSturgeon commented Aug 1, 2024

Description of changes

I've updated the description now that this is ready for review. See the original description below:

Draft PR description

This is an untested proof of concept for adding finalAttrs support to buildDotnetModule, as discussed #331355 (comment)

I've opened this as a draft just to share my conceptual work, it'd probably be best if someone more familiar with build-support/dotnet would take over. @corngood is this something you'd be willing to do?

Otherwise I can continue to work on this and improve based on feedback.

Presumably, we'd also want tests somewhere for this? I'm unfamiliar with how build-support functions are usually tested.

It might be nice to reformat using rfc166 here too, since almost the entire file is being touched anyway...

Allow users to pass arguments to buildDotnetModule in the form:

buildDotnetModule (finalAttrs: {
  # Args
})

Exposing the behaviour of the underlying mkDerivation and allowing packages to be defined in a recursive way that works correctly even when the package is overridden, e.g. using overrideAttrs.

Added some simple test cases that piggyback on the existing structured-attrs test.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: dotnet Language: .NET label Aug 1, 2024
@corngood
Copy link
Contributor

corngood commented Aug 1, 2024

I'm happy to take this over, but I'm honestly not sure what I'd do differently. As for testing, we could have a test similar to pkgs/test/dotnet/structured-attrs to test function vs attrs, or we could just include a commit that makes nexusmods-app use it.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Aug 1, 2024
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Aug 1, 2024
@corngood
Copy link
Contributor

corngood commented Aug 6, 2024

This all looks good to me. Anything I can do to help?

@MattSturgeon
Copy link
Contributor Author

This all looks good to me. Anything I can do to help?

I think it's just the test that is incomplete. I've not had chance to look at it since I pushed it up, but I wanted to come up with some test cases that'd check override and overrideAttrs behave as expected.

Any ideas/suggestions/etc there would be helpful!

I also wonder if the implementation can be simplified using lib.fix or lib.mkOverridable (etc)? I think this isn't possible because finalAttrs should also include finalPackage.

@Aleksanaa
Copy link
Member

Please ignore nixf-tidy in both cases. See #331085

@MattSturgeon MattSturgeon changed the title buildDotnetModule: WIP/POC finalAttrs support buildDotnetModule: add finalAttrs support Aug 6, 2024
@MattSturgeon MattSturgeon marked this pull request as ready for review August 6, 2024 15:27
Allow users to pass arguments to `buildDotnetModule` in the form:

```nix
buildDotnetModule (finalAttrs: {
  # Args
})
```

Exposing the behaviour of the underlying `mkDerivation` and allowing
packages to be defined in a recursive way that works correctly even when
the package is overridden, e.g. using `overrideAttrs`.

Added some simple test cases that piggyback on the existing
`structured-attrs` test.
@MattSturgeon
Copy link
Contributor Author

@corngood I've polished up the test a little and included a test for overriding the copyright string. I think this is ready for review. Thanks for your support so far!

I've checked the tests pass; both nix-build -A tests.dotnet and nix-build -A tests.dotnet.final-attrs build ok.

@corngood corngood self-requested a review August 6, 2024 15:47
Copy link
Contributor

@corngood corngood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. FYI @NixOS/dotnet in case anyone else can review.

@ofborg ofborg bot added the ofborg-internal-error Ofborg encountered an error label Aug 6, 2024
@corngood corngood merged commit 7f2de09 into NixOS:master Aug 8, 2024
@MattSturgeon MattSturgeon deleted the dotnet-finalAttrs branch August 8, 2024 08:52
@eclairevoyant eclairevoyant mentioned this pull request Aug 12, 2024
13 tasks
@MattSturgeon MattSturgeon mentioned this pull request Aug 21, 2024
13 tasks
@cole-h cole-h removed the ofborg-internal-error Ofborg encountered an error label Oct 21, 2024
stdenvNoCC.mkDerivation (
finalAttrs:
let
args = if lib.isFunction fnOrAttrs then fnOrAttrs (args // finalAttrs) else fnOrAttrs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only just got word of the fact that buildDotnetModule has finalAttrs support at wanted to share my thoughts.
(I know this line has been updated since, but it's a bit more obvious what's happening here)

Keep in mind that in the current version, the non-prefixed names (e.g executables) are filtered out of the args after transformation.

AFAICT args // is there so that you can access the non-prefixed values that have been passed to the builder.
This means since they are not passed to the builder, they are not actually part of finalAttrs so you cannot override them.
However you can override the prefixed names.
BUT if you used the non-prefixed name instead of the prefixed name when getting the value from ""finalAttrs"" (aka. args // finalAttrs), you will not get the overridden value.

Do we really need args //? Couldn't the users just do lib.fix or rec if they wanted to access those values? I know it would incur extra noise, but at least they wont have false expectations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For added context, at the time of this PR args was much closer to the finalAttrs, with only nugetDeps being removed. Now there's a few more differences:

args'' = removeAttrs args' [
"nugetDeps"
"runtimeId"
"installPath"
"executables"
"projectFile"
"projectReferences"
"runtimeDeps"
"disabledTests"
"testProjectFile"
"buildType"
"selfContainedBuild"
"useDotnet"
"useAppHost"
"dotnet-sdk"
];

As per #331398 (comment), the "correct" approach would probably be to add a overrideDotnetAttrs function, similar to python's overridePythonAttrs.

@TomaSajt TomaSajt mentioned this pull request Jan 6, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: dotnet Language: .NET 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants