{"id":14967889,"url":"https://github.com/indiscipline/nix-db-repair","last_synced_at":"2025-07-18T20:33:06.805Z","repository":{"id":255053303,"uuid":"848397617","full_name":"indiscipline/nix-db-repair","owner":"indiscipline","description":"Automatically fix Nix/NixOS error `SQLite statement 'delete from ValidPaths where path = *;': constraint failed`","archived":false,"fork":false,"pushed_at":"2024-11-11T23:08:14.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T10:51:11.461Z","etag":null,"topics":["database","nix","nixos","script","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indiscipline.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-27T17:27:22.000Z","updated_at":"2025-01-01T17:10:51.000Z","dependencies_parsed_at":"2024-08-27T19:27:50.143Z","dependency_job_id":null,"html_url":"https://github.com/indiscipline/nix-db-repair","commit_stats":null,"previous_names":["indiscipline/nix-db-repair"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indiscipline%2Fnix-db-repair","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indiscipline%2Fnix-db-repair/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indiscipline%2Fnix-db-repair/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indiscipline%2Fnix-db-repair/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indiscipline","download_url":"https://codeload.github.com/indiscipline/nix-db-repair/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238212440,"owners_count":19434955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","nix","nixos","script","sqlite"],"created_at":"2024-09-24T13:38:49.722Z","updated_at":"2025-02-11T00:31:27.419Z","avatar_url":"https://github.com/indiscipline.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nix-db-repair\n\n\u003e 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')\n\n[#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.\n\nYou 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.\n\n## Usage\n\nMake sure `bash`, `sqlite3` and `sed` are accessibly from your environment.\n\n`DB_PATH` is usually `/nix/var/nix/db/db.sqlite`\n\n\u003e [!WARNING]\n\u003e Make a backup of your database first!\n\u003e `sqlite3 DB_PATH \".backup 'nix-store-db.sqlite'\"`\n\n### nix-db-cleanup.sh\n\nPerform database fixing operations for a single hash:\n\n```# ./nix-db-cleanup.sh \u003cDB_PATH\u003e \u003cHASH\u003e```\n\n### nix-db-repair.sh\n\nRepair all `ValidPaths` errors iteratively:\n\n```# ./nix-db-repair.sh \u003cDB_PATH\u003e```\n\nThis 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.\n\n## Disclaimer\n\nShellcheck is ok with this, but think for yourself. No guarantees!\n\n## License\n\nnix-db-repair licensed under GNU General Public License version 3.0 or later\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findiscipline%2Fnix-db-repair","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findiscipline%2Fnix-db-repair","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findiscipline%2Fnix-db-repair/lists"}