Skip to content

Make the JSON format for derivation use basename store paths#13980

Merged
roberth merged 1 commit intoNixOS:masterfrom
obsidiansystems:drv-json-issue-13570
Sep 17, 2025
Merged

Make the JSON format for derivation use basename store paths#13980
roberth merged 1 commit intoNixOS:masterfrom
obsidiansystems:drv-json-issue-13570

Conversation

@Ericson2314
Copy link
Member

Motivation

See #13570 for details --- the idea is that included the store dir in store paths makes systematic JSON parting with e.g. Serde, Aeson, nlohmann, or similiar harder.

After talking to Eelco, we are changing the Derivation format right away because not only is nix derivation technically experimental, we think it is also less widely used in practice than, say, nix path-info.

Context

Progress on #13570


Add 👍 to pull requests you find important.

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

@github-actions github-actions bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority labels Sep 13, 2025
@Ericson2314 Ericson2314 marked this pull request as ready for review September 13, 2025 13:39
@github-project-automation github-project-automation bot moved this to Triage in Nix team Sep 13, 2025
@Ericson2314
Copy link
Member Author

A question remaining is whether we should have "storeDir": "/nix/store" as part of the JSON format, and likewise store that in Derivation.

In today's context (stores always have single store dir) this would be pure denormaliation -- bad. But there is no reason that e.g. binary caches have a single store dir --- in that case including the store dir would actually be meaningful.

If we include the store dir, we can have parse the old format in a self-contained way, but it would still be "uncompositional" in these formats, so I recommend not doing that. Perhaps a better thing we can do is include the output path for fixed-output derivations, and for which we need a store dir to calculate that path. If you see the code, you can see I removed it for now.

That said, the path for fixed-output derivations is (given a store dir) pure denormalization also, and one would image e.g. a nix derivation show-output-paths that would specifically compute those paths, or similar, to separate the canonical data from derived information.

[&](const DerivationOutput::InputAddressed & doi) { res["path"] = doi.path; },
[&](const DerivationOutput::CAFixed & dof) {
res["path"] = store.printStorePath(dof.path(store, drvName, outputName));
// res["path"] = dof.path(store, drvName, outputName);
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed path for fixed-output-derivations (see comment above for details)

Comment on lines +1324 to +1327
#if 0
if (dof.path(store, drvName, outputName) != static_cast<StorePath>(valueAt(json, "path")))
throw Error("Path doesn't match derivation output");
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed path for fixed-output-derivations (see comment above for details)

See NixOS#13570 for details --- the idea is that included the store dir in
store paths makes systematic JSON parting with e.g. Serde, Aeson,
nlohmann, or similiar harder.

After talking to Eelco, we are changing the `Derivation` format right
away because not only is `nix derivation` technically experimental, we think it is
also less widely used in practice than, say, `nix path-info`.

Progress on NixOS#13570
@github-actions github-actions bot added the c api Nix as a C library with a stable interface label Sep 17, 2025
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Great to have a version number

@roberth roberth merged commit b4fcb64 into NixOS:master Sep 17, 2025
14 checks passed
@Ericson2314 Ericson2314 deleted the drv-json-issue-13570 branch September 17, 2025 22:17
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nix-2-32-0-released/70528/1

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

Labels

c api Nix as a C library with a stable interface documentation new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants