selfprivacy-nixos-config/files.nix

63 lines
2.8 KiB
Nix
Raw Normal View History

2021-11-15 10:02:05 +00:00
{ config, pkgs, ... }:
let
cfg = config.services.userdata;
in
{
systemd.tmpfiles.rules =
let
2022-06-09 19:52:54 +00:00
domain = builtins.replaceStrings [ "\n" "\"" "\\" "%" ] [ "\\n" "\\\"" "\\\\" "%%" ] cfg.domain;
2021-11-15 10:02:05 +00:00
in
[
2022-05-02 08:04:02 +00:00
(if cfg.bitwarden.enable then "d /var/lib/bitwarden 0777 vaultwarden vaultwarden -" else "")
(if cfg.bitwarden.enable then "d /var/lib/bitwarden/backup 0777 vaultwarden vaultwarden -" else "")
2021-12-16 13:51:43 +00:00
(if cfg.pleroma.enable then "d /var/lib/pleroma 0700 pleroma pleroma - -" else "")
"d /var/lib/restic 0600 restic - - -"
2021-12-16 13:51:43 +00:00
(if cfg.pleroma.enable then "f /var/lib/pleroma/secrets.exs 0755 pleroma pleroma - -" else "")
"f+ /var/domain 0444 selfprivacy-api selfprivacy-api - ${domain}"
2021-11-15 10:02:05 +00:00
];
2022-07-13 15:10:06 +00:00
system.activationScripts = let
jq = "${pkgs.jq}/bin/jq";
2022-07-13 15:12:34 +00:00
sed = "${pkgs.gnused}/bin/sed";
2022-07-13 15:10:06 +00:00
in
{
2022-07-13 15:06:16 +00:00
nextcloudSecrets =
if cfg.nextcloud.enable then ''
2022-07-13 15:10:06 +00:00
cat /etc/nixos/userdata/userdata.json | ${jq} -r '.nextcloud.databasePassword' > /var/lib/nextcloud/db-pass
2022-07-13 15:06:16 +00:00
chmod 0440 /var/lib/nextcloud/db-pass
chown nextcloud:nextcloud /var/lib/nextcloud/db-pass
2022-07-13 15:10:06 +00:00
cat /etc/nixos/userdata/userdata.json | ${jq} -r '.nextcloud.adminPassword' > /var/lib/nextcloud/admin-pass
2022-07-13 15:06:16 +00:00
chmod 0440 /var/lib/nextcloud/admin-pass
chown nextcloud:nextcloud /var/lib/nextcloud/admin-pass
''
else ''
rm /var/lib/nextcloud/db-pass
rm /var/lib/nextcloud/admin-pass
'';
cloudflareCredentials = ''
echo 'CF_API_KEY=REPLACEME' > /var/lib/cloudflare/Credentials.ini
echo 'CLOUDFLARE_DNS_API_TOKEN=REPLACEME' >> /var/lib/cloudflare/Credentials.ini
echo 'CLOUDFLARE_ZONE_API_TOKEN=REPLACEME' >> /var/lib/cloudflare/Credentials.ini
2022-07-13 15:10:06 +00:00
${sed} -i "s/REPLACEME/$(cat /etc/nixos/userdata/userdata.json | ${jq} -r '.cloudflare.apiKey')/g" /var/lib/cloudflare/Credentials.ini
2022-07-13 15:06:16 +00:00
chmod 0440 /var/lib/cloudflare/Credentials.ini
chown nginx:acmerecievers /var/lib/cloudflare/Credentials.ini
'';
resticCredentials = ''
echo '[backblaze]' > /root/.config/rclone/rclone.conf
echo 'type = b2' >> /root/.config/rclone/rclone.conf
echo 'account = REPLACEME1' >> /root/.config/rclone/rclone.conf
echo 'key = REPLACEME2' >> /root/.config/rclone/rclone.conf
2022-07-13 15:10:06 +00:00
${sed} -i "s/REPLACEME1/$(cat /etc/nixos/userdata/userdata.json | ${jq} -r '.backblaze.accountId')/g" /root/.config/rclone/rclone.conf
${sed} -i "s/REPLACEME2/$(cat /etc/nixos/userdata/userdata.json | ${jq} -r '.backblaze.accountKey')/g" /root/.config/rclone/rclone.conf
2022-07-13 15:06:16 +00:00
chmod 0400 /root/.config/rclone/rclone.conf
chown root:root /root/.config/rclone/rclone.conf
2022-07-13 15:16:02 +00:00
cat /etc/nixos/userdata/userdata.json | ${jq} -r '.resticPassword' > /var/lib/restic/pass
2022-07-13 15:06:16 +00:00
chmod 0400 /var/lib/restic/pass
chown restic /var/lib/restic/pass
'';
};
2021-11-15 10:02:05 +00:00
}