Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wamserma/flake-programs-sqlite
A simple flake to automagically specify programs.sqlite for command-not-found.
https://github.com/wamserma/flake-programs-sqlite
flakes nix
Last synced: 3 months ago
JSON representation
A simple flake to automagically specify programs.sqlite for command-not-found.
- Host: GitHub
- URL: https://github.com/wamserma/flake-programs-sqlite
- Owner: wamserma
- License: mit
- Created: 2022-12-13T22:11:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T08:52:48.000Z (3 months ago)
- Last Synced: 2024-10-29T10:02:30.898Z (3 months ago)
- Topics: flakes, nix
- Language: Nim
- Homepage: https://discourse.nixos.org/t/27669
- Size: 3.09 MB
- Stars: 39
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# programs.sqlite for Nix Flake based systems
[![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)
## TL;DR
(assuming a flake similar to )
Add to `inputs` in `flake.nix`:
```nix
flake-programs-sqlite.url = "github:wamserma/flake-programs-sqlite";
flake-programs-sqlite.inputs.nixpkgs.follows = "nixpkgs";
```Then just add the module.
### NixOS module
Usage with a minimal system flake:
```nix
{
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-22.11;
inputs.flake-programs-sqlite.url = "github:wamserma/flake-programs-sqlite";
inputs.flake-programs-sqlite.inputs.nixpkgs.follows = "nixpkgs";outputs = inputs@{ self, nixpkgs, ... }: {
nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[
(import configuration.nix)
inputs.flake-programs-sqlite.nixosModules.programs-sqlite
];
};
};
}
```The module's functionality is enabled as soon as the module is imported.
### alternative: without using a module
Add `flake-programs-sqlite` to the arguments of the flake's `outputs` function.
Add `programs-sqlite-db = flake-programs-sqlite.packages.${system}.programs-sqlite`
to the `specialArgs` argument of `lib.nixosSystem`.Add `programs-sqlite-db`to the inputs of your system configuration (`configuration.nix`)
and to the configuration itself add:```nix
programs.command-not-found.dbPath = programs-sqlite-db;
```## Why?
NixOS systems configured with flakes and thus lacking channels usually have a broken
`command-not-found`. The reason is that the backing database `programs.sqlite` is only
available on channels. The problem is that the channel URL can not be determined from
the `nixpkgs` revision alone, as it also contains a build number.
command-not-what?
Bash and other shells have a special handler that is invoked when an unknown command
is issued to the shell. For bash this is `command_not_found_handler`.`command-not-found` is [a Perl script](https://github.com/NixOS/nixpkgs/blob/7c44c865ee736afba33ee8788b59e4a123800437/nixos/modules/programs/command-not-found/command-not-found.pl)
that is hooked into this handler when
the option [`programs.command-not-found.enable`](https://search.nixos.org/options?show=programs.command-not-found.enable)
is set to `true`. This perl script evaluates a pre-made database to suggest
packages that might be able to provide the command.The pre-made database is generated as part of a channel, hence pure-flake-systems
do not have access to it. This flake extracts the database from the channels
and passes it to the `command-not-found` script to restore functionality that
was previously only available when using channels.This is an attempt to provide a usable solution, motivated by
## How?
The channel page is regularly scraped for the revision and file hashes, then a
[lookup table](./sources.json) from revisions to URL and hashes is amended with any
new information.
The lookup table is used to create a fixed-output-derivation (FOD) for `programs.sqlite`
based on the revision of `nixpkgs` passed as input of this flake.## Usage
see TL:DR above
## Development
The flake provides a minimal devshell, but hacking on the code with a editor and
running `nix run .#updater` is valid, too.Development happens on the `tooling` branch, which is then merged into the `main`
branch. Updates to the JSON file go directly to `main`. Releases of the tooling are
also cut from the `tooling` branch. There are no releases for the JSON files.## Fetching selected channel revisions
e.g. to fetch info for older revisions/releases from before this project was started
```sh
[ -f sources.json ] || echo {} > sources.json
nix run github:wamserma/flake-programs-sqlite#updater -- --dir:. --channel:https://releases.nixos.org/nixos/20.03/nixos-20.03.2400.ff1b66eaea4
```Multiple channels/revisions may be passed for a single run.
If no channel is given, the current channels are guessed and their latest revisions are fetched.## Alternatives
- [nix-index](https://github.com/bennofs/nix-index#usage-as-a-command-not-found-replacement)
## Licensing
The Nim code to scrape the metadata is released under MIT License.
The Nix code to provide the FODs is released under MIT License.
The database itself (JSON) is public domain.