From bf12a289b2e4c8f22d1be781408a6d1273fd3b04 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 17 Feb 2024 18:31:41 +0530 Subject: fscusat/modules/mirror: init --- hosts/fscusat/configuration.nix | 2 +- hosts/fscusat/modules/ftpsync/default.nix | 21 -------- hosts/fscusat/modules/ftpsync/ftpsync.nix | 66 ------------------------- hosts/fscusat/modules/mirror/debian/default.nix | 22 +++++++++ hosts/fscusat/modules/mirror/debian/ftpsync.nix | 65 ++++++++++++++++++++++++ hosts/fscusat/modules/mirror/default.nix | 11 +++++ hosts/fscusat/modules/mirror/www.nix | 11 +++++ hosts/fscusat/modules/www.nix | 5 +- 8 files changed, 111 insertions(+), 92 deletions(-) delete mode 100644 hosts/fscusat/modules/ftpsync/default.nix delete mode 100644 hosts/fscusat/modules/ftpsync/ftpsync.nix create mode 100644 hosts/fscusat/modules/mirror/debian/default.nix create mode 100644 hosts/fscusat/modules/mirror/debian/ftpsync.nix create mode 100644 hosts/fscusat/modules/mirror/default.nix create mode 100644 hosts/fscusat/modules/mirror/www.nix diff --git a/hosts/fscusat/configuration.nix b/hosts/fscusat/configuration.nix index 72e8e04..779f0ec 100644 --- a/hosts/fscusat/configuration.nix +++ b/hosts/fscusat/configuration.nix @@ -5,7 +5,7 @@ ./hardware-configuration.nix ./modules/network.nix ./modules/www.nix - ./modules/ftpsync + ./modules/mirror ../../common.nix ]; diff --git a/hosts/fscusat/modules/ftpsync/default.nix b/hosts/fscusat/modules/ftpsync/default.nix deleted file mode 100644 index aa214ac..0000000 --- a/hosts/fscusat/modules/ftpsync/default.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ config, ... }: let - name = config.userdata.user; - 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"; - }; - }; -} diff --git a/hosts/fscusat/modules/ftpsync/ftpsync.nix b/hosts/fscusat/modules/ftpsync/ftpsync.nix deleted file mode 100644 index 8c1d170..0000000 --- a/hosts/fscusat/modules/ftpsync/ftpsync.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ 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 = { - DynamicUser = true; - LogsDirectory = name; - StateDirectory = name; - - ExecStart = "${archvsync}/bin/ftpsync sync:all"; - }; - }; - }; - }; -} diff --git a/hosts/fscusat/modules/mirror/debian/default.nix b/hosts/fscusat/modules/mirror/debian/default.nix new file mode 100644 index 0000000..da56ade --- /dev/null +++ b/hosts/fscusat/modules/mirror/debian/default.nix @@ -0,0 +1,22 @@ +{ config, ... }: let + name = config.userdata.user; + 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/hosts/fscusat/modules/mirror/debian/ftpsync.nix b/hosts/fscusat/modules/mirror/debian/ftpsync.nix new file mode 100644 index 0000000..29fb55b --- /dev/null +++ b/hosts/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/hosts/fscusat/modules/mirror/default.nix b/hosts/fscusat/modules/mirror/default.nix new file mode 100644 index 0000000..c5fd462 --- /dev/null +++ b/hosts/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/hosts/fscusat/modules/mirror/www.nix b/hosts/fscusat/modules/mirror/www.nix new file mode 100644 index 0000000..ebde425 --- /dev/null +++ b/hosts/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;"; + }; +} diff --git a/hosts/fscusat/modules/www.nix b/hosts/fscusat/modules/www.nix index 464aaa6..24398da 100644 --- a/hosts/fscusat/modules/www.nix +++ b/hosts/fscusat/modules/www.nix @@ -30,10 +30,7 @@ in sslCertificateKey = config.sops.secrets."cusat.ac.in/key".path; sslCertificate = config.sops.secrets."cusat.ac.in/crt".path; - locations."/" = { - return = "200 '

under construction

'"; - extraConfig = "add_header Content-Type text/html;"; - }; + locations."/".extraConfig = "return 307 $scheme://$host/mirror/;"; }; }; } -- cgit v1.2.3