# Flake-programs-sqlite: fixing command-not-found for pure flake systems

**URL:** https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669
**Category:** Announcements
**Created:** [April 27, 2023, 6:51pm UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669 "2023-04-27T18:51:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [April 27, 2023, 6:51pm UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669/1 "2023-04-27T18:51:48Z")

</div>

Hey everyone,  
happy to introduce [flake-programs-sqlite](https://github.com/wamserma/flake-programs-sqlite), a simple flake to automagically specify `programs.sqlite` for `command-not-found`.

## Why?

NixOS systems configured with flakes often don’t have a channel set (e.g. `nix-channel --list` shows no channel), which usually results in a broken `command-not-found` as the command database is part of the channel system and not part of `nixpkgs`.  
Up to now the only option was to use [nix-index](https://github.com/bennofs/nix-index#usage-as-a-command-not-found-replacement), but it was not possible to get back the UX known from channels. ([see here](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722))

With [flake-programs-sqlite](https://github.com/wamserma/flake-programs-sqlite) a working `command-not-found` only requires a few additions to a flake based system configuration.

## How?

[flake-programs-sqlite](https://github.com/wamserma/flake-programs-sqlite) makes use of a mapping from git commit hashes to channel names. This mapping is updated by a GitHub action by scraping {channels,releases}.nixos.org (currently) about every ten minutes.  
When importing [flake-programs-sqlite](https://github.com/wamserma/flake-programs-sqlite), the standard flake mechanism can be used to pin it’s `nixpkgs` input. When the `programs-sqlite` output package is requested, a fixed output derivation for a `programs.sqlite` database matching the revision of the input `nixpkgs` is constructed from the scraped data. The result of this derivation is then injected into `command-not-found`.

## NixOS Module Integration

Using [flake-programs-sqlite](https://github.com/wamserma/flake-programs-sqlite) as a module in your NixOS configuration is the preferred method. Just add it to your flake inputs, pass it to your outputs and add it to your list of modules:

```auto
# ... 
inputs.fps.url = "github:wamserma/flake-programs-sqlite";
inputs.fps.inputs.nixpkgs.follows = "nixpkgs";

# ...

outputs = { nixpkgs, fps, ... }: {

    nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem {
      modules =
        [
          (import configuration.nix)
          fps.nixosModules.programs-sqlite
          # ...
        ];
    };

```

## Contribute

Feel free to submit issues or pull requests on the [GitHub repository](https://github.com/wamserma/flake-programs-sqlite).

## Note

Scraping started on 21st December 2022. If a certain channel revision is missing, follow the [README](https://github.com/wamserma/flake-programs-sqlite/README.md) for instructions on scraping or [open an issue](https://github.com/wamserma/flake-programs-sqlite/issues).

---

<div class="post-metadata">

### Author: ![pbsds](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbsds/32/11198_2.png) [@pbsds](https://discourse.nixos.org/u/pbsds)
#### Post date: [April 27, 2023, 11:01pm UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669/2 "2023-04-27T23:01:01Z")

</div>

Wouldn’t this work?

```nix
nix.registry.nixpkgs.flake = inputs.nixpkgs;
nix.nixPath = ["nixpkgs=${inputs.nixpkgs}"];

```

---

<div class="post-metadata">

### Author: ![wamserma](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wamserma/32/5353_2.png) [@wamserma](https://discourse.nixos.org/u/wamserma)
#### Post date: [April 28, 2023, 5:20am UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669/3 "2023-04-28T05:20:50Z")

</div>

> [@pbsds](#):
>
> Wouldn’t this work?
> 
> ```nix
> nix.registry.nixpkgs.flake = inputs.nixpkgs;
> nix.nixPath = ["nixpkgs=${inputs.nixpkgs}"];
> 
> ```

No, this only pins the version of `nixpgks` in the flake registry. The `command-not-found` script relies on information that can only be computed after a `nixpkgs` commit has been fully evaluated and thus can only be found in the channel metadata and not in the `nixpkgs`-flake.

---

<div class="post-metadata">

### Author: ![Lillecarl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lillecarl/32/34279_2.png) [@Lillecarl](https://discourse.nixos.org/u/Lillecarl)
#### Post date: [May 8, 2023, 4:11pm UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669/4 "2023-05-08T16:11:04Z")

</div>

@wamserma Thanks for this, I was seeing NAR mismatches fetching the channel between machines. But no more!

---

<div class="post-metadata">

### Author: ![anticipatedfart](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@anticipatedfart](https://discourse.nixos.org/u/anticipatedfart)
#### Post date: [March 25, 2024, 10:10pm UTC](https://discourse.nixos.org/t/flake-programs-sqlite-fixing-command-not-found-for-pure-flake-systems/27669/5 "2024-03-25T22:10:42Z")

</div>

> [@wamserma](#):
>
> `github:wamserma/flake-programs-sqlite`

Thanks for this! I wasn’t aware what exactly broke the command-not-found integration at first. This fixes it for me.
