From 193cf5748e9be11522ad0fc60c166c4424432a1c Mon Sep 17 00:00:00 2001 From: Swarsel Date: Fri, 19 Jul 2024 14:30:07 +0200 Subject: [PATCH] feat: add nix-index-database --- SwarselSystems.org | 38 ++++++++++- flake.lock | 21 ++++++ flake.nix | 8 +++ index.html | 120 ++++++++++++++++++++++++----------- profiles/common/home.nix | 17 ++++- scripts/command-not-found.sh | 33 ++++++++++ 6 files changed, 196 insertions(+), 41 deletions(-) create mode 100644 scripts/command-not-found.sh diff --git a/SwarselSystems.org b/SwarselSystems.org index c77f6f6..7a93daa 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -403,6 +403,7 @@ Mind the comma at the end. You need this because the =...= is being passed as th nixos-hardware, nix-alien, nswitch-rcm-nix, + nix-index-database, #+end_src @@ -429,8 +430,11 @@ A short overview over each input and what it does: Provides specific hardware setting for some hardware configurations. For example, this sets some better defaults for my Lenovo Thinkpad P14s Gen2. - [[https://github.com/thiagokokada/nix-alien][nix-alien]] This is supposed to allow me to run unpatched libraries directly without a need for ELF patching or resorting to =steam-run=. However, I have not yet gotten this to work. -- nswitch-rcm-nix +- [[https://github.com/Swarsel/nswitch-rcm-nix][nswitch-rcm-nix]] Allows auto injection of payloads upon connecting a Nintendo Switch. +- [[https://github.com/nix-community/nix-index-database][nix-index-database]] + This provides a database for =nix-index= that is updated weekly. This allows for declarative management, without needing to run the =nix-index= command for database assembly. + #+begin_src nix :tangle no :noweb-ref flakeinputs @@ -499,6 +503,12 @@ A short overview over each input and what it does: url = "github:Swarsel/nswitch-rcm-nix"; }; + # weekly updated nix-index database + nix-index-database = { + url = "github:nix-community/nix-index-database"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + #+end_src *** let :PROPERTIES: @@ -545,6 +555,7 @@ Lastly I define some common module lists that I can simply load depending on the ]; # Home-Manager modules wanted on both NixOS and non-NixOS systems mixedModules = [ sops-nix.homeManagerModules.sops + nix-index-database.hmModules.nix-index ./profiles/common/home.nix ]; @@ -5751,13 +5762,34 @@ This section is for programs that require no further configuration. zsh Integrat yt-dlp.enable = true; mpv.enable = true; jq.enable = true; - nix-index.enable = true; ripgrep.enable = true; pandoc.enable = true; fzf.enable = true; zoxide.enable = true; - }; +#+end_src +*** nix-index + +nix-index provides a way to find out which packages are provided by which derivations. By default it also comes with a replacement for =command-not-found.sh=, however, the implementation is based on a channel based setup. I like consistency, so I replace the command with one that provides a flakes-based output. + +#+begin_src nix :tangle profiles/common/home.nix + + nix-index = let + command-not-found = pkgs.runCommandLocal "command-not-found.sh" { } '' + mkdir -p $out/etc/profile.d + substitute ${../../scripts/command-not-found.sh} \ + $out/etc/profile.d/command-not-found.sh \ + --replace @nix-locate@ ${pkgs.nix-index}/bin/nix-locate \ + --replace @tput@ ${pkgs.ncurses}/bin/tput + ''; + in { + enable = true; + package = pkgs.symlinkJoin { + name = "nix-index"; + paths = [ command-not-found ]; + }; + }; + }; #+end_src *** password-store diff --git a/flake.lock b/flake.lock index 7311653..1399b51 100644 --- a/flake.lock +++ b/flake.lock @@ -572,6 +572,26 @@ "type": "github" } }, + "nix-index-database_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720926593, + "narHash": "sha256-fW6e27L6qY6s+TxInwrS2EXZZfhMAlaNqT0sWS49qMA=", + "owner": "nix-community", + "repo": "nix-index-database", + "rev": "5fe5b0cdf1268112dc96319388819b46dc051ef4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-index-database", + "type": "github" + } + }, "nix-on-droid": { "inputs": { "home-manager": "home-manager_2", @@ -1015,6 +1035,7 @@ "lanzaboote": "lanzaboote", "nix-alien": "nix-alien", "nix-gaming": "nix-gaming", + "nix-index-database": "nix-index-database_2", "nix-on-droid": "nix-on-droid", "nixgl": "nixgl", "nixos-generators": "nixos-generators", diff --git a/flake.nix b/flake.nix index df2dcdb..9142c2d 100644 --- a/flake.nix +++ b/flake.nix @@ -66,6 +66,12 @@ nswitch-rcm-nix = { url = "github:Swarsel/nswitch-rcm-nix"; }; + + # weekly updated nix-index database + nix-index-database = { + url = "github:nix-community/nix-index-database"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs @ { @@ -82,6 +88,7 @@ nixos-hardware, nix-alien, nswitch-rcm-nix, + nix-index-database, ... }: let system = "x86_64-linux"; # not very portable, but I do not use other architectures at the moment @@ -127,6 +134,7 @@ # Home-Manager modules wanted on both NixOS and non-NixOS systems mixedModules = [ sops-nix.homeManagerModules.sops + nix-index-database.hmModules.nix-index ./profiles/common/home.nix ]; in { diff --git a/index.html b/index.html index 90ff89c..f08a3af 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + SwarselSystems: NixOS + Emacs Configuration @@ -261,20 +261,21 @@
  • 3.3.6. Linking dotfiles
  • 3.3.7. Sourcing environment variables
  • 3.3.8. Programs
  • -
  • 3.3.9. password-store
  • -
  • 3.3.10. direnv
  • -
  • 3.3.11. eza
  • -
  • 3.3.12. git
  • -
  • 3.3.13. Fuzzel
  • -
  • 3.3.14. Starship
  • -
  • 3.3.15. Kitty
  • -
  • 3.3.16. zsh
  • -
  • 3.3.17. Mail
  • -
  • 3.3.18. Home-manager: Emacs
  • -
  • 3.3.19. Waybar
  • -
  • 3.3.20. Firefox
  • -
  • 3.3.21. Services
  • -
  • 3.3.22. Sway
  • +
  • 3.3.9. nix-index
  • +
  • 3.3.10. password-store
  • +
  • 3.3.11. direnv
  • +
  • 3.3.12. eza
  • +
  • 3.3.13. git
  • +
  • 3.3.14. Fuzzel
  • +
  • 3.3.15. Starship
  • +
  • 3.3.16. Kitty
  • +
  • 3.3.17. zsh
  • +
  • 3.3.18. Mail
  • +
  • 3.3.19. Home-manager: Emacs
  • +
  • 3.3.20. Waybar
  • +
  • 3.3.21. Firefox
  • +
  • 3.3.22. Services
  • +
  • 3.3.23. Sway
  • 3.4. flake.nix template and Closing Parenthesis (this needs to be the last heading in the Systems header) @@ -387,7 +388,7 @@

    -This file has 41033 words spanning 10909 lines and was last revised on 2024-07-19 00:52:31 +0200. +This file has 41233 words spanning 10941 lines and was last revised on 2024-07-19 14:29:02 +0200.

    @@ -437,7 +438,7 @@ This section defines my Emacs configuration. For a while, I considered to use ry

    -My emacs is built using the emacs-overlay nix flake, which builds a bleeding edge emacs on wayland (pgtk) with utilities like treesitter support. By executing the below source block, the current build setting can be updated at any time, and you can see my most up-to-date build options (last updated: 2024-07-19 00:52:31 +0200) +My emacs is built using the emacs-overlay nix flake, which builds a bleeding edge emacs on wayland (pgtk) with utilities like treesitter support. By executing the below source block, the current build setting can be updated at any time, and you can see my most up-to-date build options (last updated: 2024-07-19 14:29:02 +0200)

  • @@ -899,6 +900,7 @@ lanzaboote, nixos-hardware, nix-alien, nswitch-rcm-nix, +nix-index-database, @@ -929,10 +931,13 @@ This brings nix to android in an app that is similar to tmux! Of course most of Provides specific hardware setting for some hardware configurations. For example, this sets some better defaults for my Lenovo Thinkpad P14s Gen2.
  • nix-alien This is supposed to allow me to run unpatched libraries directly without a need for ELF patching or resorting to steam-run. However, I have not yet gotten this to work.
  • -
  • nswitch-rcm-nix +
  • nswitch-rcm-nix Allows auto injection of payloads upon connecting a Nintendo Switch.
  • +
  • nix-index-database +This provides a database for nix-index that is updated weekly. This allows for declarative management, without needing to run the nix-index command for database assembly.
  • +
     nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    @@ -1000,6 +1005,12 @@ nswitch-rcm-nix = {
       url = "github:Swarsel/nswitch-rcm-nix";
     };
     
    +# weekly updated nix-index database
    +nix-index-database = {
    +  url = "github:nix-community/nix-index-database";
    +  inputs.nixpkgs.follows = "nixpkgs";
    +};
    +
     
    @@ -1051,6 +1062,7 @@ homeModules = [ stylix.homeManagerModules.stylix ]; # Home-Manager modules wanted on both NixOS and non-NixOS systems mixedModules = [ sops-nix.homeManagerModules.sops + nix-index-database.hmModules.nix-index ./profiles/common/home.nix ]; @@ -6983,21 +6995,47 @@ programs = { yt-dlp.enable = true; mpv.enable = true; jq.enable = true; - nix-index.enable = true; ripgrep.enable = true; pandoc.enable = true; fzf.enable = true; zoxide.enable = true; -}; - +
    +

    3.3.9. nix-index

    +
    +

    +nix-index provides a way to find out which packages are provided by which derivations. By default it also comes with a replacement for command-not-found.sh, however, the implementation is based on a channel based setup. I like consistency, so I replace the command with one that provides a flakes-based output. +

    + +
    +
    +nix-index = let
    +  command-not-found = pkgs.runCommandLocal "command-not-found.sh" { } ''
    +      mkdir -p $out/etc/profile.d
    +      substitute ${../../scripts/command-not-found.sh}                  \
    +        $out/etc/profile.d/command-not-found.sh             \
    +        --replace @nix-locate@ ${pkgs.nix-index}/bin/nix-locate \
    +        --replace @tput@ ${pkgs.ncurses}/bin/tput
    +      '';
    +in {
    +  enable = true;
    +  package = pkgs.symlinkJoin {
    +    name = "nix-index";
    +    paths = [ command-not-found ];
    +  };
    +};
    +};
    +
    +
    +
    +
    -

    3.3.9. password-store

    +

    3.3.10. password-store

    Enables password store with the pass-otp extension which allows me to store and generate one-time-passwords. @@ -7015,7 +7053,7 @@ programs.password-store = {

    -

    3.3.10. direnv

    +

    3.3.11. direnv

    Enables direnv, which I use for nearly all of my nix dev flakes. @@ -7033,7 +7071,7 @@ programs.direnv = {

    -

    3.3.11. eza

    +

    3.3.12. eza

    Eza provides me with a better ls command and some other useful aliases. @@ -7056,7 +7094,7 @@ programs.eza = {

    -

    3.3.12. git

    +

    3.3.13. git

    Here I set up my git config, automatic signing of commits, useful aliases for my ost used commands (for when I am not using Magit) as well as a git template defined in Linking dotfiles. @@ -7106,7 +7144,7 @@ programs.git = {

    -

    3.3.13. Fuzzel

    +

    3.3.14. Fuzzel

    Here I only need to set basic layout options - the rest is being managed by stylix. @@ -7131,7 +7169,7 @@ programs.fuzzel = {

    -

    3.3.14. Starship

    +

    3.3.15. Starship

    Starship makes my zsh look cooler! I have symbols for most programming languages and toolchains, also I build my own powerline. @@ -7248,7 +7286,7 @@ programs.starship = {

    -

    3.3.15. Kitty

    +

    3.3.16. Kitty

    Kitty is the terminal emulator of choice for me, it is nice to configure using nix, fast, and has a nice style. @@ -7275,7 +7313,7 @@ programs.kitty = {

    -

    3.3.16. zsh

    +

    3.3.17. zsh

    zsh is the most convenient shell for me and it happens to be super neat to configure within home manager. @@ -7341,7 +7379,7 @@ programs.zsh = {

    -

    3.3.17. Mail

    +

    3.3.18. Mail

    Normally I use 4 mail accounts - here I set them all up. Three of them are Google accounts (sadly), which are a chore to setup. The last is just a sender account that I setup SMTP for here. @@ -7482,7 +7520,7 @@ accounts.email = {

    -

    3.3.18. Home-manager: Emacs

    +

    3.3.19. Home-manager: Emacs

    By using the emacs-overlay NixOS module, I can install all Emacs packages that I want to use right through NixOS. This is done by passing my init.el file to the configuration which will then be parsed upon system rebuild, looking for use-package sections in the Elisp code. Also I define here the style of Emacs that I want to run - I am going with native Wayland Emacs here (emacs-pgtk). All of the nice options such as tree-sitter support are enabled by default, so I do not need to adjust the build process. @@ -7545,7 +7583,7 @@ programs.emacs = {

    -

    3.3.19. Waybar

    +

    3.3.20. Waybar

    Again I am just using the first bar option here that I was able to find good understandable documentation for. Of note is that the `cpu` section's `format` is not defined here, but in section 1 (since not every machine has the same number of cores) @@ -7757,7 +7795,7 @@ programs.waybar = {

    -

    3.3.20. Firefox

    +

    3.3.21. Firefox

    Setting up firefox along with some policies that are important to me (mostly disabling telemetry related stuff as well as Pocket). I also enable some integrations that enable super useful packages, namely tridactyl and browserpass. @@ -7877,7 +7915,7 @@ programs.firefox = {

    -

    3.3.21. Services

    +

    3.3.22. Services

    Services that can be defined through home-manager should be defined here. @@ -8016,7 +8054,7 @@ group-by=category

    -

    3.3.22. Sway

    +

    3.3.23. Sway

    I am currently using SwayFX, which adds some nice effects to sway, like rounded corners and hiding the separator between title and content of a window. @@ -8403,6 +8441,12 @@ This tangles the flake.nix file; This block only needs to be touched when updati url = "github:Swarsel/nswitch-rcm-nix"; }; + # weekly updated nix-index database + nix-index-database = { + url = "github:nix-community/nix-index-database"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; outputs = inputs@{ @@ -8420,6 +8464,7 @@ This tangles the flake.nix file; This block only needs to be touched when updati nixos-hardware, nix-alien, nswitch-rcm-nix, + nix-index-database, ... }: let @@ -8458,6 +8503,7 @@ This tangles the flake.nix file; This block only needs to be touched when updati ]; # Home-Manager modules wanted on both NixOS and non-NixOS systems mixedModules = [ sops-nix.homeManagerModules.sops + nix-index-database.hmModules.nix-index ./profiles/common/home.nix ]; @@ -9341,7 +9387,7 @@ The standard Emacs behaviour for the Python process shell is a bit annoying. Thi

    -
  • Nix common prefix bracketer
    +
  • Nix common prefix bracketer

    This function searches for common delimiters in region and removes them, summarizing all captured lines by it. @@ -12912,7 +12958,7 @@ My laptop, sadly soon to be replaced by a new one, since most basic functions ar

    Author: Leon Schwarzäugl

    -

    Created: 2024-07-19 Fr 00:52

    +

    Created: 2024-07-19 Fr 14:29

    Validate

    diff --git a/profiles/common/home.nix b/profiles/common/home.nix index 8e6db0a..4ed5dca 100644 --- a/profiles/common/home.nix +++ b/profiles/common/home.nix @@ -546,11 +546,26 @@ yt-dlp.enable = true; mpv.enable = true; jq.enable = true; - nix-index.enable = true; ripgrep.enable = true; pandoc.enable = true; fzf.enable = true; zoxide.enable = true; + + nix-index = let + command-not-found = pkgs.runCommandLocal "command-not-found.sh" {} '' + mkdir -p $out/etc/profile.d + substitute ${../../scripts/command-not-found.sh} \ + $out/etc/profile.d/command-not-found.sh \ + --replace @nix-locate@ ${pkgs.nix-index}/bin/nix-locate \ + --replace @tput@ ${pkgs.ncurses}/bin/tput + ''; + in { + enable = true; + package = pkgs.symlinkJoin { + name = "nix-index"; + paths = [command-not-found]; + }; + }; }; programs.password-store = { diff --git a/scripts/command-not-found.sh b/scripts/command-not-found.sh new file mode 100644 index 0000000..f6b0b26 --- /dev/null +++ b/scripts/command-not-found.sh @@ -0,0 +1,33 @@ +# Adapted from https://github.com/bennofs/nix-index/blob/master/command-not-found.sh + +command_not_found_handle () { + if [ -n "${MC_SID-}" ] || ! [ -t 1 ]; then + >&2 echo "$1: command not found" + return 127 + fi + + echo -n "searching nix-index..." + ATTRS=$(@nix-locate@ --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$1") + + case `echo -n "$ATTRS" | grep -c "^"` in + 0) + >&2 echo -ne "$(@tput@ el1)\r" + >&2 echo "$1: command not found" + ;; + *) + >&2 echo -ne "$(@tput@ el1)\r" + >&2 echo "The program ‘$(@tput@ setaf 4)$1$(@tput@ sgr0)’ is currently not installed." + >&2 echo "It is provided by the following derivation(s):" + while read ATTR; do + ATTR=$(echo "$ATTR" | sed 's|\.out$||') # Strip trailing '.out' + >&2 echo " $(@tput@ setaf 12)nixpkgs#$(@tput@ setaf 4)$ATTR$(@tput@ sgr0)" + done <<< "$ATTRS" + esac + + return 127 +} + +command_not_found_handler () { + command_not_found_handle $@ + return $? +}