76 lines
2.3 KiB
Nix
76 lines
2.3 KiB
Nix
{
|
|
self,
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}: {
|
|
config = {
|
|
facter.reportPath = ./facter.json;
|
|
system.stateVersion = "23.05";
|
|
users.users.root.openssh.authorizedKeys.keys = config.pim.ssh.keys.pim ++ config.pim.ssh.keys.niels;
|
|
sops.defaultSopsFile = "${self}/secrets/lewis/nixos.yaml";
|
|
environment.systemPackages = [pkgs.beets];
|
|
|
|
deployment = {
|
|
targetHost = "lewis";
|
|
targetUser = "root";
|
|
tags = ["server" "kubernetes"];
|
|
};
|
|
|
|
pim = {
|
|
k3s.serverAddr = "https://jefke.dmz:6443";
|
|
data-sharing.enable = true;
|
|
backups.enable = true;
|
|
};
|
|
|
|
systemd = {
|
|
timers.read-dir-sizes = {
|
|
wantedBy = ["timers.target"];
|
|
timerConfig = {
|
|
OnBootSec = "5m";
|
|
OnUnitActiveSec = "5m";
|
|
Unit = "read-dir-sizes.service";
|
|
};
|
|
};
|
|
|
|
services."read-dir-sizes" = {
|
|
script = let
|
|
script = pkgs.writeShellScriptBin "read-dir-sizes.sh" ''
|
|
DIRS=(
|
|
"/mnt/longhorn/persistent/media/movies"
|
|
"/mnt/longhorn/persistent/media/shows"
|
|
)
|
|
|
|
temp_file=$(mktemp)
|
|
trap 'rm -f "$temp_file"' EXIT
|
|
|
|
for DIR_PATH in "''${DIRS[@]}"; do
|
|
# Find all top-level subdirectories and calculate their size
|
|
find "$DIR_PATH" -mindepth 1 -maxdepth 1 -type d | while read -r subdir; do
|
|
# Calculate the size of the top-level subdirectory
|
|
du --block-size=1 -s "$subdir" | while read -r size path; do
|
|
# Print size in Prometheus format
|
|
echo "directory_size_bytes{dir=\"$path\"} $size" >> $temp_file
|
|
done
|
|
done
|
|
done
|
|
mkdir -p /var/lib/node_exporter/textfile_collector
|
|
cp $temp_file /var/lib/node_exporter/textfile_collector/dir_sizes.prom
|
|
chmod o=r /var/lib/node_exporter/textfile_collector/dir_sizes.prom
|
|
'';
|
|
in "${lib.getExe script}";
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = "root";
|
|
};
|
|
};
|
|
|
|
tmpfiles.rules = [
|
|
"d /mnt/longhorn/persistent/media/torrents 775 414 51 8d"
|
|
];
|
|
};
|
|
|
|
services.prometheus.exporters.node.extraFlags = ["--collector.textfile.directory=/var/lib/node_exporter/textfile_collector"];
|
|
};
|
|
}
|