Skip to content

Get rid of the settings-dependent writeDerivation wrapper#15219

Merged
xokdvium merged 1 commit intoNixOS:masterfrom
obsidiansystems:writeDerivation-lighter-read-only
Feb 14, 2026
Merged

Get rid of the settings-dependent writeDerivation wrapper#15219
xokdvium merged 1 commit intoNixOS:masterfrom
obsidiansystems:writeDerivation-lighter-read-only

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Feb 13, 2026

Motivation

It was a crude hack that this one low-level function was dependent on the high-level read-only mode setting --- all the more so because rather than making derivation writing fail, that setting made it silently "succeed" while not actually writing the derivation. (Also, for context, we didn't have an such behavior for any other store-mutating operations, just for this one function.)

Context

I have gotten rid of the wrapper, and updated the call sites accordingly.

  • For the ones that should remain dependent on this setting, I made this explicit, and added a comment.

  • For others, surrounding operations assumed writability (e.g. we had written something before, or were about to try to read back the written derivation after), and so I just made those do the underlying Store::writeDerivation operation.


Add 👍 to pull requests you find important.

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

It was a crude hack that this one low-level function was dependent on
the high-level read-only mode setting --- all the more so because rather
than making derivation writing fail, that setting made it silently
"succeed" why not actually writing the derivation. (Also, for context,
we didn't have an such behavior for any other store-mutating operations,
just for this one function.)

I have gotten rid of the wrapper, and updated the call sites
accordingly.

- For the ones that should remain dependent on this setting, I made this
  explicit, and added a comment.

- For others, surrounding operations assumed writability (e.g. we had
  written something before, or were about to try to read back the
  written derivation after), and so I just made those do the underlying
  `Store::writeDerivation` operation.
@github-actions github-actions bot added new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store c api Nix as a C library with a stable interface labels Feb 13, 2026
@Ericson2314 Ericson2314 changed the title Write derivation lighter read only Get rid of the settings-dependent writeDerivation wrapper Feb 13, 2026
@xokdvium xokdvium added this pull request to the merge queue Feb 14, 2026
Comment on lines +311 to +315
/* Quite dubious that users would want this to silently suceed
without actually writing the derivation if this setting is
set, but it was that way already, so we are doing this for
back-compat for now. */
auto ret = nix::settings.readOnlyMode ? nix::computeStorePath(*store->ptr, derivation->drv)
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, ideally the behaviour of C API functions isn't affected in an observable way. The method by which we do stuff vs what the end result is a different matter.

@roberth, what do you think?

IMO it seems reasonable to fix this as a bugfix. I doubt any caller is using this hack to just compute a store path.

Merged via the queue into NixOS:master with commit 6cbf80a Feb 14, 2026
16 checks passed
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 new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants