108 lines
4.1 KiB
Nix
108 lines
4.1 KiB
Nix
{ lib, pkgs, ... }: {
|
|
|
|
users.groups.gandalf = { gid = 1000; };
|
|
|
|
users.users.gandalf = {
|
|
isNormalUser = true;
|
|
home = "/home/gandalf";
|
|
createHome = true;
|
|
group = "gandalf";
|
|
extraGroups = [ "wheel" ];
|
|
shell = pkgs.zsh;
|
|
};
|
|
|
|
programs.zsh = {
|
|
enable = true;
|
|
ohMyZsh = {
|
|
enable = true;
|
|
theme = "half-life";
|
|
};
|
|
syntaxHighlighting.enable = true;
|
|
enableCompletion = true;
|
|
autosuggestions.enable = true;
|
|
shellAliases = {
|
|
ls = "${pkgs.eza}/bin/eza --group-directories-first --hyperlink --icons";
|
|
la =
|
|
"${pkgs.eza}/bin/eza --group-directories-first --hyperlink --icons -la";
|
|
ll =
|
|
"${pkgs.expect}/bin/unbuffer ${pkgs.eza}/bin/eza --group-directories-first --hyperlink --icons -la | ${pkgs.less}/bin/less -r";
|
|
lt =
|
|
"${pkgs.eza}/bin/eza --group-directories-first --hyperlink --icons -la --tree";
|
|
llt =
|
|
"${pkgs.expect}/bin/unbuffer ${pkgs.eza}/bin/eza --group-directories-first --hyperlink --icons -la --tree | ${pkgs.less}/bin/less -r";
|
|
sa = ''
|
|
if ps -p $SSH_AGENT_PID > /dev/null 2>&1; then ${pkgs.gum}/bin/gum log -l info "ssh-agent is already running: pid: $SSH_AGENT_PID"; else eval $(ssh-agent); ssh-add ~/.ssh/id_ed25519; ${pkgs.gum}/bin/gum log -l info "ssh-agent started"; fi'';
|
|
};
|
|
};
|
|
|
|
environment.systemPackages = [
|
|
(pkgs.writeShellScriptBin "n" ''
|
|
set -euo pipefail
|
|
|
|
action=$(${pkgs.gum}/bin/gum choose --header "Choose action:" build clean)
|
|
target=$(${pkgs.gum}/bin/gum choose --header "Choose target:" PABU APPA MOMO)
|
|
|
|
case "$target" in
|
|
"PABU")
|
|
;;
|
|
*)
|
|
if ! ps -p $SSH_AGENT_PID > /dev/null; then
|
|
${pkgs.gum}/bin/gum log -t kitchen -l error "ssh-agent is not running! Please run \"sa\". Exiting ..."
|
|
exit 1
|
|
fi
|
|
${pkgs.rsync}/bin/rsync -r . $target:/root/nix/
|
|
;;
|
|
esac
|
|
|
|
case "$action" in
|
|
"clean")
|
|
case "$target" in
|
|
"PABU")
|
|
${pkgs.gum}/bin/gum log -t kitchen -l info "Running: sudo nix-collect-garbage -d && nix store gc && nix-store --optimise"
|
|
sudo nix-collect-garbage -d && nix store gc && nix-store --optimise
|
|
;;
|
|
*)
|
|
${pkgs.gum}/bin/gum log -t kitchen -l info "Running: ssh $target \"nix-collect-garbage -d && nix store gc && nix-store --optimise\""
|
|
ssh $target "nix-collect-garbage -d && nix store gc && nix-store --optimise"
|
|
;;
|
|
esac
|
|
;;
|
|
"build")
|
|
case "$target" in
|
|
"PABU")
|
|
sudo nixos-rebuild build --option sandbox false --log-format internal-json -v --flake .#PABU |& ${pkgs.nix-output-monitor}/bin/nom --json
|
|
${pkgs.nvd}/bin/nvd --color=always diff /run/current-system result
|
|
postBuildAction=$(${pkgs.gum}/bin/gum choose --header "Choose post-build-action" skip switch boot test )
|
|
case "$postBuildAction" in
|
|
"skip")
|
|
${pkgs.gum}/bin/gum log -t kitchen -l info "Skipping ..."
|
|
;;
|
|
*)
|
|
sudo ./result/bin/switch-to-configuration $postBuildAction
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
ssh $target "cd /root/nix; nixos-rebuild build --log-format internal-json -v --flake .#$target" |& ${pkgs.nix-output-monitor}/bin/nom --json
|
|
ssh $target "cd /root/nix; nix run nixpkgs#nvd -- --color=always diff /run/current-system result"
|
|
postBuildAction=$(${pkgs.gum}/bin/gum choose --header "Choose post-build-action" skip switch boot test )
|
|
case "$postBuildAction" in
|
|
"skip")
|
|
${pkgs.gum}/bin/gum log -t kitchen -l info "Skipping ..."
|
|
;;
|
|
*)
|
|
ssh $target "cd /root/nix; ./result/bin/switch-to-configuration $postBuildAction"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
${pkgs.gum}/bin/gum log -t kitchen -l error "Unkown action: $action. Exiting ..."
|
|
exit 1
|
|
;;
|
|
esac
|
|
'')
|
|
];
|
|
|
|
}
|