test: setting up opencloud and microvms

This commit is contained in:
Nick 2025-12-05 02:47:08 -06:00
parent 97aebfbb59
commit 9ab5ebd35f
8 changed files with 81 additions and 122 deletions

View file

@ -1,5 +1,4 @@
{
config,
flake,
pkgs,
...
@ -9,10 +8,8 @@ let
inherit (flake.config.services) instances;
serviceCfg = instances.opencloud0;
hostCfg = instances.web;
dns = instances.web.dns.provider0;
localhost = instances.web.localhost.address1;
host = serviceCfg.domains.url0;
dnsPath = "dns/${dns}";
in
{
microvm.vms = {
@ -55,17 +52,28 @@ in
path = [ pkgs.inotify-tools ];
};
opencloud-fix-permissions = {
description = "Fix OpenCloud storage permissions on file changes";
description = "Fix OpenCloud storage permissions";
after = [ "opencloud.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = pkgs.writeShellScript "fix-perms-on-change" ''
${pkgs.inotify-tools}/bin/inotifywait -m -r -e create,moved_to /var/lib/opencloud/storage --format '%w%f' | while read filepath; do
${pkgs.coreutils}/bin/chown opencloud:opencloud "$filepath"
Type = "oneshot";
ExecStart = pkgs.writeShellScript "fix-perms" ''
echo "Starting permission fix..."
OPENCLOUD_UID=$(id -u opencloud)
echo "OpenCloud UID: $OPENCLOUD_UID"
find /var/lib/opencloud/storage/users -type f ! -uid "$OPENCLOUD_UID" 2>/dev/null | while read -r file; do
echo "Fixing file: $file"
chown opencloud:opencloud "$file" 2>/dev/null || true
done
find /var/lib/opencloud/storage/users -type d ! -uid "$OPENCLOUD_UID" 2>/dev/null | while read -r dir; do
echo "Fixing dir: $dir"
chown opencloud:opencloud "$dir" 2>/dev/null || true
done
echo "Permission fix complete"
'';
Restart = "always";
User = "root";
};
};
@ -74,7 +82,7 @@ in
description = "Periodically fix OpenCloud storage permissions";
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "1min";
OnBootSec = "30s";
OnUnitActiveSec = "1min";
Unit = "opencloud-fix-permissions.service";
};
@ -158,6 +166,7 @@ in
};
environment.systemPackages = builtins.attrValues {
inherit (pkgs)
inotify-tools
opencloud
;
};
@ -165,28 +174,6 @@ in
};
};
# security.acme.certs."${host}" = {
# dnsProvider = dns;
# environmentFile = config.sops.secrets.${dnsPath}.path;
# group = "caddy";
# };
services.caddy.virtualHosts = {
"${host}" = {
extraConfig = ''
reverse_proxy ${serviceCfg.interface.ip}:${toString serviceCfg.ports.port0} {
header_up X-Real-IP {remote_host}
}
redir /.well-known/carddav /remote.php/dav/ 301
redir /.well-known/caldav /remote.php/dav/ 301
'';
};
};
users.users.caddy.extraGroups = [ "acme" ];
systemd = {
tmpfiles.rules = [
"d ${serviceCfg.mntPaths.path0} 0751 microvm wheel - -"