Skip to content

Store DerivationOption inside Derivation, put in JSON format#10760

Draft
haenoe wants to merge 1 commit intoNixOS:masterfrom
haenoe:derivation-untangle
Draft

Store DerivationOption inside Derivation, put in JSON format#10760
haenoe wants to merge 1 commit intoNixOS:masterfrom
haenoe:derivation-untangle

Conversation

@haenoe
Copy link
Contributor

@haenoe haenoe commented May 22, 2024

Motivation

This opens the door to derivations that directly specify their options, rather than "stealing" environment variables to do so.

The A-Term derivation format used on disk didn't change --- we cannot do that for existing derivations, so those derivations will continue to not support separate options. But having a more flexible JSON format opens the door to extending the on-disk format in others, like directly using JSON, using CBOR, etc.

Context

Fixes #9846

Progress on #9866 (regarding the "magic values" env field that are used as options)

Depends on #13263
Depends on #14506

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

StringPairs env;
std::string name;

DerivationOptions options;
Copy link
Member

Choose a reason for hiding this comment

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

It seems that having this field in BasicDerivation "denormalizes" it, since information like the value of __impureEnvVars is now stored in both drv.env and drv.options.impureEnvVars, which could get out of sync and would therefore be error-prone to use. Wouldn't it be better to have methods like BasicDerivation::{get,set}ImpureEnvVars()?

Copy link
Member

Choose a reason for hiding this comment

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

@edolstra the goal is, via the JSON format, to allow that stuff to not exist in the env. Then only the legacy decoding results looks like denormalization — but actually I prefer the perspective that there is no denormalization and rather the legacy format simply lacks the expressive power to set one without setting the other.

Does that make sense? It is some subtle philosophical perspective-shifting.

Copy link
Member

Choose a reason for hiding this comment

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

Philisophical doesn't do it justice. It's anticipating a design improvement.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah philosophical before the new feature (better JSON format as input), practical with it.

@fricklerhandwerk fricklerhandwerk added contributor-experience Developer experience for Nix contributors store Issues and pull requests concerning the Nix store labels Jun 24, 2024
@haenoe haenoe force-pushed the derivation-untangle branch from b06017d to 5fab050 Compare June 24, 2024 21:18
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jun 24, 2024
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-06-24-nix-team-meeting-minutes-155/47739/1

Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 20, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 20, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 20, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 20, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Jan 20, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
@haenoe

This comment was marked as outdated.

Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Feb 3, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
Ericson2314 added a commit to obsidiansystems/nix that referenced this pull request Feb 16, 2025
This is a first step towards PR NixOS#10760, and the issues it addresses.
See the Doxygen for details.

Thanks to these changes, we are able to drastically restrict how the
rest of the code-base uses `ParseDerivation`.

Co-Authored-By: HaeNoe <[email protected]>
@Ericson2314
Copy link
Member

OK I rebased this, and it now depends on #13263.

Some unit tests fail in a subtle way --- the rendered JSON is equal, but the value are not. Need to sit in GDB and debug those equality constraints.

@dpulls
Copy link

dpulls bot commented Jul 30, 2025

🎉 All dependencies have been resolved !

@Ericson2314 Ericson2314 changed the title Derivation untangle Store DerivationOption instead Derivation, put in JSON format Jul 30, 2025
Comment on lines 19 to 37
"additionalSandboxProfile": "",
"allowLocalNetworking": false,
"allowSubstitutes": true,
"impureEnvVars": [],
"impureHostDeps": [],
"noChroot": false,
"outputChecks": {
"forAllOutputs": {
"allowedReferences": null,
"allowedRequisites": null,
"disallowedReferences": [],
"disallowedRequisites": [],
"ignoreSelfRefs": true
}
},
"passAsFile": [],
"preferLocalBuild": false,
"requiredSystemFeatures": [],
"unsafeDiscardReferences": {}
Copy link
Member

Choose a reason for hiding this comment

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

So I would, contra our usual JSON policies, not want unused options in here. This is because I want to think of options as an "extensible record", where various Nix implementations are e.g. free to do their own custom options under their own prefix, and whenever an unknown option is encountered, as sensible warning is given.

@Ericson2314 Ericson2314 force-pushed the derivation-untangle branch 2 times, most recently from 7e04b86 to f54ef07 Compare August 6, 2025 22:08
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Aug 6, 2025
@Ericson2314
Copy link
Member

Note that the code touched in #14306 will need to be updated once again with this

@dpulls
Copy link

dpulls bot commented Nov 19, 2025

🎉 All dependencies have been resolved !

This opens the door to derivations that *directly* specify their
options, rather than "stealing" environment variables to do so.

The A-Term derivation format used on disk didn't change --- we cannot do
that for existing derivations, so those derivations will continue to not
support separate options. But having a more flexible JSON format opens
the door to extending the on-disk format in others, like directly using
JSON, using CBOR, etc.

Co-authored-by: HaeNoe <[email protected]>
Co-authored-by: Jonathan Gibbons <[email protected]>
@Ericson2314 Ericson2314 changed the title Store DerivationOption instead Derivation, put in JSON format Store DerivationOption inside Derivation, put in JSON format Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor-experience Developer experience for Nix contributors documentation new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge ParsedDerivation into BasicDerivation

6 participants