mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2026-04-14 13:19:09 +02:00
chore: change to native nix scripts
This commit is contained in:
parent
80c08a6d19
commit
7ad9d84109
42 changed files with 2071 additions and 2102 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, config, pkgs, ... }:
|
||||
{ lib, config, pkgs, ... }:
|
||||
{
|
||||
options.swarselmodules.nix-index = lib.mkEnableOption "nix-index settings";
|
||||
config = lib.mkIf config.swarselmodules.nix-index {
|
||||
|
|
@ -6,7 +6,43 @@
|
|||
let
|
||||
commandNotFound = pkgs.runCommandLocal "command-not-found.sh" { } ''
|
||||
mkdir -p $out/etc/profile.d
|
||||
substitute ${self + /files/scripts/command-not-found.sh} \
|
||||
cat > $out/etc/profile.d/command-not-found.sh <<'EOF'
|
||||
# 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 --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 -r ATTR; do
|
||||
ATTR=''${ATTR%.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 $?
|
||||
}
|
||||
EOF
|
||||
|
||||
substitute $out/etc/profile.d/command-not-found.sh \
|
||||
$out/etc/profile.d/command-not-found.sh \
|
||||
--replace-fail @nix-locate@ ${pkgs.nix-index}/bin/nix-locate \
|
||||
--replace-fail @tput@ ${pkgs.ncurses}/bin/tput
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue