Compare commits
2 Commits
b0b643f164
...
a5c8d284ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5c8d284ee | ||
|
|
c2f151e03e |
@@ -44,6 +44,7 @@
|
||||
./system-modules/postgres.nix
|
||||
./system-modules/nx2site/proxy.nix
|
||||
./system-modules/calendar-publish.nix
|
||||
./system-modules/calendar-lec.nix
|
||||
./system-modules/nx2site/audiobookshelf.nix
|
||||
./system-modules/nx2site/gitea.nix
|
||||
./system-modules/nx2site/open-web-calendar.nix
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
{
|
||||
name = "LEC";
|
||||
url = "https://zlypher.github.io/lol-events/cal/league-of-legends-lec.ical";
|
||||
url = "https://${domain}/lec.ics";
|
||||
color = "#A87000";
|
||||
read-only = true;
|
||||
type = "ics";
|
||||
|
||||
67
home-modules/nx2site-backup.nix
Normal file
67
home-modules/nx2site-backup.nix
Normal file
@@ -0,0 +1,67 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
home.packages = [
|
||||
(pkgs.writeShellApplication {
|
||||
name = "nx_backup";
|
||||
runtimeInputs = [ ];
|
||||
text = let
|
||||
web-root = "/var/nginx/webroot";
|
||||
gitea-backup = "/var/backup/gitea";
|
||||
postgres-backup = "/var/backup/postgresql";
|
||||
in /* bash */ ''
|
||||
DIRECTORIES=(
|
||||
"${web-root}"
|
||||
"${gitea-backup}"
|
||||
"${postgres-backup}"
|
||||
)
|
||||
|
||||
NOW=$(date +%Y_%m_%d-%H_%M)
|
||||
TEMP_BAK_DIR=$(mktemp -d)
|
||||
TEMP_WORKING_DIR=$(mktemp -d)
|
||||
ZIP_NAME="nx2site-backup-''${NOW}.zip"
|
||||
ZIP_FILE="$TEMP_WORKING_DIR/$ZIP_NAME"
|
||||
ENCRYPTED_NAME="''${ZIP_NAME}.asc"
|
||||
ENCRYPTED_FILE="$TEMP_WORKING_DIR/$ENCRYPTED_NAME"
|
||||
DESTINATION="/vault/$ENCRYPTED_NAME"
|
||||
WEBROOT="${web-root}"
|
||||
|
||||
echo "Fixing Permissions of Gitea dump"
|
||||
sudo chmod -R g+r "${gitea-backup}"
|
||||
|
||||
echo "Fixing Permissions of Postgres dump"
|
||||
sudo chmod -R g+r "${postgres-backup}"
|
||||
sudo chmod g+x "${postgres-backup}"
|
||||
echo "Fixing Ownership of Postgres dump"
|
||||
sudo chown -R postgres:postgres "${postgres-backup}"
|
||||
|
||||
echo "Copying files to backup to tempoary directory $TEMP_BAK_DIR ..."
|
||||
for DIR in "''${DIRECTORIES[@]}"; do
|
||||
rsync -aR "$DIR" "$TEMP_BAK_DIR"
|
||||
done
|
||||
|
||||
# Create the zip file
|
||||
echo "Adding files to $ZIP_NAME ..."
|
||||
zip -qr "$ZIP_FILE" "$TEMP_BAK_DIR"
|
||||
|
||||
# Encrypt the zip file using GPG
|
||||
echo "Encryping file with gpg"
|
||||
gpg -e -r gpg@nx2.site -o "$ENCRYPTED_FILE" "$ZIP_FILE"
|
||||
|
||||
echo "Moving file to Destination $DESTINATION"
|
||||
mv "$ENCRYPTED_FILE" "$DESTINATION"
|
||||
|
||||
echo "Updating latest-bakup path in $WEBROOT"
|
||||
echo "$DESTINATION" > "$WEBROOT/latest-backup"
|
||||
|
||||
echo "Cleaning up tempoary files and directories"
|
||||
rm -rf "$TEMP_BAK_DIR" "$TEMP_WORKING_DIR" "$ZIP_FILE"
|
||||
|
||||
echo "Backup and encryption complete: $DESTINATION"
|
||||
|
||||
echo "Space remaining:"
|
||||
df -h | head -n 1
|
||||
df -h | grep -P "^/dev.+? "
|
||||
'';
|
||||
})
|
||||
];
|
||||
}
|
||||
8
home.nix
8
home.nix
@@ -1,4 +1,4 @@
|
||||
{ pkgs, pkgs-unstable, host, user, inputs, ... }:
|
||||
{ pkgs, pkgs-unstable, lib, host, user, inputs, ... }:
|
||||
{
|
||||
imports = [
|
||||
./home-modules/auto-mount.nix
|
||||
@@ -31,7 +31,6 @@
|
||||
./home-modules/nh.nix
|
||||
./home-modules/nixd.nix
|
||||
./home-modules/nvidia.nix
|
||||
./home-modules/nx2site.nix
|
||||
./home-modules/nxgs.nix
|
||||
# ./home-modules/nx-gcal-event.nix
|
||||
./home-modules/obs.nix
|
||||
@@ -62,7 +61,10 @@
|
||||
./home-modules/yazi.nix
|
||||
./home-modules/zathura.nix
|
||||
./home-modules/zoxide.nix
|
||||
];
|
||||
] ++ (if (host == "NxACE") then [
|
||||
./home-modules/nx2site.nix
|
||||
./home-modules/nx2site-backup.nix
|
||||
] else []);
|
||||
home.username = user;
|
||||
home.homeDirectory = "/home/${user}";
|
||||
home.stateVersion = "24.05";
|
||||
|
||||
97
system-modules/calendar-lec.nix
Normal file
97
system-modules/calendar-lec.nix
Normal file
@@ -0,0 +1,97 @@
|
||||
{ config, pkgs, user, domain, ... }:
|
||||
{
|
||||
systemd.timers."nx_cal_lec" = {
|
||||
enable = true;
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "40m";
|
||||
OnUnitActiveSec = "24h";
|
||||
Unit = "nx_cal_lec.service";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services."nx_cal_lec" = {
|
||||
script = let
|
||||
nx_cal_lec = (pkgs.writers.writePython3Bin "nx_cal_lec" {
|
||||
libraries = with pkgs.python3Packages; [
|
||||
ical
|
||||
ics
|
||||
requests
|
||||
dateutils
|
||||
];
|
||||
flakeIgnore = [ "E302" "E305" "E226" "E501" ];
|
||||
} /*python */ ''
|
||||
import hashlib
|
||||
from ics import Calendar
|
||||
import requests
|
||||
from datetime import timedelta
|
||||
|
||||
def get_event_hash(event):
|
||||
"""
|
||||
Generate a unique hash for an event based on its details.
|
||||
"""
|
||||
event_data = f"{event.name}{event.begin}{event.end}{event.description}"
|
||||
return hashlib.md5(event_data.encode('utf-8')).hexdigest()
|
||||
|
||||
def adjust_events(events):
|
||||
"""
|
||||
Adjust overlapping events to ensure they do not conflict.
|
||||
"""
|
||||
sorted_events = sorted(events, key=lambda e: e.begin)
|
||||
for i in range(1, len(sorted_events)):
|
||||
previous_event = sorted_events[i - 1]
|
||||
current_event = sorted_events[i]
|
||||
|
||||
if current_event.begin < previous_event.end:
|
||||
# Adjust the start time of the current event to just after the previous event
|
||||
current_event.begin = previous_event.end + timedelta(minutes=1)
|
||||
print(f"Adjusted event '{current_event.name}' to start at {current_event.begin} and end at {current_event.end}")
|
||||
return sorted_events
|
||||
|
||||
def fetch_and_save_ical_events(ical_url, save_path):
|
||||
"""
|
||||
Fetch events from an iCal URL and save them as a single combined calendar.
|
||||
"""
|
||||
try:
|
||||
# Fetch the iCal data
|
||||
response = requests.get(ical_url)
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse the iCal data
|
||||
calendar = Calendar(response.text)
|
||||
|
||||
# Adjust events
|
||||
adjusted_events = adjust_events(list(calendar.events))
|
||||
|
||||
# Create a new combined calendar
|
||||
combined_calendar = Calendar()
|
||||
for event in adjusted_events:
|
||||
combined_calendar.events.add(event)
|
||||
|
||||
# Save the combined calendar to a single .ics file
|
||||
with open(save_path, 'w') as file:
|
||||
file.writelines(combined_calendar.serialize_iter())
|
||||
|
||||
print(f"Saved combined calendar to {save_path}")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching iCal data: {e}")
|
||||
except Exception as e:
|
||||
print(f"Error processing iCal data: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Replace with your iCal URL and target file path
|
||||
ICAL_URL = "https://zlypher.github.io/lol-events/cal/league-of-legends-lec.ical"
|
||||
SAVE_PATH = "${config.services.nginx.virtualHosts."${domain}".root}/lec.ics"
|
||||
|
||||
fetch_and_save_ical_events(ICAL_URL, SAVE_PATH)
|
||||
'');
|
||||
in ''
|
||||
${nx_cal_lec}/bin/nx_cal_lec
|
||||
'';
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "nx2";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user