Skip to content

Proof of concept, refactor/extract makeDerivationArgument#295105

Closed
roberth wants to merge 21 commits intoNixOS:masterfrom
hercules-ci:poc-makeDerivationArgument
Closed

Proof of concept, refactor/extract makeDerivationArgument#295105
roberth wants to merge 21 commits intoNixOS:masterfrom
hercules-ci:poc-makeDerivationArgument

Conversation

@roberth
Copy link
Member

@roberth roberth commented Mar 11, 2024

Description of changes

A clean refactor of make-derivation.nix to extract a function that only generates the derivation argument.

See commit messages for some more details.

Questions:

  • Does ofborg agree?

    • It's a fairly clean refactor, so I expect it to, but I'm only human
    • It agrees
  • What's the possible performance impact?

    • I've "doubled" the removeAttrs call and I've added at least three function calls.
    • Performance can be regained later by using a derivation making function that omits meson and cmake attributes (unless requested by user in a modular way), although this is hard to measure ahead of time.
    • Not significant
    • Optimizations possible
  • Would it be cleaner to refactor the other way around?

    • I might call what I've done "inside out", pulling out a variable into a function of its scope, and then going from there.
      This is the most mechanical and therefore more reliable method.
      However, now that we know the end state of the small mkDerivation function, we could
      • Start over
      • Rename mkDerivation to makeDerivationArgument
      • Strip all the undesired bits and bobs
      • Copy mkDerivation from this PR
      • End up with a diff that's
        • smaller
        • a very good git blame for the most relevant parts that go into the actual derivation
        • maybe not a great git blame for the other things like passthru, or maybe it's fine, being near the end, and already nicely indented
    • Will follow up

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.

roberth added 17 commits March 11, 2024 17:02
Non-__structuredAttrs compatibility logic should be handled
in a simpler manner if at all in future callers of
makeDerivationArgument.
…dening

This appears only relevant in a stdenv with a compiler. Should reconsider?
… meson and cmake

A generic derivation making function should not be coupled to
specific build tools.

This also moves the logic into separate files for good measure.
This is not complete, as described in the comment.

You can now do:

    nix-repl> :b derivation (stdenv.makeDerivationArgument { name = "hi"; dontUnpack = true; buildPhase = "echo hi > $out"; dontInstall = true; })

or even:

    nix-repl> :b x // { type = "derivation"; }
    error: derivation name missing

    nix-repl> x.drvPath
    "/nix/store/zfnznggsbm48y2g130wg1h891gwbf6s4-hi.drv"

    nix-repl> :b x // { name = "okay"; type = "derivation"; }

    This derivation produced the following outputs:
      out -> /nix/store/szky5bcmil93q0jjqprzc52mia5nfgsc-hi

The latter is obviously NOT recommended, because it does not
produce a standard package attribute set. Point is, new code
could implement that logic without duplicating what's in
Nix's built-in derivation.nix file.
Among many other improvements.
 - For instance, no cmake/meson overhead where it's not needed.
 - Single fixpoint NixOS#273815
@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Mar 11, 2024
@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 Mar 11, 2024
roberth added a commit to hercules-ci/nixpkgs that referenced this pull request Mar 12, 2024
These two commits make for a cleaner commit history and git blame than
NixOS#295105, where this refactor
was developed.

See its commit messages for details and design choices, esp. up to
and including 37f76fd.
@roberth
Copy link
Member Author

roberth commented Mar 12, 2024

Continued in #295378.

@roberth roberth closed this Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: stdenv Standard environment 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant