{"id":21060420,"url":"https://github.com/wamserma/flake-programs-sqlite","last_synced_at":"2025-05-16T00:34:08.044Z","repository":{"id":65092810,"uuid":"577942797","full_name":"wamserma/flake-programs-sqlite","owner":"wamserma","description":"A simple flake to automagically specify programs.sqlite for command-not-found.","archived":false,"fork":false,"pushed_at":"2025-05-12T10:16:45.000Z","size":2696,"stargazers_count":48,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T11:30:21.410Z","etag":null,"topics":["flakes","nix"],"latest_commit_sha":null,"homepage":"https://discourse.nixos.org/t/27669","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wamserma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2022-12-13T22:11:28.000Z","updated_at":"2025-05-12T10:16:48.000Z","dependencies_parsed_at":"2023-12-20T07:21:52.420Z","dependency_job_id":"32c85275-5ab7-4294-b3bd-a027498ec49e","html_url":"https://github.com/wamserma/flake-programs-sqlite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamserma%2Fflake-programs-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamserma%2Fflake-programs-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamserma%2Fflake-programs-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamserma%2Fflake-programs-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wamserma","download_url":"https://codeload.github.com/wamserma/flake-programs-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254447994,"owners_count":22072755,"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":["flakes","nix"],"created_at":"2024-11-19T17:17:27.180Z","updated_at":"2025-05-16T00:34:03.020Z","avatar_url":"https://github.com/wamserma.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# programs.sqlite for Nix Flake based systems\n\n[![Update Channel Info](https://github.com/wamserma/flake-programs-sqlite/actions/workflows/scrape.yml/badge.svg?branch=main)](https://github.com/wamserma/flake-programs-sqlite/actions/workflows/scrape.yml)\n\n## TL;DR\n\n(assuming a flake similar to \u003chttps://nixos.wiki/wiki/Flakes#Using_nix_flakes_with_NixOS\u003e)\n\nAdd to `inputs` in `flake.nix`:\n\n```nix\nflake-programs-sqlite.url = \"github:wamserma/flake-programs-sqlite\";\nflake-programs-sqlite.inputs.nixpkgs.follows = \"nixpkgs\";\n```\n\nThen just add the module.\n\n### NixOS module\n\nUsage with a minimal system flake:\n\n```nix\n{\n  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-22.11;\n  inputs.flake-programs-sqlite.url = \"github:wamserma/flake-programs-sqlite\";\n  inputs.flake-programs-sqlite.inputs.nixpkgs.follows = \"nixpkgs\";\n\n  outputs = inputs@{ self, nixpkgs, ... }: {\n\n    nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem {\n      system = \"x86_64-linux\";\n      modules =\n        [\n          (import configuration.nix)\n          inputs.flake-programs-sqlite.nixosModules.programs-sqlite\n        ];\n    };\n  };\n}\n```\n\nThe module's functionality is enabled as soon as the module is imported.\n\n### alternative: without using a module\n\nAdd `flake-programs-sqlite` to the arguments of the flake's `outputs` function.\n\nAdd `programs-sqlite-db = flake-programs-sqlite.packages.${system}.programs-sqlite`\nto the `specialArgs` argument of `lib.nixosSystem`.\n\nAdd `programs-sqlite-db`to the inputs of your system configuration (`configuration.nix`)\nand to the configuration itself add:\n\n```nix\nprograms.command-not-found.dbPath = programs-sqlite-db;\n```\n\n## Why?\n\nNixOS systems configured with flakes and thus lacking channels usually have a broken\n`command-not-found`. The reason is that the backing database `programs.sqlite` is only\navailable on channels. The problem is that the channel URL can not be determined from\nthe `nixpkgs` revision alone, as it also contains a build number.\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n  \u003ccode\u003ecommand-not-what?\u003c/code\u003e\n  \u003c/summary\u003e\n\n  Bash and other shells have a special handler that is invoked when an unknown command\n  is issued to the shell. For bash this is `command_not_found_handler`.\n\n  `command-not-found` is [a Perl script](https://github.com/NixOS/nixpkgs/blob/7c44c865ee736afba33ee8788b59e4a123800437/nixos/modules/programs/command-not-found/command-not-found.pl)\n  that is hooked into this handler when\n  the option [`programs.command-not-found.enable`](https://search.nixos.org/options?show=programs.command-not-found.enable)\n  is set to `true`. This perl script evaluates a pre-made database to suggest\n  packages that might be able to provide the command.\n\n  The pre-made database is generated as part of a channel, hence pure-flake-systems\n  do not have access to it. This flake extracts the database from the channels\n  and passes it to the `command-not-found` script to restore functionality that\n  was previously only available when using channels.\n\u003c/details\u003e\n\nThis is an attempt to provide a usable solution, motivated by \u003chttps://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/3\u003e\n\n## How?\n\nThe channel page is regularly scraped for the revision and file hashes, then a\n[lookup table](./sources.json) from revisions to URL and hashes is amended with any\nnew information.\nThe lookup table is used to create a fixed-output-derivation (FOD) for `programs.sqlite`\nbased on the revision of `nixpkgs` passed as input of this flake.\n\n## Usage\n\nsee TL:DR above\n\n## Development\n\nThe flake provides a minimal devshell, but hacking on the code with a editor and\nrunning `nix run .#updater` is valid, too.\n\nDevelopment happens on the `tooling` branch, which is then merged into the `main`\nbranch. Updates to the JSON file go directly to `main`. Releases of the tooling are\nalso cut from the `tooling` branch. There are no releases for the JSON files.\n\n## Fetching selected channel revisions\n\ne.g. to fetch info for older revisions/releases from before this project was started\n\n```sh\n[ -f sources.json ] || echo {} \u003e sources.json\nnix run github:wamserma/flake-programs-sqlite#updater -- --dir:. --channel:https://releases.nixos.org/nixos/20.03/nixos-20.03.2400.ff1b66eaea4\n```\n\nMultiple channels/revisions may be passed for a single run.  \nIf no channel is given, the current channels are guessed and their latest revisions are fetched.\n\n## Alternatives\n\n- [nix-index](https://github.com/bennofs/nix-index#usage-as-a-command-not-found-replacement)\n\n## Licensing\n\nThe Nim code to scrape the metadata is released under MIT License.  \nThe Nix code to provide the FODs is released under MIT License.  \nThe database itself (JSON) is public domain.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwamserma%2Fflake-programs-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwamserma%2Fflake-programs-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwamserma%2Fflake-programs-sqlite/lists"}