1
0
Fork 0

feat: Move btrbk into utilities options

This commit is contained in:
lwad 2024-03-13 22:23:09 +00:00
parent 531c60b8c0
commit 20ae1a2c96
20 changed files with 353 additions and 247 deletions

View File

@ -33,8 +33,14 @@ in {
../components/filesystems.nix
../components/programs/doas.nix
../components/services/mariadb.nix
../lwad
./hardware-configuration.nix
];
lwad.utilities.btrbk.snapshots = [{
volume = "/";
subvolume = "home/${username}/Documents";
snapshotDir = "home/${username}/snapshots";
}];
networking = {
hostName = "akame";
firewall.interfaces."tailscale0".allowedTCPPorts = [ 8081 ];
@ -55,8 +61,6 @@ in {
'';
};
services = {
btrbk.instances.${config.networking.hostName}.settings.volume."/".subvolume."home/${username}/Documents".snapshot_dir =
"home/${username}/snapshots";
hardware.openrgb = {
enable = true;
motherboard = "intel";

View File

@ -19,5 +19,4 @@
];
};
};
imports = [ ./snapshots/snapshot-service.nix ];
}

View File

@ -1,4 +1,4 @@
{ config, inputs, lib, pkgs, ... }:
{ config, pkgs, ... }:
let username = import ../username.nix;
in {
@ -70,6 +70,12 @@ in {
};
useUserPackages = true;
};
imports = [ ../../lwad ];
lwad.utilities.btrbk.snapshots = [{
volume = "/";
subvolume = "home/scc230/per-user";
snapshotDir = "home/scc230/snapshots";
}];
networking.firewall.interfaces."tailscale0" = {
allowedTCPPortRanges = [
{
@ -94,8 +100,6 @@ in {
};
};
services = {
btrbk.instances.${config.networking.hostName}.settings.volume."/".subvolume."home/scc230/per-user".snapshot_dir =
"home/scc230/snapshots";
postgresql = {
authentication = ''
host scc230 scc230 100.0.0.0/8 trust

View File

@ -1,10 +0,0 @@
{ pkgs, ... }:
{
services.btrbk.sshAccess = [{
key = "";
roles = [ "delete" "source" ];
}];
systemd.tmpfiles.rules = [ "v /backups 700 root root" ];
users.users.btrbk.packages = with pkgs; [ mbuffer zstd ];
}

View File

@ -1,22 +0,0 @@
{ config, lib, pkgs, ... }:
{
services.btrbk = {
extraPackages = with pkgs; [ zstd ];
instances.${config.networking.hostName} = {
onCalendar = "daily";
settings = {
send_compressed_data = "yes";
snapshot_preserve = "14d 3m";
snapshot_preserve_min = "2d";
ssh_user = "btrbk";
stream_buffer = "25%";
stream_buffer_remote = "25%";
stream_compress = "zstd";
transaction_syslog = "user";
};
};
};
systemd.services."btrbk-${config.networking.hostName}".restartIfChanged =
false;
}

View File

@ -1,13 +0,0 @@
{ config, ... }:
let backup_server = "shinobu";
in {
services.btrbk.instances.${config.networking.hostName}.settings = {
target_preserve = "3w 3m";
target_preserve_min = "no";
volume."/".subvolume."home/${
import ../username.nix
}/Documents".target."ssh://${backup_server}/backups/${config.networking.hostName}" =
{ };
};
}

View File

@ -97,53 +97,11 @@ in {
NVIM_UNDODIR = "\${HOME}/Documents/.undo/";
};
};
btop = {
enable = true;
package = pkgs.btop;
settings = {
disks_filter = "/ /boot/efi";
proc_tree = true;
theme_background = false;
update_ms = 100;
vim_keys = true;
};
};
git = {
enable = true;
userEmail = "toolbox.0-kindred@icloud.com";
userName = "lwad";
};
taskwarrior = {
config = {
calendar.weekstart = "Monday";
color.scheduled = "white on color4";
news.version = lib.concatStringsSep "."
((lib.sublist 0 2 (lib.splitVersion pkgs.taskwarrior.version))
++ [ "0" ]);
report."brief" = {
columns = [
"id"
"project"
"scheduled"
"due"
"depends"
"description.count"
];
filter = "status:pending project:uni";
labels = [ "ID" "Project" "Scheduled" "Due" "Dep" "Description" ];
sort = [ "priority-/" "project-" "description+" ];
};
terminal.editor = "nvim";
uda.link = {
label = "link";
type = "string";
};
};
dataLocation =
config.home-manager.users.${username}.home.homeDirectory
+ "/Documents/tasks";
enable = true;
};
};
};
};
@ -155,10 +113,10 @@ in {
./lwad
];
lwad = {
utilities = {
qol.enable = true;
remote.enable = true;
terminal.enable = true;
applications = {
btop.enable = true;
git.enable = true;
task.enable = true;
};
development.languages = {
bash.enable = true;
@ -169,6 +127,11 @@ in {
rust.enable = true;
typescript.enable = true;
};
utilities = {
qol.enable = true;
remote.enable = true;
terminal.enable = true;
};
};
programs = {
dconf.enable = true;
@ -299,17 +262,6 @@ in {
xclip = "xclip -selection clipboard";
};
};
git = {
config = {
core.excludesFile = pkgs.writeText "gitignore" ''
.virtfs_metadata
.run
'';
init.defaultBranch = "main";
push.autoSetupRemote = true;
};
enable = true;
};
};
services.pipewire = {
audio.enable = true;

68
lwad/applications.nix Normal file
View File

@ -0,0 +1,68 @@
{ config, lib, pkgs, ... }:
with lib; {
options.lwad.applications = {
btop.enable = mkEnableOption "btop";
git.enable = mkEnableOption "git";
task.enable = mkEnableOption "taskwarrior";
};
config = let
cfg = config.lwad.applications;
username = import ../components/username.nix;
in {
home-manager.users.${username}.programs = {
btop = mkIf cfg.btop.enable {
enable = true;
package = pkgs.btop;
settings = {
disks_filter = "/ /boot/efi";
proc_tree = true;
theme_background = false;
update_ms = 100;
vim_keys = true;
};
};
taskwarrior = mkIf cfg.task.enable {
config = {
calendar.weekstart = "Monday";
color.scheduled = "white on color4";
news.version = lib.concatStringsSep "."
((lib.sublist 0 2 (lib.splitVersion pkgs.taskwarrior.version))
++ [ "0" ]);
report."brief" = {
columns = [
"id"
"project"
"scheduled"
"due"
"depends"
"description.count"
];
filter = "status:pending project:uni";
labels = [ "ID" "Project" "Scheduled" "Due" "Dep" "Description" ];
sort = [ "priority-/" "project-" "description+" ];
};
terminal.editor = "nvim";
uda.link = {
label = "link";
type = "string";
};
};
dataLocation = config.home-manager.users.${username}.home.homeDirectory
+ "/Documents/tasks";
enable = true;
};
};
programs.git = mkIf cfg.git.enable {
config = {
core.excludesFile = pkgs.writeText "gitignore" ''
.virtfs_metadata
.run
'';
init.defaultBranch = "main";
push.autoSetupRemote = true;
};
enable = true;
};
};
}

View File

@ -1,5 +1,5 @@
{ ... }:
{
imports = [ ./development ./utilities.nix ];
imports = [ ./applications.nix ./development ./utilities ];
}

View File

@ -1,134 +0,0 @@
{ config, inputs, lib, pkgs, ... }:
let project-manager = inputs.project-manager.packages.x86_64-linux.default;
in with lib; {
options.lwad.utilities = {
qol.enable = mkEnableOption "quality-of-life utilities";
remote.enable = mkEnableOption "remote system interaction utilities";
terminal.enable = mkEnableOption "terminal utilities";
};
config = let cfg = config.lwad.utilities;
in {
environment.systemPackages = with pkgs;
flatten [
(optionals cfg.qol.enable [ eza fd fzf jq rename ripgrep watchexec ])
(optionals cfg.remote.enable [ rsync sshfs ])
(optionals cfg.terminal.enable [ project-manager ])
];
programs = {
bash = {
shellAliases = (optionalAttrs cfg.qol.enable
(let eza = "${pkgs.eza}/bin/eza";
in {
eza = "${eza} --long --icons --git";
recent = "${eza} --sort=modified --reverse | head -n 1";
tree = "${eza} --long --icons --git --tree";
})) // (optionalAttrs cfg.terminal.enable {
p = "${project-manager}/bin/project-manager";
});
interactiveShellInit = mkBefore (concatLines (flatten
(let tmux = "${pkgs.tmux}/bin/tmux";
in [
(optional cfg.terminal.enable ''
if [ -z "$TMUX" ]; then
if ! ${tmux} has-session -t "base" 2>/dev/null; then
${tmux} new-session -s "base" -d
fi
${tmux} attach-session -t "base" && exit 0
fi
'')
(optional cfg.qol.enable ''
tell() {
join_by() {
local d=''${1-} f=''${2-}
if shift 2; then
${pkgs.coreutils}/bin/printf %s "$f" "''${@/#/$d}"
fi
}
session_name="$(${tmux} list-clients -t "$TMUX_PANE" -F "#{session_name}" | ${pkgs.coreutils}/bin/head -n 1)"
if eval "$@"; then
icon="data-information"
else
icon="data-error"
fi
${pkgs.dunst}/bin/dunstify -a "longCommand" \
-u normal \
-i "$icon" \
"$session_name" \
"$(join_by " " $@)"
}
complete -F _command tell
g() {
if [ -z "$1" ]
then
nvim -c "G | bd 1"
else
git "$@"
fi
}
source ${pkgs.git}/share/bash-completion/completions/git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main g
'')
])));
};
starship = optionalAttrs cfg.terminal.enable {
enable = true;
settings = {
add_newline = false;
character = {
success_symbol = "[\\$](white)";
error_symbol = "[\\$](#BE2A49)";
};
custom.nest = {
format = " ";
when = let ps = "${pkgs.procps}/bin/ps";
in ''
[[ "$(${ps} -o comm= -p $(${ps} -o ppid= -p $(${ps} -o ppid= -p $(${ps} -o ppid= -p $$))))" != "tmux: server" ]]'';
};
directory = {
home_symbol = "home";
read_only = "";
read_only_style = "#777777";
repo_root_style = "purple";
style = "#777777";
truncation_length = 5;
};
format = ''
''${custom.nest}$directory$git_branch$git_status$nix_shell
$character'';
git_branch = {
format = "[\\($branch\\)]($style)";
ignore_branches = [ "master" "main" ];
style = "purple";
};
git_status = {
format =
"([$conflicted$deleted$renamed$modified$staged$untracked$ahead_behind]($style))";
style = "purple";
};
line_break.disabled = true;
nix_shell = {
format = "$symbol";
heuristic = false;
symbol = "󱄅";
};
};
};
tmux = optionalAttrs cfg.terminal.enable {
enable = true;
escapeTime = 0;
extraConfig = import ./tmux.conf.nix {
inherit (pkgs) btop tmux;
inherit project-manager;
};
keyMode = "vi";
};
};
};
}

View File

@ -0,0 +1,5 @@
{ ... }:
{
imports = [ ./snapshots.nix ./server.nix ];
}

View File

@ -0,0 +1,14 @@
{ config, lib, pkgs, ... }:
with lib; {
options.lwad.utilities.btrbk.server.enable = mkEnableOption "btrbk server";
config = let cfg = config.lwad.utilities.btrbk.server.enable;
in mkIf cfg {
services.btrbk.sshAccess = [{
key = "";
roles = [ "delete" "source" ];
}];
systemd.tmpfiles.rules = [ "v /backups 700 root root" ];
users.users.btrbk.packages = with pkgs; [ mbuffer zstd ];
};
}

View File

@ -0,0 +1,77 @@
{ config, lib, pkgs, ... }:
with lib;
let
snapshotOptions = {
options = {
snapshotDir = mkOption {
description = "The directory to save snapshots to.";
type = types.str;
};
subvolume = mkOption {
description = "The subvolume to snapshot.";
type = types.str;
};
sync = mkOption {
default = { enable = false; };
description = "Server synchronisation options.";
type = types.submodule syncOptions;
};
volume = mkOption {
description = "The volume containing the subvolume.";
type = types.str;
};
};
};
syncOptions = {
options = {
enable = mkEnableOption "server synchronisation";
serverAddress = mkOption {
default = "";
description = "Address of btrbk server to sync to.";
type = types.str;
};
serverBackupDir = mkOption {
default = "DONT LEAVE THIS HERE";
description = "Directory on btrbk server to sync to.";
type = types.str;
};
};
};
in {
options.lwad.utilities.btrbk.snapshots = mkOption {
default = [ ];
description = "Snapshots to take with btrbk.";
type = types.listOf (types.submodule snapshotOptions);
};
config = let cfg = config.lwad.utilities.btrbk.snapshots;
in mkIf (length cfg != 0) {
services.btrbk = {
extraPackages = with pkgs; [ zstd ];
instances.${config.networking.hostName} = {
onCalendar = "daily";
settings = {
send_compressed_data = "yes";
snapshot_preserve = "14d 3m";
snapshot_preserve_min = "2d";
ssh_user = "btrbk";
stream_buffer = "25%";
stream_buffer_remote = "25%";
stream_compress = "zstd";
target_preserve = "3w 3m";
target_preserve_min = "no";
transaction_syslog = "user";
volume = mkMerge (map (entity: {
${entity.volume}.subvolume.${entity.subvolume} = {
snapshot_dir = entity.snapshotDir;
target."ssh://${entity.sync.serverAddress}${entity.sync.serverBackupDir}" =
mkIf entity.sync.enable { };
};
}) cfg);
};
};
};
systemd.services."btrbk-${config.networking.hostName}".restartIfChanged =
false;
};
}

View File

@ -0,0 +1,5 @@
{ ... }:
{
imports = [ ./btrbk ./qol.nix ./remote.nix ./terminal.nix ];
}

64
lwad/utilities/qol.nix Normal file
View File

@ -0,0 +1,64 @@
{ config, lib, pkgs, ... }:
with lib; {
options.lwad.utilities.qol.enable =
mkEnableOption "quality-of-life utilities";
config = let cfg = config.lwad.utilities.qol.enable;
in mkIf cfg {
environment.systemPackages = with pkgs; [
eza
fd
fzf
jq
rename
ripgrep
watchexec
];
programs.bash = {
shellAliases = let eza = "${pkgs.eza}/bin/eza";
in {
eza = "${eza} --long --icons --git";
recent = "${eza} --sort=modified --reverse | head -n 1";
tree = "${eza} --long --icons --git --tree";
};
interactiveShellInit = ''
tell() {
join_by() {
local d=''${1-} f=''${2-}
if shift 2; then
${pkgs.coreutils}/bin/printf %s "$f" "''${@/#/$d}"
fi
}
session_name="$(${pkgs.tmux}/bin/tmux list-clients -t "$TMUX_PANE" -F "#{session_name}" | ${pkgs.coreutils}/bin/head -n 1)"
if eval "$@"; then
icon="data-information"
else
icon="data-error"
fi
${pkgs.dunst}/bin/dunstify -a "longCommand" \
-u normal \
-i "$icon" \
"$session_name" \
"$(join_by " " $@)"
}
complete -F _command tell
g() {
if [ -z "$1" ]
then
nvim -c "G | bd 1"
else
git "$@"
fi
}
source ${pkgs.git}/share/bash-completion/completions/git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main g
'';
};
};
}

View File

@ -0,0 +1,8 @@
{ config, lib, pkgs, ... }:
with lib; {
options.lwad.utilities.remote.enable =
mkEnableOption "remote system interaction utilities";
config = let cfg = config.lwad.utilities.remote.enable;
in mkIf cfg { environment.systemPackages = with pkgs; [ rsync sshfs ]; };
}

View File

@ -0,0 +1,76 @@
{ config, inputs, lib, pkgs, ... }:
let project-manager = inputs.project-manager.packages.x86_64-linux.default;
in with lib; {
options.lwad.utilities.terminal.enable = mkEnableOption "terminal utilities";
config = let cfg = config.lwad.utilities.terminal.enable;
in mkIf cfg {
environment.systemPackages = [ project-manager ];
programs = {
bash = {
shellAliases.p = "${project-manager}/bin/project-manager";
interactiveShellInit = mkBefore (let tmux = "${pkgs.tmux}/bin/tmux";
in ''
if [ -z "$TMUX" ]; then
if ! ${tmux} has-session -t "base" 2>/dev/null; then
${tmux} new-session -s "base" -d
fi
${tmux} attach-session -t "base" && exit 0
fi
'');
};
starship = {
enable = true;
settings = {
add_newline = false;
character = {
success_symbol = "[\\$](white)";
error_symbol = "[\\$](#BE2A49)";
};
custom.nest = {
format = " ";
when = let ps = "${pkgs.procps}/bin/ps";
in ''
[[ "$(${ps} -o comm= -p $(${ps} -o ppid= -p $(${ps} -o ppid= -p $(${ps} -o ppid= -p $$))))" != "tmux: server" ]]'';
};
directory = {
home_symbol = "home";
read_only = "";
read_only_style = "#777777";
repo_root_style = "purple";
style = "#777777";
truncation_length = 5;
};
format = ''
''${custom.nest}$directory$git_branch$git_status$nix_shell
$character'';
git_branch = {
format = "[\\($branch\\)]($style)";
ignore_branches = [ "master" "main" ];
style = "purple";
};
git_status = {
format =
"([$conflicted$deleted$renamed$modified$staged$untracked$ahead_behind]($style))";
style = "purple";
};
line_break.disabled = true;
nix_shell = {
format = "$symbol";
heuristic = false;
symbol = "󱄅";
};
};
};
tmux = {
enable = true;
escapeTime = 0;
extraConfig = import ./tmux.conf.nix {
inherit (pkgs) btop tmux;
inherit project-manager;
};
keyMode = "vi";
};
};
};
}

View File

@ -35,9 +35,18 @@ in {
../components/programs/doas.nix
../components/programs/kmscon.nix
../components/services/mariadb.nix
../components/snapshots/sync-client.nix
../lwad
./hardware-configuration.nix
];
lwad.utilities.btrbk.snapshots = [{
volume = "/";
subvolume = "home/${username}/Documents";
snapshotDir = "home/${username}/snapshots";
sync = {
serverAddress = "shinobu";
serverBackupDir = "/backups";
};
}];
networking = {
hostName = "ryuko";
firewall.interfaces."tailscale0".allowedTCPPorts = [ 8081 ];
@ -59,8 +68,6 @@ in {
};
};
services = {
btrbk.instances.${config.networking.hostName}.settings.volume."/".subvolume."home/${username}/Documents".snapshot_dir =
"home/${username}/snapshots";
logind.extraConfig = ''
HandlePowerKey=ignore
'';

View File

@ -1,4 +1,4 @@
{ inputs, pkgs, ... }:
{ pkgs, ... }:
{
hardware.bluetooth.enable = false;
@ -13,7 +13,9 @@
../components/programs/kmscon.nix
../components/server/ci.nix
../components/server/scc230.nix
../lwad
];
lwad.utilities.btrbk.server.enable = true;
networking.hostName = "shinobu";
nixpkgs.overlays = [
(self: super: {