Skip to content

Add special error message for empty derivation file#15298

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
dramforever:parse-derivation-empty-special-msg
Feb 19, 2026
Merged

Add special error message for empty derivation file#15298
Ericson2314 merged 1 commit intoNixOS:masterfrom
dramforever:parse-derivation-empty-special-msg

Conversation

@dramforever
Copy link
Contributor

@dramforever dramforever commented Feb 19, 2026

This rather commonly occurs when the computer was uncleanly shut down and fsync was not enabled. Show the user a more actionable message than "expected string 'D'".

Motivation

error parsing derivation '/nix/store/blahblah-blah.drv': error: expected string 'D'

It would be better if we didn't rely on someone in the Matrix channel telling people they have FS corruption due to an unclean shutdown.

This message doesn't try to tell the user how to fix it, since it can be kind of tricky. See #11148.

This message also doesn't try to catch all errors thrown by the parsing function. Some of them can be caused by version mismatches instead, where trying to fix store corruption would be the wrong direction.

Context


Add 👍 to pull requests you find important.

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

@Ericson2314
Copy link
Member

Can you put the check at

return parseDerivation(store, accessor->readFile(CanonPath::root), Derivation::nameFromPath(drvPath));
?

This is better separation of concerns: parseDerivation is just parsing a string and shouldn't be guessing that that string came from a drv file.

Ideally we'd only do the warning for LocalFSStore too, but that seems a bit too much work to me, so I think putting it in the method implementation shared across all stores that I linked above is fine.

@Ericson2314
Copy link
Member

You'll want to make it a FormatError too so the catch block I linked adds useful context.

@dramforever dramforever force-pushed the parse-derivation-empty-special-msg branch from 8d10d50 to eb875b7 Compare February 19, 2026 09:31
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Feb 19, 2026
@dramforever
Copy link
Contributor Author

I'm not sure if it should be a strictly LocalFSStore-only thing. If you get an empty .drv file from a store, there's probably an empty-file-caused-by-unclean-shutdown that happened somewhere

This rather commonly occurs when the computer was uncleanly shut down
and fsync was not enabled. Show the user a more actionable message than
"expected string 'D'".
@dramforever dramforever force-pushed the parse-derivation-empty-special-msg branch from eb875b7 to c33c82f Compare February 19, 2026 09:35
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Ah, good point about bad drv file somewhere else!

@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 19, 2026
Merged via the queue into NixOS:master with commit 3df67a8 Feb 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants