2025-11-16 01:07:55 -06:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
flake,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
inherit (flake.config.people) user0;
|
|
|
|
|
inherit (flake.config.services) instances;
|
|
|
|
|
serviceCfg = instances.opencloud;
|
|
|
|
|
hostCfg = instances.web;
|
|
|
|
|
dns = instances.web.dns.provider1;
|
|
|
|
|
localhost = instances.web.localhost.address1;
|
|
|
|
|
host = "${serviceCfg.subdomain}.${flake.inputs.linkpage.secrets.domains.projectsite}";
|
|
|
|
|
dnsPath = "dns/${dns}";
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
microvm.vms = {
|
|
|
|
|
projectcloud = {
|
|
|
|
|
autostart = true;
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
config = {
|
|
|
|
|
system.stateVersion = "24.05";
|
|
|
|
|
time.timeZone = "America/Winnipeg";
|
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
|
|
|
|
|
services = {
|
|
|
|
|
opencloud = {
|
|
|
|
|
enable = true;
|
|
|
|
|
url = "https://${host}";
|
|
|
|
|
port = serviceCfg.ports.port0;
|
|
|
|
|
address = localhost;
|
|
|
|
|
stateDir = "/var/lib/${serviceCfg.name}";
|
2025-11-30 16:32:34 -06:00
|
|
|
environmentFile = "/etc/opencloud-secrets/env";
|
2025-11-16 01:07:55 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
openssh = {
|
|
|
|
|
enable = true;
|
|
|
|
|
settings = {
|
|
|
|
|
PasswordAuthentication = false;
|
|
|
|
|
PermitRootLogin = "prohibit-password";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
|
22 # SSH
|
|
|
|
|
587 # SMTP
|
|
|
|
|
serviceCfg.ports.port0
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
|
services = {
|
|
|
|
|
opencloud = {
|
|
|
|
|
path = [ pkgs.inotify-tools ];
|
|
|
|
|
};
|
2025-11-30 17:13:44 -06:00
|
|
|
systemd.services.opencloud-copy-secrets = {
|
2025-11-30 16:32:34 -06:00
|
|
|
description = "Copy secrets from virtiofs to local filesystem";
|
2025-11-30 17:13:44 -06:00
|
|
|
before = [
|
|
|
|
|
"opencloud-init-config.service"
|
|
|
|
|
"opencloud.service"
|
|
|
|
|
];
|
2025-11-30 17:04:02 -06:00
|
|
|
requiredBy = [ "opencloud.service" ];
|
2025-11-30 17:13:44 -06:00
|
|
|
after = [ "run-secrets.mount" ];
|
2025-11-30 16:32:34 -06:00
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
RemainAfterExit = true;
|
|
|
|
|
};
|
|
|
|
|
script = ''
|
2025-11-30 17:13:44 -06:00
|
|
|
set -e
|
|
|
|
|
echo "Checking for secrets..."
|
|
|
|
|
|
|
|
|
|
if [ ! -f /run/secrets/projectenv ]; then
|
|
|
|
|
echo "ERROR: /run/secrets/projectenv not found!"
|
|
|
|
|
ls -la /run/secrets/ || true
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Copying secrets..."
|
2025-11-30 16:32:34 -06:00
|
|
|
mkdir -p /etc/opencloud-secrets
|
2025-11-30 17:13:44 -06:00
|
|
|
cp -v /run/secrets/projectenv /etc/opencloud-secrets/env
|
2025-11-30 16:32:34 -06:00
|
|
|
chmod 755 /etc/opencloud-secrets
|
|
|
|
|
chmod 644 /etc/opencloud-secrets/*
|
2025-11-30 17:13:44 -06:00
|
|
|
|
|
|
|
|
echo "Secrets copied successfully"
|
|
|
|
|
cat /etc/opencloud-secrets/env
|
2025-11-30 16:32:34 -06:00
|
|
|
'';
|
|
|
|
|
};
|
2025-11-16 01:07:55 -06:00
|
|
|
};
|
|
|
|
|
network = {
|
|
|
|
|
enable = true;
|
|
|
|
|
networks."20-lan" = {
|
|
|
|
|
matchConfig.Name = "enp0s5";
|
|
|
|
|
addresses = [
|
|
|
|
|
{ Address = "${serviceCfg.interface.ip}/24"; }
|
|
|
|
|
];
|
|
|
|
|
routes = [
|
|
|
|
|
{
|
|
|
|
|
Destination = "${hostCfg.localhost.address1}/0";
|
|
|
|
|
Gateway = serviceCfg.interface.gate;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
dns = [
|
|
|
|
|
"1.1.1.1"
|
|
|
|
|
"8.8.8.8"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tmpfiles.rules = [
|
2025-11-30 14:57:21 -06:00
|
|
|
"d ${serviceCfg.varPaths.path0} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
|
2025-11-30 17:12:26 -06:00
|
|
|
"z /etc/opencloud 0700 ${serviceCfg.name} ${serviceCfg.name} -"
|
|
|
|
|
# "L+ /etc/opencloud/proxy.yaml - - - - /etc/static/opencloud/proxy.yaml"
|
2025-11-16 01:07:55 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-networkd.wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
microvm = {
|
2025-11-30 14:57:21 -06:00
|
|
|
vcpu = 1;
|
|
|
|
|
mem = 1024 * 1;
|
2025-11-16 01:07:55 -06:00
|
|
|
hypervisor = "qemu";
|
|
|
|
|
interfaces = [
|
|
|
|
|
{
|
|
|
|
|
type = "tap";
|
|
|
|
|
id = serviceCfg.interface.id;
|
|
|
|
|
mac = serviceCfg.interface.mac;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
type = "user";
|
|
|
|
|
id = serviceCfg.interface.idUser;
|
|
|
|
|
mac = serviceCfg.interface.macUser;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
forwardPorts = [
|
|
|
|
|
{
|
|
|
|
|
from = "host";
|
|
|
|
|
host.port = serviceCfg.interface.ssh;
|
|
|
|
|
guest.port = 22;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
shares = [
|
|
|
|
|
{
|
|
|
|
|
mountPoint = "/nix/.ro-store";
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "/nix/store";
|
|
|
|
|
tag = "read_only_nix_store";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
mountPoint = "/var/lib/${serviceCfg.name}";
|
|
|
|
|
proto = "virtiofs";
|
2025-11-30 14:57:21 -06:00
|
|
|
source = "${serviceCfg.mntPaths.path0}/data";
|
2025-11-16 01:07:55 -06:00
|
|
|
tag = "${serviceCfg.name}_data";
|
|
|
|
|
}
|
2025-11-30 14:57:21 -06:00
|
|
|
{
|
|
|
|
|
mountPoint = "/etc/opencloud";
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/config";
|
|
|
|
|
tag = "${serviceCfg.name}_config";
|
|
|
|
|
}
|
2025-11-16 01:07:55 -06:00
|
|
|
{
|
|
|
|
|
mountPoint = "/run/secrets";
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "/run/secrets/${serviceCfg.name}";
|
|
|
|
|
tag = "host_secrets";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
};
|
2025-11-27 05:12:15 -06:00
|
|
|
environment.systemPackages = builtins.attrValues {
|
|
|
|
|
inherit (pkgs)
|
|
|
|
|
yazi
|
|
|
|
|
bottom
|
|
|
|
|
trashy
|
|
|
|
|
fastfetch
|
2025-11-30 14:57:21 -06:00
|
|
|
opencloud
|
2025-11-27 05:12:15 -06:00
|
|
|
;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-16 01:07:55 -06:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
security.acme.certs."${host}" = {
|
|
|
|
|
dnsProvider = dns;
|
|
|
|
|
environmentFile = config.sops.secrets.${dnsPath}.path;
|
|
|
|
|
group = "caddy";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.caddy.virtualHosts = {
|
|
|
|
|
"${host}" = {
|
2025-11-30 16:59:47 -06:00
|
|
|
extraConfig =
|
|
|
|
|
let
|
|
|
|
|
credPath = "/var/lib/acme/${host}";
|
|
|
|
|
in
|
|
|
|
|
''
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
tls ${credPath}/fullchain.pem ${credPath}/key.pem
|
|
|
|
|
'';
|
2025-11-16 01:07:55 -06:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users.users.caddy.extraGroups = [ "acme" ];
|
|
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
|
tmpfiles.rules = [
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0} 0751 microvm wheel - -"
|
2025-11-30 16:18:57 -06:00
|
|
|
"d ${serviceCfg.mntPaths.path0}/data 0751 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/config 0751 microvm wheel - -"
|
2025-11-16 01:07:55 -06:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sops.secrets = {
|
|
|
|
|
"${serviceCfg.name}/projectenv" = {
|
|
|
|
|
owner = "root";
|
|
|
|
|
mode = "0600";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|