Compare commits

...

14 commits

16 changed files with 366 additions and 33 deletions

View file

@ -161,6 +161,7 @@ toggle_oppacity.sh
Other dotfiles that I learned / copy from: Other dotfiles that I learned / copy from:
- [Frost-Phoenix/nixos-config](https://github.com/Frost-Phoenix/nixos-config): This is the repository that I cloned and changed to my needs. Their credits are in their repository's readme. - [Frost-Phoenix/nixos-config](https://github.com/Frost-Phoenix/nixos-config): This is the repository that I cloned and changed to my needs. Their credits are in their repository's readme.
- [IvarWithoutBones/dotfiles](https://github.com/IvarWithoutBones/dotfiles)
- [notthebee/nix-config](https://github.com/notthebee/nix-config) - [notthebee/nix-config](https://github.com/notthebee/nix-config)
- [mrusme/dotfiles](https://github.com/mrusme/dotfiles) - [mrusme/dotfiles](https://github.com/mrusme/dotfiles)

View file

@ -12,7 +12,6 @@
./../../modules/core/virtualization.nix ./../../modules/core/virtualization.nix
./../../modules/services/tailscale.nix ./../../modules/services/tailscale.nix
./../../modules/services/mpd.nix ./../../modules/services/mpd.nix
./../../modules/services/syncthing.nix
./../../modules/services/smart-monitoring.nix ./../../modules/services/smart-monitoring.nix
inputs.nixos-hardware.nixosModules.framework-13-7040-amd inputs.nixos-hardware.nixosModules.framework-13-7040-amd
]; ];
@ -49,7 +48,7 @@
networking = { networking = {
hostName = "sakura"; hostName = "sakura";
networkmanager.ethernet.macAddress = "13:37:13:37:13:37"; # networkmanager.ethernet.macAddress = "13:37:6a:8a:ed:a4";
}; };
powerManagement = { powerManagement = {

View file

@ -29,18 +29,19 @@
libraries = with pkgs; [ ]; libraries = with pkgs; [ ];
}; };
# nixpkgs = { nixpkgs = {
# overlays = [ overlays = [
# self.overlays.default self.overlays.default
# inputs.nur.overlay # inputs.nur.overlay
# ]; ];
# }; };
nixpkgs.config = { nixpkgs.config = {
allowUnfree = true; allowUnfree = true;
permittedInsecurePackages = [ permittedInsecurePackages = [
"jitsi-meet-1.0.8043" "jitsi-meet-1.0.8043"
"olm-3.2.16" "olm-3.2.16"
"libsoup-2.74.3"
]; ];
overlays = [ overlays = [
self.overlays.default self.overlays.default

View file

@ -8,6 +8,7 @@
pkgs.noto-fonts-emoji pkgs.noto-fonts-emoji
pkgs.swww pkgs.swww
pkgs.swaylock pkgs.swaylock
pkgs.pywal16
]; ];
gtk = { gtk = {

View file

@ -62,7 +62,6 @@
reader reader
nmap nmap
speedtest-go speedtest-go
delta
powertop powertop
android-tools android-tools
sshpass sshpass

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
magick convert "$1" ~/.local/share/bg.png magick convert "$1" ~/.local/share/bg.png
wal -i "$1"
swww img ~/.local/share/bg.png --transition-type fade swww img ~/.local/share/bg.png --transition-type fade

View file

@ -3,6 +3,7 @@
config, config,
pkgs, pkgs,
host, host,
lib,
... ...
}: }:
{ {
@ -46,6 +47,8 @@
}; };
initContent = '' initContent = ''
export export PATH="''${PATH}:''${HOME}/.local/bin/:''${HOME}/.cargo/bin/:''${HOME}/.fzf/bin/"
autoload -U add-zsh-hook autoload -U add-zsh-hook
autoload -U compinit autoload -U compinit
zmodload zsh/complist zmodload zsh/complist
@ -135,7 +138,11 @@
fi fi
} }
export export PATH="''${PATH}:''${HOME}/.local/bin/:''${HOME}/.cargo/bin/:''${HOME}/.fzf/bin/" # Enter a 'nix shell' with packages selected by fzf
source ${pkgs.nix-search-fzf.zsh-shell-widget}
zle -N nix-search-fzf-shell-widget
bindkey '^O' nix-search-fzf-shell-widget
# if [[ $(which sxiv&>/dev/null && echo 1) == "1" ]]; then # if [[ $(which sxiv&>/dev/null && echo 1) == "1" ]]; then
# alias imv="sxiv" # alias imv="sxiv"
@ -149,7 +156,6 @@
enable = true; enable = true;
abbreviations = { abbreviations = {
mkdir = "mkdir -p"; mkdir = "mkdir -p";
mv = "mv --interactive";
vim = "nvim"; vim = "nvim";
v = "nvim"; v = "nvim";
vi = "nvim"; vi = "nvim";
@ -198,13 +204,19 @@
yt-dlp-audio = "yt-dlp -f 'ba' -x --audio-format mp3"; yt-dlp-audio = "yt-dlp -f 'ba' -x --audio-format mp3";
open = "xdg-open"; open = "xdg-open";
tree = "eza --icons --tree --group-directories-first"; tree = "eza --icons --tree --group-directories-first";
# nvim = "nix run /home/liv/Development/nixvim --";
vim = "nvim";
doas = "sudo"; doas = "sudo";
sxiv = "nsxiv"; sxiv = "nsxiv";
enby = "man"; enby = "man";
woman = "man"; woman = "man";
mkcd = "mkdir $1 && cd $1"; mkcd = "mkdir $1 && cd $1";
du = "dust";
cp = "cp -i -v";
mv = "mv -i -v";
rm = "rm -i -v";
cat = "${lib.getExe pkgs.bat} --plain";
diff = "${lib.getExe pkgs.delta} --color-only";
battery-left = "${lib.getExe pkgs.acpi} | cut -d' ' -f5";
github-actions = "${lib.getExe pkgs.act} -s GITHUB_TOKEN=\"$(${lib.getExe pkgs.github-cli} auth token)\"";
# NixOS # NixOS
ns = "nix-shell --run zsh"; ns = "nix-shell --run zsh";
@ -249,4 +261,11 @@
enableZshIntegration = true; enableZshIntegration = true;
}; };
}; };
home.packages = with pkgs; [
dust
fd
delta
bat
nix-search-fzf.zsh-shell-widget
];
} }

View file

@ -7,7 +7,6 @@
++ [ (import ./home-assistant.nix) ] ++ [ (import ./home-assistant.nix) ]
++ [ (import ./monitoring.nix) ] ++ [ (import ./monitoring.nix) ]
++ [ (import ./smart-monitoring.nix) ] ++ [ (import ./smart-monitoring.nix) ]
++ [ (import ./syncthing.nix) ]
++ [ (import ./tailscale.nix) ] ++ [ (import ./tailscale.nix) ]
++ [ (import ./nfs.nix) ] ++ [ (import ./nfs.nix) ]
++ [ (import ./hd-idle.nix) ]; ++ [ (import ./hd-idle.nix) ];

View file

@ -1,3 +1,3 @@
{ {
addition = final: _: import ../pkgs { pkgs = final; }; addition = final: _: import ../pkgs/default.nix { pkgs = final; };
} }

View file

@ -0,0 +1,40 @@
{
lib,
runCommand,
makeWrapper,
}:
# A function which creates a shell script with optional dependencies added to PATH.
name: src:
{
dependencies ? [ ],
...
}@attrs:
runCommand name
(
{
inherit src;
nativeBuildInputs = lib.optionals (dependencies != [ ]) (attrs.nativeBuildInputs or [ ]) ++ [
makeWrapper
];
meta = {
mainProgram = name;
} // attrs.meta or { };
}
// (builtins.removeAttrs attrs [
"nativeBuildInputs"
"meta"
])
)
''
mkdir -p $out/bin
install -Dm755 $src $out/bin/$name
patchShebangs $out/bin/$name
${lib.optionalString (dependencies != [ ]) ''
wrapProgram $out/bin/$name --prefix PATH : ${lib.makeBinPath dependencies}
''}
''

View file

@ -1,4 +1,5 @@
{ pkgs }: { pkgs }:
{ {
wikit = pkgs.callPackage ./wikit/default.nix { }; createScript = pkgs.callPackage ./createScript/default.nix { };
nix-search-fzf = pkgs.callPackage ./nix-search-fzf/default.nix { };
} }

View file

@ -0,0 +1,50 @@
{
createScript,
replaceVars,
gnused,
jq,
fzf,
nix,
coreutils,
bash,
nix-search-fzf,
writeShellScript,
}:
let
previewText = createScript "fzf-preview" ./fzf-preview.sh { };
src = replaceVars ./nix-search-fzf.sh {
previewText = "${previewText}/bin/fzf-preview";
};
in
createScript "nix-search-fzf" src {
dependencies = [
gnused
jq
fzf
nix
coreutils
bash
];
# Enter a 'nix shell' with packages selected by this script
passthru.zsh-shell-widget = writeShellScript "nix-search-fzf-shell-widget" ''
nix-search-fzf-shell-widget() {
setopt localoptions pipefail no_aliases 2> /dev/null
local cmd="$(eval "${nix-search-fzf}/bin/nix-search-fzf -c")"
if [[ -z "$cmd" ]]; then
zle redisplay
return 0
fi
zle push-line
BUFFER="''${cmd}"
zle accept-line
local ret=$?
unset cmd
zle reset-prompt
return $ret
}
'';
meta.description = "a wrapper around 'nix {run,shell,edit}' with autocomplete using fzf";
}

View file

@ -0,0 +1,73 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p
# shellcheck shell=bash
set -euo pipefail
PKG_NAME="$1"
FLAKE="$2"
FLAKE_PATH="${FLAKE}#${PKG_NAME}"
removeQuotes() {
local flag="$*"
flag="${flag%\"}"
echo "${flag#\"}"
}
newlinesToCommaSeperated() {
echo "$@" | sed ':a;N;$!ba;s/\n/, /g'
}
evalAttr() {
local attr data
attr="$1"
data="$(nix eval "$FLAKE_PATH"."$attr" 2>/dev/null)"
[[ $data != "null" && $data != "false" && -n $data ]] && removeQuotes "$data"
}
evalJsonAttr() {
local attr jqArgs data
attr="$1"
jqArgs="$2"
data="$(nix eval --json "$FLAKE_PATH"."$attr" 2>/dev/null | jq -r "$jqArgs")"
[[ $data != "null" && -n $data ]] && echo "$data"
}
evalNixpkgsLib() {
local function data
function="$1"
# Impure is needed to import the flake reference
data="$(nix eval --raw --impure --expr "let pkgs = (builtins.getFlake \"flake:$FLAKE\"); in pkgs.lib.$function pkgs.$PKG_NAME" 2>/dev/null)"
[[ $data != "null" && -n $data ]] && echo "$data"
}
maybeEcho() {
local -r prefix="$1"
local flag="$2"
local -r commaSeperated="${3:-false}"
[[ $commaSeperated == "true" ]] && flag="$(newlinesToCommaSeperated "$flag")"
test -n "$flag" && echo "$prefix $flag"
}
test -n "$(evalAttr "meta.broken")" && echo "broken: true"
test -n "$(evalAttr "meta.insecure")" && echo "insecure: true"
version="$(evalAttr "version")"
# Derive the version from "name" using 'lib.getVersion' if it's not set
test -z "$version" && version="$(evalNixpkgsLib "getVersion")"
maybeEcho "version:" "$version"
homepage="$(evalAttr "meta.homepage")"
maybeEcho "homepage:" "$homepage"
description="$(evalAttr "meta.description")"
maybeEcho "description:" "$description"
license="$(evalJsonAttr "meta.license" 'if type=="array" then .[].fullName else .fullName end')"
maybeEcho "license:" "$license" true
maintainers="$(evalJsonAttr "meta.maintainers" '.[].github')"
maybeEcho "maintainers:" "$maintainers" true
platforms="$(evalJsonAttr "meta.platforms" 'if type=="array" then .[] else . end')"
maybeEcho "platforms:" "$platforms" true

View file

@ -0,0 +1,161 @@
#!/usr/bin/env bash
# An fzf script with autocomplete from "nix search" which allows for interactive fuzzy searching of derivations.
# After the search a nix subcommand is executed on the selected derivation(s), e.g. "nix shell" or "nix run".
set -eou pipefail
FLAKE="nixpkgs" # The default flake to use. TODO: make this configurable
NIX_SUBCOMMAND="shell" # The default nix subcommand to execute
MULTIPLE_SELECTION=true # Whether to allow the user to select multiple derivations
PRINT_COMMAND=false # Only print the command that would be executed, don't execute it
if [ -n "${XDG_CACHE_HOME-}" ]; then
CACHE_PATH="$XDG_CACHE_HOME/nix-search-fzf/cache.txt"
else
CACHE_PATH="$HOME/.cache/nix-search-fzf/cache.txt"
fi
# Because fzf executes commands from keybindings in a subprocess, we cannot directly change this scripts state.
# Instead we can use a temporary file as an IPC mechanism, to change which subcommand to execute.
TMP_FILE="$(mktemp --dry-run --suffix "-nix-search-fzf")"
trap 'rm -f "$TMP_FILE"' EXIT INT TERM
handleArguments() {
while (("$#" > 0)); do
case "$1" in
-s | shell | --shell)
NIX_SUBCOMMAND="shell"
;;
-b | build | --build)
NIX_SUBCOMMAND="build"
;;
-r | run | --run)
NIX_SUBCOMMAND="run"
MULTIPLE_SELECTION=false
;;
-e | edit | --edit)
NIX_SUBCOMMAND="edit"
MULTIPLE_SELECTION=false
;;
-c | command | --command)
PRINT_COMMAND=true
;;
-u | update | --update)
manageCache true
exit
;;
-h | help | --help)
echo "Usage: $(basename "$0") [--shell|--build|--run|--edit|--update]"
echo " --shell: enter a nix shell with the selected package(s). This is the default"
echo " --build: build the selected package(s) with nix build"
echo " --run: run the selected package with nix run"
echo " --edit: edit the selected package with nix edit"
echo " --command: only print the command that would be executed, don't execute it"
echo " --update: update the nix search cache, this is done automatically every 10 days"
echo " --help: show this help message"
exit 0
;;
*)
echo "Unknown option '$1'"
exit 1
;;
esac
shift 1
done
}
runColored() {
printf "\e[32m\$ %s\n\e[0m" "$1"
eval "$1"
}
manageCache() {
local doUpdate="${1:-false}"
mkdir -p "$(dirname "$CACHE_PATH")"
if [ ! -f "$CACHE_PATH" ] || [ ! -s "$CACHE_PATH" ]; then
doUpdate="true"
echo "attribute path cache does not exist, generating..." >&2
elif (($(date -r "$CACHE_PATH" +%s) < $(date -d "now - 10 days" +%s))); then
doUpdate="true"
echo "cache file is older than 10 days, updating..." >&2
fi
if [ "$doUpdate" == "true" ]; then
echo "caching attribute paths..." >&2
# Create a list of all attribute paths with "legacyPackages.$arch" stripped
# In the future this could contain metadata as well, doing a "nix-eval" for each is not the fastest
nix search "$FLAKE" "^" --quiet --json | jq -r 'keys[]' | cut -d'.' -f3- >"$CACHE_PATH"
echo "successfully generated attribute path cache" >&2
fi
}
fzfBindingFlag() {
local tmpFile="$1"
local -A bindings=(
["shell"]="ctrl-s"
["build"]="ctrl-b"
["edit"]="ctrl-e"
["run"]="ctrl-r"
)
local result="--bind="
for subCommand in "${!bindings[@]}"; do
local binding="${bindings[$subCommand]}"
# When pressed, write the appropriate command to our temporary IPC file, and change the prompt accordingly
result+="$binding:execute-silent(echo $subCommand > $tmpFile)+change-prompt($subCommand > ),"
done
echo "${result%,}"
}
runFzf() {
local multi_flag
if [ "$MULTIPLE_SELECTION" == true ]; then
multi_flag="--multi"
else
multi_flag="--no-multi"
fi
fzf "$multi_flag" \
--height 40% \
--preview-window right,70% \
--border rounded \
--prompt "$NIX_SUBCOMMAND > " \
--preview "bash -c \"@previewText@ {} $FLAKE\"" \
"$(fzfBindingFlag "$TMP_FILE")" <"$CACHE_PATH"
}
runNix() {
local packages selectedPkgs command
readarray -t selectedPkgs <<<"$@"
((${#selectedPkgs[@]} == 0)) && exit 0
if [ "$MULTIPLE_SELECTION" == true ] && ((${#selectedPkgs[@]} > 1)); then
# Build a brace expansion string
local pkg_list="{"
for pkg in "${selectedPkgs[@]}"; do
pkg_list+="$pkg,"
done
packages="${pkg_list%,}}"
else
packages="${selectedPkgs[0]}"
fi
((${#packages} == 0)) && exit 0
# Update what subcommand to execute, in case it was changed by a keybinding from fzf
[ -s "$TMP_FILE" ] && NIX_SUBCOMMAND="$(<"$TMP_FILE")"
command="NIXPKGS_ALLOW_UNFREE=1 nix $NIX_SUBCOMMAND $FLAKE#$packages --impure"
if [ "$PRINT_COMMAND" == true ]; then
echo "$command"
exit 0
else
runColored "$command"
fi
}
handleArguments "$@"
manageCache
runNix "$(runFzf)"

View file

@ -1,16 +0,0 @@
{ lib, ... }:
with lib;
let
src = fetchFromGitHub {
owner = "KorySchneider";
repo = "wikit";
rev = "6432c6020606868cc5f240d0317040e38b992292";
};
in {
wikit = mkYarnPackage {
name = "wikit";
inherit src;
packageJSON = src + "./package.json";
yarnLock = src + "./yarn.lock";
};
}

View file

@ -49,6 +49,10 @@ in
# Not GUI but specific to GUI usage # Not GUI but specific to GUI usage
sshuttle sshuttle
sshfs
# try out for a bit
niri
]; ];
}; };
} }