summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-02-17 12:21:58 +0530
committersinanmohd <sinan@sinanmohd.com>2024-02-17 18:26:04 +0530
commit60ed7bde534f23be9e3ee5429f72cf63ac8bfff2 (patch)
tree315b8237ac46c1f70ce06c19e541e4465a30ec26
parentcc89fdfae084f7a0e2b0b91b7c88ff5f0e6667cf (diff)
fscusat/modules/ftpsync: init
-rw-r--r--hosts/fscusat/configuration.nix1
-rw-r--r--hosts/fscusat/modules/ftpsync/default.nix21
-rw-r--r--hosts/fscusat/modules/ftpsync/ftpsync.nix66
-rw-r--r--hosts/fscusat/pkgs/archvsync/Makefile.patch50
-rw-r--r--hosts/fscusat/pkgs/archvsync/common.patch26
-rw-r--r--hosts/fscusat/pkgs/archvsync/default.nix52
6 files changed, 216 insertions, 0 deletions
diff --git a/hosts/fscusat/configuration.nix b/hosts/fscusat/configuration.nix
index faa0b69..72e8e04 100644
--- a/hosts/fscusat/configuration.nix
+++ b/hosts/fscusat/configuration.nix
@@ -5,6 +5,7 @@
./hardware-configuration.nix
./modules/network.nix
./modules/www.nix
+ ./modules/ftpsync
../../common.nix
];
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";
+ };
+ };
+ };
+ };
+}
diff --git a/hosts/fscusat/pkgs/archvsync/Makefile.patch b/hosts/fscusat/pkgs/archvsync/Makefile.patch
new file mode 100644
index 0000000..e82ada4
--- /dev/null
+++ b/hosts/fscusat/pkgs/archvsync/Makefile.patch
@@ -0,0 +1,50 @@
+From f2ba21ba678907fac0d3d088ad09b0d140ba7740 Mon Sep 17 00:00:00 2001
+From: sinanmohd <sinan@sinanmohd.com>
+Date: Sat, 17 Feb 2024 11:37:23 +0530
+Subject: [PATCH] Makefile: nix port
+
+---
+ Makefile | 17 ++++++++---------
+ 1 file changed, 8 insertions(+), 9 deletions(-)
+
+diff --git a/Makefile b/Makefile
+index 7a774b4..1efa053 100644
+--- a/Makefile
++++ b/Makefile
+@@ -1,9 +1,8 @@
+-include /usr/share/dpkg/pkg-info.mk
++bindir = ${OUT}/bin
++docdir = ${DOC}/share/doc/ftpsync
++mandir = ${MAN}/share/man
+
+-bindir = /usr/bin
+-docdir = /usr/share/doc/ftpsync
+ examplesdir = ${docdir}/examples
+-mandir = /usr/share/man
+ man1dir = ${mandir}/man1
+ man5dir = ${mandir}/man5
+
+@@ -41,15 +40,15 @@ install -D bin/runmirrors.$(1) $(2)/runmirrors
+ endef
+
+ install:
+- $(call install_bin,install,${DESTDIR}/${bindir})
+- install -D -m644 -t ${DESTDIR}/${docdir} \
++ $(call install_bin,install,${bindir})
++ install -D -m644 -t ${docdir} \
+ README.md
+- install -D -m644 -t ${DESTDIR}/${examplesdir} \
++ install -D -m644 -t ${examplesdir} \
+ etc/ftpsync.conf.sample \
+ etc/runmirrors.conf.sample \
+ etc/runmirrors.mirror.sample
+- install -D -m644 -t ${DESTDIR}/${man1dir} ${MAN1:%=doc/%.1}
+- install -D -m644 -t ${DESTDIR}/${man5dir} ${MAN5:%=doc/%.5}
++ install -D -m644 -t ${man1dir} ${MAN1:%=doc/%.1}
++ install -D -m644 -t ${man5dir} ${MAN5:%=doc/%.5}
+
+ install-tar:
+ $(call install_bin,install-tar,${DESTDIR}/bin/)
+--
+2.43.0
+
diff --git a/hosts/fscusat/pkgs/archvsync/common.patch b/hosts/fscusat/pkgs/archvsync/common.patch
new file mode 100644
index 0000000..d101f40
--- /dev/null
+++ b/hosts/fscusat/pkgs/archvsync/common.patch
@@ -0,0 +1,26 @@
+From 0bb6e03dbbf0bd47f6f8cc42274b8f7fa9fc9262 Mon Sep 17 00:00:00 2001
+From: sinanmohd <sinan@sinanmohd.com>
+Date: Sat, 17 Feb 2024 14:31:03 +0530
+Subject: [PATCH] common: fix config location when wrapped
+
+---
+ bin/common | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/bin/common b/bin/common
+index 7ac7977..941e77a 100644
+--- a/bin/common
++++ b/bin/common
+@@ -332,6 +332,9 @@ search_config() {
+ # Read config file
+ read_config() {
+ local name=$(echo "$1" | sed -e 's/[^A-Za-z0-9._-]/_/g')
++ name="${1%-wrapped.conf}"
++ name="${name#.}.conf"
++
+ local config=$(search_config "$name")
+ if [ "$config" ]; then
+ . "$config"
+--
+2.43.0
+
diff --git a/hosts/fscusat/pkgs/archvsync/default.nix b/hosts/fscusat/pkgs/archvsync/default.nix
new file mode 100644
index 0000000..bd3560e
--- /dev/null
+++ b/hosts/fscusat/pkgs/archvsync/default.nix
@@ -0,0 +1,52 @@
+{ lib,
+ stdenvNoCC,
+ fetchFromGitLab,
+ makeWrapper,
+
+ pandoc,
+ rsync,
+ bash,
+ hostname,
+}:
+
+stdenvNoCC.mkDerivation {
+ pname = "archvsync";
+ version = "unstable-2024-02-17";
+
+ src = fetchFromGitLab {
+ domain = "salsa.debian.org";
+ owner = "mirror-team";
+ repo = "archvsync";
+ rev = "653357779c338863917aa069afbae1b24472d32d";
+ hash = "sha256-vI32Cko5jXY/aZI9hKWm3GI26Oy89M5VLUFWBk1HNXQ=";
+ };
+
+ strictDeps = true;
+ nativeBuildInputs = [ makeWrapper pandoc ];
+ outputs = [ "out" "man" "doc" ];
+
+ patches = [ ./Makefile.patch ./common.patch ];
+
+ postInstall = ''
+ for s in $out/bin/*; do
+ wrapProgram $s --prefix PATH : ${lib.makeBinPath
+ [ rsync bash hostname ]
+ }
+ done
+ '';
+
+ makeFlags = [
+ "OUT=${placeholder "out"}"
+ "MAN=${placeholder "man"}"
+ "DOC=${placeholder "doc"}"
+ ];
+
+ meta = with lib; {
+ description = "Scripts for maintaining a Debian archive mirror";
+ homepage = "https://salsa.debian.org/mirror-team/archvsync";
+ license = licenses.gpl2;
+ platforms = platforms.all;
+ maintainers = with maintainers; [ sinanmohd ];
+ mainProgram = "ftpsync";
+ };
+}