2023-05-11 05:33:08 +07:00
|
|
|
{ config
|
|
|
|
, pkgs
|
|
|
|
, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.server;
|
|
|
|
in {
|
2023-05-17 06:29:03 +07:00
|
|
|
impermanence.directories = [
|
|
|
|
{ directory = /var/lib/fdroid; user = "fdroid"; group = "fdroid"; mode = "0755"; }
|
|
|
|
];
|
2023-07-28 09:59:47 +07:00
|
|
|
services.nginx.virtualHosts."fdroid.${cfg.domainName}" = {
|
|
|
|
quic = true;
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
globalRedirect = cfg.domainName;
|
|
|
|
locations."/repo/".alias = "/var/lib/fdroid/repo/";
|
|
|
|
};
|
2023-05-11 05:33:08 +07:00
|
|
|
services.nginx.virtualHosts."${cfg.domainName}" = {
|
|
|
|
locations."/fdroid/".alias = "/var/lib/fdroid/repo/";
|
2023-07-12 03:26:50 +07:00
|
|
|
locations."/fdroid/repo/".alias = "/var/lib/fdroid/repo/";
|
2023-05-11 05:33:08 +07:00
|
|
|
};
|
|
|
|
users.users.fdroid = {
|
|
|
|
home = "/var/lib/fdroid";
|
|
|
|
group = "fdroid";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
users.groups.fdroid = { };
|
|
|
|
systemd.timers.update-fdroid = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
partOf = [ "update-fdroid.service" ];
|
|
|
|
# slightly unusual time to reduce server load
|
|
|
|
timerConfig.OnCalendar = [ "*-*-* 00:40:00" ]; # every day
|
|
|
|
};
|
|
|
|
systemd.services.update-fdroid = {
|
|
|
|
serviceConfig = let
|
|
|
|
inherit (pkgs) fdroidserver;
|
|
|
|
fdroidScript = pkgs.writeText "update-froid.py" ''
|
2023-07-12 03:26:50 +07:00
|
|
|
import requests, subprocess, os, shutil, sys
|
2023-05-11 05:33:08 +07:00
|
|
|
|
|
|
|
x = requests.get('https://api.github.com/repos/ppy/osu/releases').json()
|
|
|
|
|
|
|
|
for q in x:
|
|
|
|
for w in q.get('assets', []):
|
|
|
|
if w.get('name', "").endswith('.apk'):
|
|
|
|
os.chdir('/var/lib/fdroid')
|
|
|
|
subprocess.run(['${pkgs.wget}/bin/wget', w['browser_download_url'], '-O', '/var/tmp/lazer.apk'], check=True)
|
2023-07-12 03:26:50 +07:00
|
|
|
shutil.move('/var/tmp/lazer.apk', '/var/lib/fdroid/repo/sh.ppy.osulazer.apk.tmp')
|
|
|
|
os.rename('/var/lib/fdroid/repo/sh.ppy.osulazer.apk.tmp', '/var/lib/fdroid/repo/sh.ppy.osulazer.apk')
|
|
|
|
subprocess.run(['${fdroidserver}/bin/fdroid', 'update', '--allow-disabled-algorithms'], check=True)
|
2023-05-11 05:33:08 +07:00
|
|
|
sys.exit()
|
|
|
|
'';
|
|
|
|
fdroidPython = pkgs.python3.withPackages (p: with p; [ requests ]);
|
|
|
|
in {
|
|
|
|
Type = "oneshot";
|
2023-07-12 03:26:50 +07:00
|
|
|
ExecStart = "${fdroidPython}/bin/python3 ${fdroidScript}";
|
2023-05-11 05:33:08 +07:00
|
|
|
};
|
|
|
|
environment.JAVA_HOME = "${pkgs.jdk11_headless}";
|
|
|
|
path = [ pkgs.jdk11_headless ];
|
|
|
|
};
|
|
|
|
}
|