Giter Site home page Giter Site logo

nix-index-database's Introduction

nix-index-database

Weekly updated nix-index database

This repository also provides nixos modules and home-manager modules that add a nix-index wrapper to use the database from this repository.

The home-manager module also allows integration with the existing command-not-found functionality.

Demo

$ nix run github:mic92/nix-index-database bin/cntr
cntr.out                                        978,736 x /nix/store/09p2hys5bxcnzcaad3bknlnwsgdkznl1-cntr-1.5.1/bin/cntr

Usage in NixOS

Include the nixos module in your configuration (requires 23.05 or nixos unstable)

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
  
    nix-index-database.url = "github:Mic92/nix-index-database";
    nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, nix-index-database, ... }: {
    nixosConfigurations = {
      my-nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          nix-index-database.nixosModules.nix-index
          # optional to also wrap and install comma
          # { programs.nix-index-database.comma.enable = true; }
        ];
      };
    };
  };
}

Usage in Home-manager

  1. Follow the manual to set up home-manager with flakes.
  2. Include the home-manager module in your configuration:
{
  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    
    nix-index-database.url = "github:Mic92/nix-index-database";
    nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = { nixpkgs, home-manager, nix-index-database, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations.jdoe = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;

        modules = [
          nix-index-database.hmModules.nix-index
          # optional to also wrap and install comma
          # { programs.nix-index-database.comma.enable = true; }
        ];
      };
    };

}

Additionally, if your shell is managed by home-manager, you can have nix-index integrate with your shell's command-not-found functionality by setting programs.nix-index.enable = true.

Ad-hoc download

download_nixpkgs_cache_index () {
  filename="index-$(uname -m | sed 's/^arm64$/aarch64/')-$(uname | tr A-Z a-z)"
  mkdir -p ~/.cache/nix-index && cd ~/.cache/nix-index
  # -N will only download a new version if there is an update.
  wget -q -N https://github.com/Mic92/nix-index-database/releases/latest/download/$filename
  ln -f $filename files
}

download_nixpkgs_cache_index

nix-index-database's People

Contributors

amesgen avatar artturin avatar badele avatar dependabot[bot] avatar figsoda avatar github-actions[bot] avatar lovesegfault avatar m-bdf avatar maralorn avatar mergify[bot] avatar mic92 avatar r-vdp avatar ryuheechul avatar therealr5 avatar xyenon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nix-index-database's Issues

In the Home Manager module, a nonexistent option is being referenced

When using the Home Manager module, an error is being thrown because the option config.programs.nix-index-database.enable doesn't exist. It should be programs.nix-index-database.comma.enable.

Relevant part of the stack trace:

       error: attribute 'enable' missing

       at /nix/store/cr9amgxwdf2qxjav6ilg4r6p8ykik1jf-source/home-manager-module.nix:27:34:

           26|     };
           27|     home.packages = lib.optional config.programs.nix-index-database.enable packages.${pkgs.stdenv.system}.comma-with-db;
             |                                  ^
           28|

Suggestion: provide a flake

I had the following idea:

This repo could provide a flake similar to this:

{
 inputs = {
  database = {
   type = "tarball";
   url = "https://github.com/Mic92/nix-index-database/releases/download/2022-05-22/index-x86_64-linux";   
   };
 }
 outputs = {database} : {
  inherit database;
 }
}

The github action could update the url and the lockfile.
This way flake users could include the database purely in their system and update it with flake update.

What do you think?

Add a nix-darwin module

It'd be great if I could just reference nix-index-database.darwinModules.nix-index, like I do for Home Manager and NixOS.

Consider moving under `nix-community`?

As a tool author, I'm concerned about sourcing a cache from a private project page.
Not for technical reasons or because I wouldn't trust you. I do!

But mainly because of the signalling that "caches are served from someone's backyard".

Moving this to nix-community could give it the appropriate standing.

Package it to nixpkgs?

Thank you to create this program which save me about 20 minutes to generate ~/.cache/nix-index/files! ๐Ÿ‘

Currently, I use this package in /etc/nixos/configuration.nix by

  environment.systemPackages = with pkgs;
    let
      nix-index-database = (
        builtins.getFlake "github:nix-community/nix-index-database"
      ).packages.${builtins.currentSystem}.default;
    in
    [
      nix-index-database
    ];

Why not package it to nixpkgs? It can simplify installation:

  environment.systemPackages = with pkgs;
    [
      nix-index-database
    ];

Explain setup with home-manager but without flakes

The current README explains how to setup nix-index-database with home-manager and flake. But flake is still experimental and some of us (me included) have not enabled it yet.

I think I managed to setup nix-index-database with home-manager and no flake with the following code. Is it something we should add to the README? Is there any problem with this code?

{ lib, config, pkgs, ... }:

let
  nix-index-database = (import ../../nix-index-database/packages.nix).${pkgs.stdenv.system}.database;
  packages.${pkgs.stdenv.system} = {
    nix-index-with-db = pkgs.callPackage ../../nix-index-database/nix-index-wrapper.nix {
      inherit nix-index-database;
    };
    comma-with-db = pkgs.callPackage ../../nix-index-database/comma-wrapper.nix {
      inherit nix-index-database;
    };
  };
  legacyPackages.${pkgs.stdenv.system}.database = nix-index-database;
in {
  imports = [
    ((import ../../nix-index-database/home-manager-module.nix) {
      inherit packages legacyPackages;
    })
  ];

  # Provides Bash's command-no-found and a nix-index command:
  programs.nix-index = { enableBashIntegration = true; };
  programs.nix-index-database.comma.enable = true;
}

Also provide `comma` integration?

Thanks for the new modules, they are very convenient! I am wondering whether they could also provide a comma which uses the pre-built database (without having to recompile comma).

My current solution for this is to set

home.file."${hm.config.xdg.cacheHome}/nix-index/files".source =
  inputs.nix-index-database.legacyPackages.${pkgs.stdenv.system}.database;

which is then used by stock comma, but maybe there is a cleaner approach.

How to use nix-index on macOS?

First of all, thank you very much for working on #18

I am now trying to get nix-index running on my macOS system.

I have added the home-manager module as described in the README:
https://github.com/MarkusLohmayer/nix-config/blob/main/flake.nix#L86

However, I had to remove
programs.nix-index.enable = true; from my home-manager config, see
https://github.com/MarkusLohmayer/nix-config/blob/main/flake.nix#L86
since I got the following error

error: builder for '/nix/store/2mngnj7w1fp5r9lwaibpyh1l6knsl9c5-home-manager-path.drv' failed with exit code 25;
       last 1 log lines:
       > error: collision between `/nix/store/nb4rk64wwcw4yhf8fmwq5q23pskhwx2f-nix-index-unstable-2022-03-07/bin/nix-locate' and `/nix/store/z2vk3mq7a5cmrsqkhcgx5rqv89g2blll-nix-index/bin/nix-locate'

Any hints for helping me to correctly setup nix-index on macOS are appreciated.
Thanks again! ๐Ÿ˜„

Permission denied error

Not sure if it's something related to comma, but after #47 I had to remove the comma package from my home-manager config since I got

> error: collision between `/nix/store/l2x9kyb234qzrjyih36zfv2mk87m2b83-comma-with-db-1.6.0/bin/,' and `/nix/store/ch4s39pafpnm24fm9gpjqqpp494v8qm0-comma-1.6.0/bin/,'

Now although everything is fine, when I try to run any comma command I get

โฏ , ls
error: creating directory '/nix/store/l2x9kyb234qzrjyih36zfv2mk87m2b83-comma-with-db-1.6.0/share/cache/nix': Permission denied

but using the "real" comma binary, it works as expected, i.e.:

/nix/store/ch4s39pafpnm24fm9gpjqqpp494v8qm0-comma-1.6.0/bin/comma ls

It looks like the overridden XDG_CACHE_HOME env variable in the wrapper is causing problems. Am I missing something?

Thanks!

In the Home Manager module, a nonexistent option is being referenced

When using the Home Manager module, an error is being thrown because the option config.programs.nix-index-database.enable doesn't exist. It should be programs.nix-index-database.comma.enable.

Relevant part of the stack trace:

       error: attribute 'enable' missing

       at /nix/store/cr9amgxwdf2qxjav6ilg4r6p8ykik1jf-source/home-manager-module.nix:27:34:

           26|     };
           27|     home.packages = lib.optional config.programs.nix-index-database.enable packages.${pkgs.stdenv.system}.comma-with-db;
             |                                  ^
           28|

In the Home Manager module, a nonexistent option is being referenced

When using the Home Manager module, an error is being thrown because the option config.programs.nix-index-database.enable doesn't exist. It should be programs.nix-index-database.comma.enable.

Relevant part of the stack trace:

       error: attribute 'enable' missing

       at /nix/store/cr9amgxwdf2qxjav6ilg4r6p8ykik1jf-source/home-manager-module.nix:27:34:

           26|     };
           27|     home.packages = lib.optional config.programs.nix-index-database.enable packages.${pkgs.stdenv.system}.comma-with-db;
             |                                  ^
           28|

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.