Compare commits

..

3 Commits

Author SHA1 Message Date
8e829637ac simplify script 2025-07-11 00:11:34 -07:00
5597fd9c3b this is awful i hate it 2025-07-10 23:07:35 -07:00
71d0c3e7e6 caddy: serviceMountDeps 2025-07-10 18:52:33 -07:00
2 changed files with 13 additions and 7 deletions

View File

@@ -138,16 +138,18 @@
serviceMountDeps = serviceName: dirs: pkgs: { serviceMountDeps = serviceName: dirs: pkgs: {
systemd.services."${serviceName}_mounts" = systemd.services."${serviceName}_mounts" =
let let
lib = nixpkgs.lib;
zfslistmounted = pkgs.writeShellApplication { zfslistmounted = pkgs.writeShellApplication {
name = "zfslistmounted"; name = "zfslistmounted";
runtimeInputs = with pkgs; [ runtimeInputs = with pkgs; [
zfs zfs
gnugrep gnugrep
gawk gawk
coreutils
]; ];
text = '' text = ''
#!/bin/sh #!/bin/sh
zfs get mounted | grep yes | awk '{print $1}' | while read -r i; do zfs get mountpoint "$i" | awk 'FNR==2 {print $3}'; done zfs list -o mountpoint,mounted | awk 'FNR > 1 && $2 == "yes" {print $1}' | grep -c '${lib.strings.concatStringsSep "\|" dirs}' | grep -Fq ${toString (lib.length dirs)}
''; '';
}; };
in in
@@ -156,12 +158,7 @@
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
RemainAfterExit = true; RemainAfterExit = true;
ExecStart = ExecStart = nixpkgs.lib.getExe zfslistmounted;
let
lib = nixpkgs.lib;
contains_cmd = "${lib.getExe pkgs.gnugrep} '${lib.strings.concatStringsSep "\|" dirs}' | ${pkgs.coreutils}/bin/wc -l | ${lib.getExe pkgs.gnugrep} -q ${toString (lib.length dirs)}";
in
"${lib.getExe pkgs.bash} -c \"${lib.getExe zfslistmounted} | ${contains_cmd}\"";
}; };
}; };

View File

@@ -3,9 +3,17 @@
service_configs, service_configs,
username, username,
pkgs, pkgs,
serviceMountDeps,
... ...
}: }:
{ {
imports = [
(serviceMountDeps "caddy" [
"/var/lib/caddy"
service_configs.https.data_dir
] pkgs)
];
services.caddy = { services.caddy = {
enable = true; enable = true;
email = "titaniumtown@proton.me"; email = "titaniumtown@proton.me";
@@ -23,6 +31,7 @@
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d ${service_configs.https.data_dir} 750 ${config.services.caddy.user} ${config.services.caddy.group}" "d ${service_configs.https.data_dir} 750 ${config.services.caddy.user} ${config.services.caddy.group}"
"d /var/lib/caddy 750 ${config.services.caddy.user} ${config.services.caddy.group}"
]; ];
systemd.packages = with pkgs; [ nssTools ]; systemd.packages = with pkgs; [ nssTools ];