]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/system/quatresaisons.nix
Fix converse
[perso/Immae/Config/Nix.git] / modules / private / system / quatresaisons.nix
index 491e215eb180e18d7925dc84245e090203ca338e..ed6f12904cddac077cfea25f89cadfb06e96e327 100644 (file)
@@ -28,6 +28,45 @@ let
     '';
   };
   normalUsers = serverSpecificConfig.users;
+  userquotas = pkgs.writeScriptBin "user_quotas" ''
+    #!/usr/bin/env bash
+    set -euo pipefail
+
+    if [ `whoami` != "root" ]; then
+      list=$(id -u)
+    else
+      list="${builtins.concatStringsSep " " (lib.mapAttrsToList (n: v: builtins.toString v.uid) normalUsers)}"
+    fi
+
+    get_size () {
+      user=$1
+      home=$((du -sbx /home/$user 2>/dev/null | cut -d"        " -f1) || echo 0)
+      nextcloud=$((du -sbx /home/var_lib/nextcloud/data/$user 2>/dev/null | cut -d"    " -f1) || echo 0)
+      echo "Home: $(numfmt --to=iec "$home")"
+      echo "Nextcloud: $(numfmt --to=iec "$nextcloud")"
+      echo "Raw: $(($home + $nextcloud))"
+    }
+
+    for user in $list; do
+      group=$(id -ng "$user")
+      size=$(get_size "$group")
+      total=$(echo "$size" | grep ^Raw | cut -d" " -f2)
+      decomp="    $group: $(numfmt --to=iec "$total")"
+      decomp="$decomp;$(echo "$size" | grep -v ^Raw | sed -e "s/^/        /")"
+
+      sponsored=$(getent group $group | cut -d':' -f4)
+      IFS=","
+      for subuser in $sponsored; do
+        size=$(get_size "$subuser")
+        totalsub=$(echo "$size" | grep ^Raw | cut -d" " -f2)
+        total=$(($total + $totalsub))
+        decomp="$decomp;    $subuser: $(numfmt --to=iec "$totalsub")"
+        decomp="$decomp;$(echo "$size" | grep -v ^Raw | sed -e "s/^/        /")"
+      done
+      echo "$group: $(numfmt --to=iec "$total")"
+      echo "$decomp" | tr ";" "\n"
+    done
+  '';
   sponsoredUser = pkgs.writeScriptBin "sponsored_user" ''
     #!/usr/bin/env bash
 
@@ -160,7 +199,7 @@ in
 {
   deployment = {
     targetUser = "root";
-    targetHost = config.hostEnv.ips.main.ip4;
+    targetHost = lib.head config.hostEnv.ips.main.ip4;
     substituteOnDestination = true;
   };
   # ssh-keyscan quatresaison | nix-shell -p ssh-to-age --run ssh-to-age
@@ -254,14 +293,12 @@ in
     '';
   };
 
-  secrets.keys = [
-    {
-      dest = "ldap/sync_password";
+  secrets.keys = {
+    "ldap/sync_password" = {
       permissions = "0400";
       text = serverSpecificConfig.ldap_sync_password;
-    }
-    {
-      dest = "ldap/ldaptree.ldif";
+    };
+    "ldap/ldaptree.ldif" = {
       permissions = "0400";
       text = serverSpecificConfig.ldap_service_users
         + (builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: v: ''
@@ -272,8 +309,8 @@ in
         sn: ${n}
         uid: ${n}
       '') normalUsers));
-    }
-  ];
+    };
+  };
 
   myServices.monitoring.enable = true;
   myServices.certificates.enable = true;
@@ -343,10 +380,10 @@ in
   ];
 
   environment.systemPackages = [
-    sponsoredUser
+    sponsoredUser userquotas
     pkgs.git pkgs.vim pkgs.rsync pkgs.strace pkgs.home-manager
-    pkgs.telnet pkgs.htop pkgs.iftop pkgs.bind.dnsutils pkgs.httpie
-    pkgs.iotop pkgs.whois pkgs.ngrep pkgs.tcpdump pkgs.tshark
+    pkgs.inetutils pkgs.htop pkgs.iftop pkgs.bind.dnsutils pkgs.httpie
+    pkgs.iotop pkgs.whois pkgs.ngrep pkgs.tcpdump pkgs.wireshark-cli
     pkgs.tcpflow pkgs.nmap pkgs.p0f pkgs.socat pkgs.lsof pkgs.psmisc
     pkgs.openssl pkgs.wget pkgs.pv pkgs.smartmontools pkgs.youtube-dl
     pkgs.unzip pkgs.octave pkgs.feh pkgs.xv pkgs.sshfs pkgs.gdb
@@ -370,7 +407,7 @@ in
       '' ];
     ips =
       let ips = config.hostEnv.ips.main;
-      in [ips.ip4] ++ (ips.ip6 or []);
+      in (ips.ip4 or []) ++ (ips.ip6 or []);
 
     fallbackVhost = {
       certName    = "quatresaisons";