From 60ed7bde534f23be9e3ee5429f72cf63ac8bfff2 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 17 Feb 2024 12:21:58 +0530 Subject: fscusat/modules/ftpsync: init --- hosts/fscusat/modules/ftpsync/default.nix | 21 ++++++++++ hosts/fscusat/modules/ftpsync/ftpsync.nix | 66 +++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 hosts/fscusat/modules/ftpsync/default.nix create mode 100644 hosts/fscusat/modules/ftpsync/ftpsync.nix (limited to 'hosts/fscusat/modules/ftpsync') diff --git a/hosts/fscusat/modules/ftpsync/default.nix b/hosts/fscusat/modules/ftpsync/default.nix new file mode 100644 index 0000000..aa214ac --- /dev/null +++ b/hosts/fscusat/modules/ftpsync/default.nix @@ -0,0 +1,21 @@ +{ 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 new file mode 100644 index 0000000..8c1d170 --- /dev/null +++ b/hosts/fscusat/modules/ftpsync/ftpsync.nix @@ -0,0 +1,66 @@ +{ 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"; + }; + }; + }; + }; +} -- cgit v1.2.3