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

buildMavenPackage: Add overrideMavenAttrs function and buildOffline documentation #313152

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tricktron
Copy link
Member

Description of changes

This pr does the following:

  • Adds a overrideMavenAttrs function to make it possible to override attributes of the buildMavenPackage function.
  • Documents the overrideMavenAttrs function.
  • Documents the use case of the buildOffline = true argument for the buildMavenPackage function.

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.05 Release Notes (or backporting 23.05 and 23.11 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.

@tricktron
Copy link
Member Author

@ofborg build lemminx dbeaver java-language-server h2 scenebuilder schemaspy

Copy link
Contributor

@fricklerhandwerk fricklerhandwerk left a comment

Choose a reason for hiding this comment

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

Discussed at #ZurichZHF

};
passthru =
let
makeOverridableMavenPackage = f: origArgs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
makeOverridableMavenPackage = f: origArgs:
makeOverridableMavenPackage = build-package: args:

This is the inner function defined in build-package.nix, right? We may want to be clear about that, and if you want to be even clearer, rename the file and the function to mavenRecipe (because recipes is what we call functions that produce derivations). Using args also matches the @args in build-package (which we may want to move to the front for clarity).

Copy link
Contributor

Choose a reason for hiding this comment

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

@roberth argues we may want a more specific names for the argument, such as mavenArgs.

let
makeOverridableMavenPackage = f: origArgs:
let
ff = f origArgs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ff = f origArgs;
drv = build-package args;

The result of this is a derivation, right?

makeOverridableMavenPackage = f: origArgs:
let
ff = f origArgs;
overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
overrideWith = newArgs: origArgs // lib.toFunction newArgs origArgs;

@roberth says this is slightly less efficient because it always creates a function, but I agree it's (slightly) more readable

Comment on lines 45 to 53
if builtins.isAttrs ff then
(ff // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage f (overrideWith newArgs);
})
else if builtins.isFunction ff then {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage f (overrideWith newArgs);
__functor = self: ff;
}
else ff;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if builtins.isAttrs ff then
(ff // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage f (overrideWith newArgs);
})
else if builtins.isFunction ff then {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage f (overrideWith newArgs);
__functor = self: ff;
}
else ff;
(ff // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage f (overrideWith newArgs);
});

This can never be anything but a derivation, see build-package.nix, which returns the output of mkDerivation. Likely the conditional is a cargo-cult from previous ways of doing things.

doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/maven.section.md Outdated Show resolved Hide resolved
@tricktron
Copy link
Member Author

@roberth Any idea on how to make this work with finalAttrs?
E.g.

jd-cli.overrideMavenAttrs (finalAttrs: old: rec {
...

Comment on lines 46 to 54
if builtins.isAttrs drv then
(drv // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage mavenRecipe (overrideWith newArgs);
})
else if builtins.isFunction drv then {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage mavenRecipe (overrideWith newArgs);
__functor = self: drv;
}
else drv;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if builtins.isAttrs drv then
(drv // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage mavenRecipe (overrideWith newArgs);
})
else if builtins.isFunction drv then {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage mavenRecipe (overrideWith newArgs);
__functor = self: drv;
}
else drv;
drv // {
overrideMavenAttrs = newArgs: makeOverridableMavenPackage mavenRecipe (overrideWith newArgs);
};

IIUC, the recipe function always returns attrs.
Code like this is confusing enough even without dead code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we actually already discussed this during review when we met.

@roberth
Copy link
Member

roberth commented Jun 12, 2024

@roberth Any idea on how to make this work with finalAttrs? E.g.

jd-cli.overrideMavenAttrs (finalAttrs: old: rec {
...

I'm not 100% sure what it should mean, and while it could be done, the "architecture" - functions composed in sequence, but made overridable - does not make this easy, and requires that the logic to make that work have knowledge about all other relevant overriding functions, such as overrideAttrs or even others introduced via passthru.
For this reason I'm proposing to change the architecture in

I'm sure you could make it work for limited use cases, e.g. initially not supporting overrideMavenAttrs after overrideAttrs has been called; I just think effort is better spent on solving the root of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants