Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/indiscipline/nix-db-repair
Automatically fix Nix/NixOS error `SQLite statement 'delete from ValidPaths where path = *;': constraint failed`
https://github.com/indiscipline/nix-db-repair
database nix nixos script sqlite
Last synced: about 1 month ago
JSON representation
Automatically fix Nix/NixOS error `SQLite statement 'delete from ValidPaths where path = *;': constraint failed`
- Host: GitHub
- URL: https://github.com/indiscipline/nix-db-repair
- Owner: indiscipline
- License: gpl-3.0
- Created: 2024-08-27T17:27:22.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-08-27T18:05:43.000Z (3 months ago)
- Last Synced: 2024-09-28T09:01:19.296Z (about 2 months ago)
- Topics: database, nix, nixos, script, sqlite
- Language: Shell
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# nix-db-repair
> error: executing SQLite statement 'delete from ValidPaths where path = '/nix/store/0ab7xhlvwpyl01xp9m19ddij9rsvw0cy-hello-1.0.0.drv';': constraint failed (in '/nix/var/nix/db/db.sqlite')
[#2218](https://github.com/NixOS/nix/issues/2218). It happened. Even though the issue's closed. You gotta fix it and reinstalling from the config is not an option.
You run `nix-store --gc`, and get the error. Easy fix, you enter `nix-shell -p sqlite` and follow the [steps](https://github.com/NixOS/nix/issues/2218#issuecomment-1209591321). You restart the GC and get the same error for another derivation... Maybe *this* will be the last one! After a while you start questioning if you chose the right career/hobby.
## Usage
Make sure `bash`, `sqlite3` and `sed` are accessibly from your environment.
`DB_PATH` is usually `/nix/car/nix/db/db.sqlite`
> [!WARNING]
> Make a backup of your database first!
> `sqlite3 DB_PATH ".backup 'nix-store-db.sqlite'"`### nix-db-cleanup.sh
Perform database fixing operations for a single hash:
```# ./nix-db-cleanup.sh ```
### nix-db-repair.sh
Repair all `ValidPaths` errors iteratively:
```# ./nix-db-repair.sh ```
This repeatedly runs the `nix-store --gc` command by default and invokes `nix-db-cleanup.sh` on errors. Change the nix command at line #21 to an operation giving you the trouble.
## Disclaimer
Shellcheck is ok with this, but think for yourself. No guarantees!
## License
nix-db-repair licensed under GNU General Public License version 3.0 or later