# How to specify \`programs.sqlite\` for \`command-not-found\` from flakes?

**URL:** https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722
**Category:** Help
**Created:** [October 23, 2022, 11:19pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722 "2022-10-23T23:19:31Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![myguidingstar](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@myguidingstar](https://discourse.nixos.org/u/myguidingstar)
#### Post date: [October 23, 2022, 11:19pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/1 "2022-10-23T23:19:31Z")

</div>

I’ve got rid of all nix channels and just use flakes for everything. However, `command-not-found` now complains it can not find `programs.sqlite` because that file is expected in default root channel. How do I specify that that for `command-not-found`? (preferrably from home-manager option `programs.command-not-found.dbPath`)

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [October 24, 2022, 5:49am UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/2 "2022-10-24T05:49:39Z")

</div>

I’m not aware of a way to pull that database in with flakes.

I therefore still maintain an irregularly updated `nixos` channel for the `root` user.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [October 24, 2022, 8:51am UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/3 "2022-10-24T08:51:47Z")

</div>

You can either replace the current command-not-found module with the one provided by nix-index (it provides both a module for nixos and home manager, thanks K900).

The second approach I can imagine is to manually download the database from [https://channels.nixos.org](https://channels.nixos.org) (code not tested)

```auto
{ pgks, ... }:
let
  # To find the channel url I went in:
  # https://channels.nixos.org/ > nixos-22.05 > nixexprs.tar.gz
  # All the available channels you can browse https://releases.nixos.org
  nixos_tarball = pkgs.fetchzip {
    url = "https://releases.nixos.org/nixos/22.05/nixos-22.05.3737.3933d8bb912/nixexprs.tar.xz";
    sha256 = "sha256-+xhJb0vxEAnF3hJ6BZ1cbndYKZwlqYJR/PWeJ3aVU8k=";}
  ;
  # extract only the sqlite file
  programs-sqlite = pkgs.runCommand "program.sqlite" {} ''
    cp ${nixos_tarball}/programs.sqlite $out
  '';
in
{
  programs.command-not-found.dbPath = programs-sqlite;
}

```

---

<div class="post-metadata">

### Author: ![myguidingstar](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@myguidingstar](https://discourse.nixos.org/u/myguidingstar)
#### Post date: [October 24, 2022, 4:44pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/4 "2022-10-24T16:44:45Z")

</div>

Thank you all, especially @tobiasBora for spending the time to write the code, really appreciated.

Can you elaborate on the nix-index? I’ve seen the `nix-index` option in home manager, but when I enable it I face the same complaints (missing `programs.sqlite`), and I’m not sure how the first approach would work.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [October 24, 2022, 5:02pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/5 "2022-10-24T17:02:08Z")

</div>

No problems. The readme provides a code snippet to use in your `configuration.nix` here [GitHub - nix-community/nix-index: Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius]](https://github.com/bennofs/nix-index#usage-as-a-command-not-found-replacement)

```auto
programs.command-not-found.enable = false;
programs.bash.interactiveShellInit = ''
      source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
    '';

```

It also links to the home manager module here [https://nix-community.github.io/home-manager/options.html#opt-programs.nix-index.enable](https://nix-community.github.io/home-manager/options.html#opt-programs.nix-index.enable) I don’t have a computer to test but I guess you want to have

```auto
programs.nix-index.enable = true;
programs.nix-index.enableBashIntegration = true;

```

(If you use zsh/fish adapt this code of course)  
Also make sure to _disable_ the `command-not-found` option to avoid conflicts as they are vifferent implementations of the same functionality(it is disabled by default but you may have enabled it). If it fails maybe try to disable system-wide to see if it helps. If you are still out of luck please post your config 😉

---

<div class="post-metadata">

### Author: ![myguidingstar](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@myguidingstar](https://discourse.nixos.org/u/myguidingstar)
#### Post date: [October 27, 2022, 2:45pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/6 "2022-10-27T14:45:03Z")

</div>

that was what I had in my `home-manager` configuration as well. However, `nix-index` doesn’t know where the `nixpkgs` is either.

I ended up writing a custom script to call it with the right nixpkgs path:

`(pkgs.writeScriptBin "nix-index-update-db" "nix-index -f ${pkgs.path}")`

and run the script when I update my flake nixpkgs input.

Thank you very much for the pointer.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [October 27, 2022, 2:50pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/7 "2022-10-27T14:50:30Z")

</div>

Oh I thought that nix-index would just pick the latest stuff from Hydra irrespective of the current channel. Good to know then!

---

<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: [December 21, 2022, 12:48pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/8 "2022-12-21T12:48:29Z")

</div>

> [@NobbZ](#):
>
> I’m not aware of a way to pull that database in with flakes.
> 
> I therefore still maintain an irregularly updated `nixos` channel for the `root` user.

@NobbZ @myguidingstar @tobiasBora  
I spent a bit of spare time on [GitHub - wamserma/flake-programs-sqlite: A simple flake to automagically specify programs.sqlite for command-not-found.](https://github.com/wamserma/flake-programs-sqlite) - maybe you could have a look and test-drive it.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [December 21, 2022, 1:09pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/9 "2022-12-21T13:09:34Z")

</div>

Seems to be a nice idea and thank you for the effort, though:

```auto
$ nixos-rebuild build --flake .#mimas
building the system configuration...
warning: Git tree '/home/nmelzer/Projects/nixos-config' is dirty
error: attribute '757b82211463dd5ba1475b6851d3731dfe14d377' missing

```

And that commit is from 2022-12-16T14:28:48Z (unstable)

If the system can’t sustain even that pace for updates, I wont be able to do any test-drive for you, sorry.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [December 21, 2022, 2:06pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/10 "2022-12-21T14:06:42Z")

</div>

I just realized that you simply might miss the old commit because your started scraping at some later moment in time.

Therefore I updated my local clone to be the same as on GitHub 😃

That lockfiles commit actually got recognized by your system and now I am building my system to start testing your flake under real life conditions.

I already found some issue with your README and hope to be able to do a PR later today.

---

<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: [December 21, 2022, 2:25pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/11 "2022-12-21T14:25:17Z")

</div>

> [@NobbZ](#):
>
> I just realized that you simply might miss the old commit because your started scraping at some later moment in time.

Yes, I only kept some older revisions for testing, but proper scraping started less than 24 hours ago.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [December 21, 2022, 2:45pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/12 "2022-12-21T14:45:42Z")

</div>

I have made my first tries and some testing and draw a first conclusion:

- Works well so far, but setup steps are currently lacking documentation (will try to PR today)
- There should be a module that handles the setup and also goes through a redirection (I hope to be able to do a PR before christmas)
- I do not really like how overriding the input is part of the contract (I have an idea, but that has to be postponed for now, I don’t have the time nor energy to even verbalise my thoughts before christmas)

* * *

I need to change something it seems, as I have posted this in the wrong thread initially and simply reposting seems to be denied by the spam filter or something…

---

<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: [December 21, 2022, 2:59pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/13 "2022-12-21T14:59:22Z")

</div>

> [@NobbZ](#):
>
> - There should be a module that handles the setup and also goes through a redirection (I hope to be able to do a PR before christmas)
> - I do not really like how overriding the input is part of the contract (I have an idea, but that has to be postponed for now, I don’t have the time nor energy to even verbalise my thoughts before christmas)

No need to hurry, most like I won’t be available to review the module before next year.

---

<div class="post-metadata">

### Author: ![kandelakitina](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kandelakitina/32/15870_2.png) [@kandelakitina](https://discourse.nixos.org/u/kandelakitina)
#### Post date: [March 7, 2024, 3:35pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/14 "2024-03-07T15:35:24Z")

</div>

Worked like a charm. As opposed to `nix-index`. Thank you very much!

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [March 7, 2024, 4:08pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/15 "2024-03-07T16:08:41Z")

</div>

I now really like `nix-index-database` (no need to worry about anything, the database is downloaded automatically) [GitHub - nix-community/nix-index-database: Weekly updated nix-index database [maintainer=@Mic92]](https://github.com/nix-community/nix-index-database). With flake installed:

```auto
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
  
    nix-index-database.url = "github:nix-community/nix-index-database"; # <--- Add this
    nix-index-database.inputs.nixpkgs.follows = "nixpkgs"; # <--- Add this
  };

  outputs = { self,
             , nixpkgs
             , nix-index-database # <--- Add this
             , ... }: {
    nixosConfigurations = {
      my-nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          nix-index-database.nixosModules.nix-index # <--- Add this
          { programs.command-not-found.enable = false; } # <--- Add this
        ];
      };
    };
  };
}

```

Then, it will automatically propose you the name of the program to install if not available, and you can use `nix-locate` to search which package provides which file.

---

<div class="post-metadata">

### Author: ![Infinisil](https://discourse.nixos.org/user_avatar/discourse.nixos.org/infinisil/32/26523_2.png) [@Infinisil](https://discourse.nixos.org/u/Infinisil)
#### Post date: [March 7, 2024, 6:47pm UTC](https://discourse.nixos.org/t/how-to-specify-programs-sqlite-for-command-not-found-from-flakes/22722/16 "2024-03-07T18:47:59Z")

</div>

Btw I recently covered this topic in a Nix Hour 🙂

[![](https://discourse.nixos.org/uploads/default/original/2X/1/13eca8337e50e5e0ac5052ccb1482a04412505a2.jpeg "The Nix Hour #63 [command-not-found, nix-index]") ](https://www.youtube.com/watch?v=sLGoWAGklds)
