diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-06-01 19:25:59 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-06-01 19:26:13 +0530 |
commit | 8febb2fad131dc1ff42a2c667b26b013d64c17b8 (patch) | |
tree | cf33b3a20def6ab7836a037b5195cc617647fa9c /os/fscusat/modules/mirror | |
parent | 5c48d5ad41221dbfa186701ba40404bd2571c242 (diff) |
repo: ./nixos -> ./os
Diffstat (limited to 'os/fscusat/modules/mirror')
-rw-r--r-- | os/fscusat/modules/mirror/debian/default.nix | 22 | ||||
-rw-r--r-- | os/fscusat/modules/mirror/debian/ftpsync.nix | 65 | ||||
-rw-r--r-- | os/fscusat/modules/mirror/default.nix | 11 | ||||
-rw-r--r-- | os/fscusat/modules/mirror/www.nix | 11 |
4 files changed, 109 insertions, 0 deletions
diff --git a/os/fscusat/modules/mirror/debian/default.nix b/os/fscusat/modules/mirror/debian/default.nix new file mode 100644 index 0000000..c052bdd --- /dev/null +++ b/os/fscusat/modules/mirror/debian/default.nix @@ -0,0 +1,22 @@ +{ config, ... }: let + name = config.userdata.name; + email = config.userdata.email; +in { + imports = [ ./ftpsync.nix ]; + + services.ftpsync = { + enable = true; + + settings = { + RSYNC_HOST = "ossmirror.mycloud.services"; + RSYNC_PATH = "debian"; + ARCH_INCLUDE = "amd64 riscv64"; + + INFO_MAINTAINER = "${name} <${email}>"; + INFO_COUNTRY = "IN"; + INFO_LOCATION = "Kochi, Kerala"; + INFO_THROUGHPUT = "1Gb"; + MAILTO = email; + }; + }; +} diff --git a/os/fscusat/modules/mirror/debian/ftpsync.nix b/os/fscusat/modules/mirror/debian/ftpsync.nix new file mode 100644 index 0000000..29fb55b --- /dev/null +++ b/os/fscusat/modules/mirror/debian/ftpsync.nix @@ -0,0 +1,65 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.services.ftpsync; + archvsync = pkgs.callPackage ../../../pkgs/archvsync {}; + + formatKeyValue = k: v: '' ${k}="${v}" ''; + configFormat = pkgs.formats.keyValue { mkKeyValue = formatKeyValue; }; + configFile = configFormat.generate "ftpsync.conf" cfg.settings; +in +{ + meta.maintainers = with lib.maintainers; [ sinanmohd ]; + + options.services.ftpsync = { + enable = lib.mkEnableOption (lib.mdDoc "ftpsync"); + + settings = lib.mkOption { + inherit (configFormat) type; + default = {}; + description = lib.mdDoc '' + Configuration options for ftpsync. + See ftpsync.conf(5) man page for available options. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + environment.etc."ftpsync/ftpsync.conf".source = configFile; + environment.systemPackages = [ archvsync ]; + + services.ftpsync.settings = { + TO = lib.mkDefault "$STATE_DIRECTORY"; + LOGDIR = lib.mkDefault "$LOGS_DIRECTORY"; + }; + + systemd = let + name = "ftpsync"; + meta = { + description = "Mirror Debian repositories of packages"; + documentation = [ "man:ftpsync(1)" ]; + }; + in { + timers.${name} = meta // { + wantedBy = [ "timers.target" ]; + + timerConfig = { + OnCalendar = "*-*-* 00,06,12,18:00:00"; + Unit="%i.service"; + Persistent = true; + FixedRandomDelay = true; + RandomizedDelaySec = "6h"; + }; + }; + + services.${name} = meta // { + serviceConfig = { + LogsDirectory = name; + StateDirectory = name; + + ExecStart = "${archvsync}/bin/ftpsync sync:all"; + }; + }; + }; + }; +} diff --git a/os/fscusat/modules/mirror/default.nix b/os/fscusat/modules/mirror/default.nix new file mode 100644 index 0000000..c5fd462 --- /dev/null +++ b/os/fscusat/modules/mirror/default.nix @@ -0,0 +1,11 @@ +{ ... }: { + imports = [ + ./debian + ./www.nix + ]; + + systemd.tmpfiles.rules = [ + "d /var/cache/mirror/ 0755 root root" + "L /var/cache/mirror/debian - - - - /var/lib/ftpsync/" + ]; +} diff --git a/os/fscusat/modules/mirror/www.nix b/os/fscusat/modules/mirror/www.nix new file mode 100644 index 0000000..ebde425 --- /dev/null +++ b/os/fscusat/modules/mirror/www.nix @@ -0,0 +1,11 @@ +{ ... }: + +let + domain = "foss.fscusat.ac.in"; +in +{ + services.nginx.virtualHosts.${domain}.locations."/mirror/" = { + alias = "/var/cache/mirror/"; + extraConfig = "autoindex on;"; + }; +} |