1
0
Fork 0
nixos/configuration.nix

277 lines
8.9 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2023-02-14 22:16:43 +01:00
let
2024-01-08 13:14:08 +01:00
runPrivileged = if config.security.doas.enable then
"${config.security.wrapperDir}/${config.security.wrappers.doas.program}"
else
"${pkgs.sudo}/bin/sudo";
2024-02-26 16:09:40 +01:00
username = import ./components/username.nix;
in {
environment = {
sessionVariables = { # home decluttering
2023-10-27 10:30:36 +02:00
ANDROID_HOME = "\${XDG_DATA_HOME}/android";
ANDROID_USER_HOME = "\${XDG_DATA_HOME}/android";
2023-10-27 10:30:36 +02:00
CUDA_CACHE_PATH = "\${XDG_CACHE_HOME}/nv";
GNUPGHOME = "\${XDG_DATA_HOME}/gnupg";
2023-11-30 23:37:47 +01:00
GRADLE_USER_HOME = "\${XDG_DATA_HOME}/gradle";
GTK2_RC_FILES = "\${XDG_CONFIG_HOME}/gtk-3.0/gtkrc";
HISTFILE = "\${XDG_STATE_HOME}/bash/history";
2023-10-27 11:21:55 +02:00
IONIC_CONFIG_DIRECTORY = "\${XDG_CONFIG_HOME}/ionic";
_JAVA_OPTIONS = "-Djava.util.prefs.userRoot=\${XDG_CONFIG_HOME}/java";
MYSQL_HISTFILE = "\${XDG_DATA_HOME}/mysql_history";
2023-11-30 23:37:47 +01:00
NODE_REPL_HISTORY = "\${XDG_DATA_HOME}/node_repl_history";
2023-10-27 10:30:36 +02:00
PSQL_HISTORY = "\${XDG_DATA_HOME}/psql_history";
XCOMPOSECACHE = "\${XDG_CACHE_HOME}/X11/xcompose";
2023-10-27 17:01:09 +02:00
XDG_CACHE_HOME = "$HOME/.cache";
XDG_CONFIG_HOME = "$HOME/.config";
XDG_DATA_HOME = "$HOME/.local/share";
XDG_STATE_HOME = "$HOME/.local/state";
} // { # other
HISTCONTROL = "ignorespace";
};
2023-11-30 23:37:47 +01:00
systemPackages = with pkgs;
[ # development
gnumake
postgresql
2023-11-30 23:37:47 +01:00
strace
valgrind
] ++ [ # utilities
acpi
cloak
man-pages
2023-11-30 23:37:47 +01:00
mdcat
unzip
wget
] ++ [ # applications
pulsemixer
R
] ++ [ # other
cifs-utils
ffmpeg
libcxx
libinput
ntfs3g
openal
];
};
2023-11-23 11:48:22 +01:00
home-manager = {
useGlobalPkgs = true;
users.${username} = {
home.file.".ghci".text = ''
:set prompt "λ "
'';
2023-11-23 11:48:22 +01:00
programs = {
bash = {
enable = true;
initExtra = let
cut = "${pkgs.coreutils}/bin/cut";
git = "${pkgs.git}/bin/git";
rg = "${pkgs.ripgrep}/bin/rg";
task = "${pkgs.taskwarrior}/bin/task";
tr = "${pkgs.coreutils}/bin/tr";
wc = "${pkgs.coreutils}/bin/wc";
in ''
task () {
if [[ "$1" == "sync" ]]
then
location="$(${task} diagnostics | ${rg} "Data:" | ${tr} -s " " | ${cut} -d " " -f 3)"
pushd "$location" >/dev/null
${git} pull >/dev/null
if ! [ "$(${git} status --porcelain | ${wc} -l)" -eq 0 ]
then
${git} add . >/dev/null
${git} commit -m "chore: Sync on $(date)" >/dev/null
${git} push origin main >/dev/null
fi
popd >/dev/null
else
command ${task} $@
fi
}
'';
sessionVariables = {
BOOKMARKS_FILE = "\${HOME}/Documents/bookmarks";
PROJECT_MANAGER_PATH = "\${HOME}/Documents/projects";
NVIM_UNDODIR = "\${HOME}/Documents/.undo/";
};
};
git = {
enable = true;
userEmail = "toolbox.0-kindred@icloud.com";
userName = "lwad";
};
2023-11-23 11:48:22 +01:00
};
};
2023-02-14 22:16:43 +01:00
};
2024-02-16 00:20:44 +01:00
imports = [
./components/bootloader.nix
./components/core.nix
2024-02-26 15:01:38 +01:00
./components/programs/neovim.nix
./components/services/tailscale.nix
2024-03-12 00:02:59 +01:00
./lwad
2024-02-16 00:20:44 +01:00
];
2024-03-12 00:02:59 +01:00
lwad = {
applications = {
btop.enable = true;
git.enable = true;
task.enable = true;
2024-03-12 00:02:59 +01:00
};
development.languages = {
bash.enable = true;
c.enable = true;
erlang.enable = true;
java.enable = true;
python.enable = true;
rust.enable = true;
typescript.enable = true;
};
utilities = {
qol.enable = true;
remote.enable = true;
terminal.enable = true;
};
2024-03-12 00:02:59 +01:00
};
2023-02-14 22:16:43 +01:00
programs = {
dconf.enable = true;
bash = {
interactiveShellInit = let
cut = "${pkgs.coreutils}/bin/cut";
echo = "${pkgs.coreutils}/bin/echo";
2024-02-08 16:35:00 +01:00
fzf = "${pkgs.fzf}/bin/fzf";
git = "${pkgs.git}/bin/git";
head = "${pkgs.coreutils}/bin/head";
2024-02-08 16:35:00 +01:00
sort = "${pkgs.coreutils}/bin/sort";
task = "${pkgs.taskwarrior}/bin/task";
tmux = "${pkgs.tmux}/bin/tmux";
in ''
git() {
2024-02-08 16:35:00 +01:00
if [[ "$1" == "commit" ]] && [ -f "$(${git} rev-parse --show-toplevel)/.precommit" ]; then
$(${git} rev-parse --show-toplevel)/.precommit
fi
2024-02-08 16:35:00 +01:00
${git} "$@"
}
listen() {
${pkgs.yt-dlp}/bin/yt-dlp \
--force-ipv4 \
--concurrent-fragments 4 \
--paths "/tmp" \
--output "%(album)s/%(playlist_index)s-%(title)s.%(ext)s" \
--restrict-filenames \
--embed-metadata \
--embed-thumbnail \
--yes-playlist \
--extract-audio \
--audio-format mp3 \
"$1"
}
play() {
if [[ "$1" == "" ]]; then
2024-01-18 12:34:45 +01:00
target="."
else
target="$1"
fi
${pkgs.mpv}/bin/mpv --video=no --display-tags-clr "$target"
}
${lib.concatStringsSep "\n" (map (category: ''
${category}() {
if [[ $1 == "add" ]]; then
shift
2024-02-08 16:35:00 +01:00
${task} add project:${category} $@
else
2024-02-08 16:35:00 +01:00
${task} project:${category} $@
fi
}
2024-02-01 14:19:05 +01:00
'') [ "learn" "uni" "life" ])}
where() {
_get_pane() {
for pid in $(${pkgs.lsof}/bin/lsof -Fp "$1"); do
pid=''${pid#p}
pts="/dev/$(${pkgs.procps}/bin/ps -o tty= -p $pid)"
2024-02-08 16:35:00 +01:00
for pane in $(${tmux} list-panes -a -F "#{pane_tty}~#{session_name}~#{pane_id}"); do
if [[ "$(${cut} -d "~" -f 1 <<< $pane)" == "$pts" ]]; then
${echo} $pane
fi
done
done
}
2024-02-08 16:35:00 +01:00
panes=$(_get_pane "$1" | ${sort} -u)
if [ -n "$panes" ]; then
for pane in $panes; do
${echo} "The file is open in: $(${cut} -d "~" -f 1 --complement <<< "$pane" | ${pkgs.gnused}/bin/sed -e "s/~/ => /")."
done
else
${echo} "No process could be found. Delete the swap file." >&2
fi
}
2024-02-08 16:35:00 +01:00
spy() {
current_session="$(${tmux} list-clients -t "$TMUX_PANE" -F "#S" | ${head} -n 1)"
if [ -n "$1" ]; then
query="-1 -q $1"
else
query=""
fi
session="$(${tmux} list-clients -F "#S" | sort -u | sed -e "/$current_session/d" | ${fzf} -0 $query --prompt "current> " || ${tmux} list-sessions -F "#S" | sort -u | sed -e "/$current_session/d" | ${fzf} -0 $query --prompt "old> ")" && \
TMUX="" ${tmux} attach-session -r -t "$session"
2024-02-08 16:35:00 +01:00
}
,() {
if [ -x "./.run" ]
then
./run $@
fi
if basedir="$(git rev-parse --show-toplevel 2>/dev/null)" && [ -x "$basedir/.run" ]
then
"$basedir/.run" $@
fi
}
2024-01-04 12:53:08 +01:00
complete -F _command doas
'';
shellAliases = {
base = ''cd "$(tmux list-panes -F "#{pane_start_path}" | head -n 1)"'';
calculator = "(cd && R --save --quiet)";
chvt = "${runPrivileged} ${pkgs.kbd}/bin/chvt";
connected = ''
ssh scc230@shinobu 'users="" && for tmux_client in $(tmux list-clients | cut -d ":" -f 1 | cut -d "/" --complement -f 1,2); do if [ -n "$users" ]; then users+="@"; fi && users+="$(tailscale whois --json "$(last | rg "still logged in" | rg "$tmux_client" | tr -s " " | cut -d " " -f 3)" | jq -r ".UserProfile.DisplayName")"; done && echo "$users"' | tr "@" "\n" | sort -u
'';
drivediff = ''
2024-02-26 16:09:40 +01:00
rsync -nilrc --delete /mnt/external/Documents/ /home/${username}/Documents/ | sed -e "/.undo/d" -e "/.git/d"'';
here = "pwd >/tmp/herethere";
open = "xdg-open";
otp = ''
${pkgs.cloak}/bin/cloak view lancs | ${pkgs.coreutils}/bin/tr -d "\n" | ${pkgs.xclip}/bin/xclip -i -selection clipboard'';
2024-02-08 16:35:00 +01:00
pk = "tmux kill-session -t PROJECTS";
psql = "psql -d scc230 -U scc230 -p 5432 -h shinobu";
2024-02-26 20:02:43 +01:00
repo = ''
2024-03-12 00:02:59 +01:00
directory="$((cd /home/${username} && ${pkgs.fd}/bin/fd -H "^\.git$" Documents -x dirname {}) | sort -h | ${pkgs.fzf}/bin/fzf)" && (pushd "/home/${username}/$directory" >/dev/null; bash -i; popd >/dev/null)'';
serverfs = ''
base=$(git rev-parse --show-toplevel 2>/dev/null) && sshfs -o uid=$(id -u),gid=$(id -g) scc230@shinobu:/home/scc230/per-user/luke/server "$base/server"'';
there = ''cd "$(head -n 1 /tmp/herethere)"'';
wget = ''wget --hsts-file="$XDG_DATA_HOME/wget-hsts"'';
xclip = "xclip -selection clipboard";
};
2023-02-14 22:16:43 +01:00
};
};
services.pipewire = {
audio.enable = true;
enable = true;
pulse.enable = true;
socketActivation = true;
2023-05-25 15:23:31 +02:00
};
users = {
defaultUserShell = pkgs.bash;
2024-03-11 21:44:56 +01:00
users.${username}.extraGroups = [ "video" ];
};
2023-02-14 22:16:43 +01:00
}