From ce831333a24011d0692f6871047fe74eab9fab8c Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Sun, 29 Nov 2026 17:24:18 +0100 Subject: initial commit --- .gitignore | 5 + config/boot.nix | 8 + config/default.nix | 23 + config/environment.nix | 17 + config/hardware/default.nix | 18 + config/hardware/hardware-configuration.nix | 46 + config/networking.nix | 24 + config/nix.nix | 12 + config/services/dav/create-bday-cal.py | 159 ++++ config/services/dav/default.nix | 30 + config/services/dav/web | 1 + config/services/default.nix | 10 + config/services/git/default.nix | 23 + config/services/git/shell-commands/default.nix | 13 + config/services/git/shell-commands/repo/.gitignore | 1 + .../services/git/shell-commands/repo/default.nix | 19 + .../git/shell-commands/repo/src/bashly.yml | 83 ++ .../git/shell-commands/repo/src/create_command.sh | 25 + .../repo/src/lib/check-git-repository.sh | 7 + .../shell-commands/repo/src/lib/check-realpath.sh | 9 + .../git/shell-commands/repo/src/lib/colors.sh | 14 + .../git/shell-commands/repo/src/lib/is-git-dir.sh | 3 + .../git/shell-commands/repo/src/lib/show-descr.sh | 3 + .../shell-commands/repo/src/lib/show-privacy.sh | 12 + .../repo/src/lib/show-repo-summary.sh | 8 + .../git/shell-commands/repo/src/lib/show-repo.sh | 6 + .../git/shell-commands/repo/src/lib/show-size.sh | 3 + .../git/shell-commands/repo/src/remove_command.sh | 10 + .../repo/src/set_description_command.sh | 14 + .../shell-commands/repo/src/set_privacy_command.sh | 17 + .../git/shell-commands/repo/src/show_command.sh | 35 + config/services/git/web | 1 + config/services/mesh/default.nix | 48 ++ config/services/web/dav/default.nix | 15 + config/services/web/default.nix | 27 + config/services/web/git/about.html | 3 + config/services/web/git/cgit.css | 943 +++++++++++++++++++++ config/services/web/git/default.nix | 49 ++ config/services/web/git/head.html | 1 + config/services/web/quentin/default.nix | 20 + .../web/rss/DeutschLernenDeutscheWelleBridge.php | 39 + config/services/web/rss/FipAlbumsBridge.php | 56 ++ config/services/web/rss/MaisonDeLaRadioBridge.php | 137 +++ config/services/web/rss/RandonavigoBridge.php | 33 + config/services/web/rss/default.nix | 45 + config/services/web/webkeydirectory/default.nix | 25 + .../hu/44hqjnz5rw4mrr9d18fmecyskbmwxetw | Bin 0 -> 3578 bytes config/system.nix | 10 + config/users.nix | 32 + devenv.lock | 149 ++++ devenv.nix | 4 + devenv.yaml | 10 + flake.lock | 493 +++++++++++ flake.nix | 55 ++ tests/configuration.nix | 75 ++ tests/run-tests.sh | 112 +++ 56 files changed, 3040 insertions(+) create mode 100644 .gitignore create mode 100644 config/boot.nix create mode 100644 config/default.nix create mode 100644 config/environment.nix create mode 100644 config/hardware/default.nix create mode 100644 config/hardware/hardware-configuration.nix create mode 100644 config/networking.nix create mode 100644 config/nix.nix create mode 100644 config/services/dav/create-bday-cal.py create mode 100644 config/services/dav/default.nix create mode 120000 config/services/dav/web create mode 100644 config/services/default.nix create mode 100644 config/services/git/default.nix create mode 100644 config/services/git/shell-commands/default.nix create mode 100644 config/services/git/shell-commands/repo/.gitignore create mode 100644 config/services/git/shell-commands/repo/default.nix create mode 100644 config/services/git/shell-commands/repo/src/bashly.yml create mode 100644 config/services/git/shell-commands/repo/src/create_command.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/check-git-repository.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/check-realpath.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/colors.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/is-git-dir.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/show-descr.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/show-privacy.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/show-repo-summary.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/show-repo.sh create mode 100644 config/services/git/shell-commands/repo/src/lib/show-size.sh create mode 100644 config/services/git/shell-commands/repo/src/remove_command.sh create mode 100644 config/services/git/shell-commands/repo/src/set_description_command.sh create mode 100644 config/services/git/shell-commands/repo/src/set_privacy_command.sh create mode 100644 config/services/git/shell-commands/repo/src/show_command.sh create mode 120000 config/services/git/web create mode 100644 config/services/mesh/default.nix create mode 100644 config/services/web/dav/default.nix create mode 100644 config/services/web/default.nix create mode 100644 config/services/web/git/about.html create mode 100644 config/services/web/git/cgit.css create mode 100644 config/services/web/git/default.nix create mode 100644 config/services/web/git/head.html create mode 100644 config/services/web/quentin/default.nix create mode 100644 config/services/web/rss/DeutschLernenDeutscheWelleBridge.php create mode 100644 config/services/web/rss/FipAlbumsBridge.php create mode 100644 config/services/web/rss/MaisonDeLaRadioBridge.php create mode 100644 config/services/web/rss/RandonavigoBridge.php create mode 100644 config/services/web/rss/default.nix create mode 100644 config/services/web/webkeydirectory/default.nix create mode 100644 config/services/web/webkeydirectory/hu/44hqjnz5rw4mrr9d18fmecyskbmwxetw create mode 100644 config/system.nix create mode 100644 config/users.nix create mode 100644 devenv.lock create mode 100644 devenv.nix create mode 100644 devenv.yaml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 tests/configuration.nix create mode 100755 tests/run-tests.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6849dee --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +### devenv +.devenv/ +.devenv.flake.nix +devenv.local.nix +.pre-commit-config.yaml diff --git a/config/boot.nix b/config/boot.nix new file mode 100644 index 0000000..e959b00 --- /dev/null +++ b/config/boot.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + personal.boot = { + grub.enable = true; + efi.enable = true; + }; +} diff --git a/config/default.nix b/config/default.nix new file mode 100644 index 0000000..ed549e3 --- /dev/null +++ b/config/default.nix @@ -0,0 +1,23 @@ +{ modulesPath, ... }: + +{ + imports = [ + (modulesPath + "/profiles/headless.nix") + (modulesPath + "/profiles/minimal.nix") + ./boot.nix + ./environment.nix + ./networking.nix + ./nix.nix + ./services + ./system.nix + ./users.nix + ]; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "26.05"; # Did you read the comment? +} diff --git a/config/environment.nix b/config/environment.nix new file mode 100644 index 0000000..072c3fb --- /dev/null +++ b/config/environment.nix @@ -0,0 +1,17 @@ +{ lib, pkgs, ... }: + +{ + personal.environment = { + enable = true; + locale.enable = true; + }; + + programs.bash.promptInit = '' + PS1="\n\[\033[1;32m\][\[\e]0;\u@$(hostname -f): \w\a\]\u@$(hostname -f):\w]\$\[\033[0m\] " + ''; + console = { + earlySetup = true; + font = lib.mkForce "ter-v32n"; + packages = with pkgs; [ terminus_font ]; + }; +} diff --git a/config/hardware/default.nix b/config/hardware/default.nix new file mode 100644 index 0000000..aa11a7b --- /dev/null +++ b/config/hardware/default.nix @@ -0,0 +1,18 @@ +{ nixos-hardware, ... }: + +{ + imports = [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + + # Community-curated hardware configuration + # nixos-hardware.nixosModules.common-cpu-intel + # nixos-hardware.nixosModules.common-pc + # nixos-hardware.nixosModules.common-pc-ssd + ]; + + personal.hardware = { + disks.crypted = "/dev/disk/by-uuid/1f453b74-3b03-4992-9d84-97a8208372d1"; + keyboard.keyMap = "fr"; + }; +} diff --git a/config/hardware/hardware-configuration.nix b/config/hardware/hardware-configuration.nix new file mode 100644 index 0000000..e92068e --- /dev/null +++ b/config/hardware/hardware-configuration.nix @@ -0,0 +1,46 @@ +{ + config, + lib, + pkgs, + modulesPath, + ... +}: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ + "xhci_pci" + "ahci" + "nvme" + "usbhid" + "usb_storage" + "sd_mod" + ]; + boot.initrd.kernelModules = [ "dm-snapshot" ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = { + device = "/dev/mapper/nixos-root"; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/DA86-17BF"; + fsType = "vfat"; + options = [ + "fmask=0022" + "dmask=0022" + ]; + }; + + swapDevices = [ + { device = "/dev/mapper/nixos-swap"; } + ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/config/networking.nix b/config/networking.nix new file mode 100644 index 0000000..f22e47b --- /dev/null +++ b/config/networking.nix @@ -0,0 +1,24 @@ +{ ... }: +{ + personal.networking = { + enable = true; + firewall.http = true; + ssh.enable = true; + }; + + networking = { + hostName = "hermaphroditos"; + domain = "aristote.fr"; + }; + + services.resolved = { + enable = true; + settings.Resolve.DNSOverTLS = "opportunistic"; + }; + + services.tailscale = { + enable = true; + openFirewall = true; + disableTaildrop = true; + }; +} diff --git a/config/nix.nix b/config/nix.nix new file mode 100644 index 0000000..2decfa3 --- /dev/null +++ b/config/nix.nix @@ -0,0 +1,12 @@ +{ ... }: + +{ + personal.nix = { + enable = true; + gc.enable = true; + }; + nixpkgs.flake = { + setNixPath = true; + setFlakeRegistry = true; + }; +} diff --git a/config/services/dav/create-bday-cal.py b/config/services/dav/create-bday-cal.py new file mode 100644 index 0000000..32fade9 --- /dev/null +++ b/config/services/dav/create-bday-cal.py @@ -0,0 +1,159 @@ +# https://github.com/iBigQ/radicale-birthday-calendar + +import fileinput +import json +import os +import random +import uuid +from collections import defaultdict +from datetime import datetime, timedelta +from typing import Iterator, Any + +import dateutil.rrule as rrule +import vobject + +BIRTHDAY_CALENDAR_COLOR = None +BIRTHDAY_REMINDER_AT_HOUR = True + + +def parse_date(date_str): + for date_fmt in ("%Y-%m-%d", "%Y%m%d", "--%m%d"): + try: + return datetime.strptime(date_str, date_fmt) + except ValueError: + pass + raise ValueError(f"could not parse date {date_str}") + + +def get_changed_files() -> dict[str, list[str]]: + user_modifications = defaultdict(list) + for changed_file in fileinput.input(): + changed_file = changed_file.rstrip("\n") + if ( + not changed_file + or "/.Radicale.cache/" in changed_file + or not changed_file.count("/") >= 3 + ): + continue + root, user, collection, file = changed_file.split("/", maxsplit=3) + user_modifications[f"{root}/{user}"].append(f"{collection}/{file}") + return user_modifications + + +def get_user_collections(user: str) -> dict[str, str]: + user_collections = {} + dirpath, dirnames, filenames = next(os.walk(user), ([], [], [])) + for collection in dirnames: + try: + with open(f"{user}/{collection}/.Radicale.props", "r") as fp: + tag = json.load(fp)["tag"] + except (FileNotFoundError, json.JSONDecodeError, KeyError): + continue + else: + user_collections[collection] = tag + return user_collections + + +def get_entries(collection: str) -> Iterator[tuple[str, Any]]: + dirpath, dirnames, filenames = next(os.walk(collection), ([], [], [])) + for filename in filenames: + if filename.startswith(".Radicale"): + continue + with open(f"{dirpath}/{filename}", "r") as fp: + for entry in vobject.readComponents(fp.read()): + yield f"{collection}/{filename}", entry + + +def get_birthday_calendar(user: str) -> Iterator[tuple[str, Any]]: + collection = f"{user}/birthdays" + if not os.path.exists(collection): + os.makedirs(collection, exist_ok=True) + fn = f"{collection}/.Radicale.props" + if not os.path.exists(fn): + with open(fn, "w") as fp: + # (Optional) Get calendar color from environment + if BIRTHDAY_CALENDAR_COLOR: + # If color was set, strip '#' for consistency + color = BIRTHDAY_CALENDAR_COLOR.strip("#") + else: + # Or alternatively choose something at random + color = "".join(random.choices("0123456abcdef", k=6)) + + data = { + "C:supported-calendar-component-set": "VEVENT", + "D:displayname": "Birthdays", + "C:calendar-description": "[AUTO GENERATED] " + + "Birthdays from all addressbooks", + "ICAL:calendar-color": f"#{color}", + "tag": "VCALENDAR", + } + json.dump(data, fp, indent=None) + yield from get_entries(collection) + + +def create_birthday(user: str, contact): + calendar = vobject.iCalendar() + + # Basic event properties + event = calendar.add("vevent") + event.add("summary").value = contact.fn.value + event.add("dtstart").value = parse_date(contact.bday.value).date() + event.add("dtend").value = event.dtstart.value + timedelta(days=1) + event.add("uid").value = contact.uid.value + + # (Optional) Set reminder + if BIRTHDAY_REMINDER_AT_HOUR: + alarm = event.add("valarm") + alarm.add("action").value = "DISPLAY" + alarm.add("description").value = "Reminder" + alarm.add("trigger").value = timedelta(hours=0) + alarm.add("uid").value = str(uuid.uuid4()) + + # Repeat yearly + newrule = rrule.rruleset() + newrule.rrule(rrule.rrule(rrule.YEARLY, dtstart=event.dtstart.value)) + event.rruleset = newrule + + # Write to disk + collection = f"{user}/birthdays" + with open(f"{collection}/{contact.uid.value}.ics", "w") as fp: + fp.write(calendar.serialize()) + + +def main(): + user_to_changes = get_changed_files() + user_to_collections = { + user: get_user_collections(user) for user in user_to_changes + } + + for user, changed_files in user_to_changes.items(): + contacts = { + contact.uid.value: contact + for collection, tag in user_to_collections[user].items() + if tag == "VADDRESSBOOK" + for _, contact in get_entries(f"{user}/{collection}") + if hasattr(contact, "bday") + } + birthday_entries = { + user_bday.vevent.uid.value: (fn, user_bday) + for fn, user_bday in get_birthday_calendar(user) + } + + # Check existing birthday entries + for bday_uid, (bday_file, bday_event) in birthday_entries.items(): + # Delete old ones + if bday_uid not in contacts: + os.unlink(bday_file) + # Keep unchanged + elif not any( + bday_uid in changed_file for changed_file in changed_files + ): + del contacts[bday_uid] + + # Write new and modified contacts + for contact in contacts.values(): + create_birthday(user, contact) + + +if __name__ == "__main__": + main() diff --git a/config/services/dav/default.nix b/config/services/dav/default.nix new file mode 100644 index 0000000..2157ad0 --- /dev/null +++ b/config/services/dav/default.nix @@ -0,0 +1,30 @@ +{ config, pkgs, ... }: + +{ + services.radicale = { + enable = true; + settings = { + auth = { + type = "htpasswd"; + # generate with + # nix shell nixpkgs#apacheHttpd --command htpasswd -cB .htpasswd username + htpasswd_filename = "/etc/radicale/.htpasswd"; + htpasswd_encryption = "bcrypt"; + }; + storage = { + filesystem_folder = "/srv/dav/collections"; + hook = "${ + pkgs.writers.writePython3Bin "create-bday-cal" { + libraries = with pkgs.python3Packages; [ + python-dateutil + vobject + ]; + } (builtins.readFile ./create-bday-cal.py) + }/bin/create-bday-cal"; + }; + web.type = "none"; + }; + }; + + systemd.services.radicale.personal.monitor = true; +} diff --git a/config/services/dav/web b/config/services/dav/web new file mode 120000 index 0000000..7698db0 --- /dev/null +++ b/config/services/dav/web @@ -0,0 +1 @@ +../web/dav/ \ No newline at end of file diff --git a/config/services/default.nix b/config/services/default.nix new file mode 100644 index 0000000..0cdc85d --- /dev/null +++ b/config/services/default.nix @@ -0,0 +1,10 @@ +{ ... }: + +{ + imports = [ + ./dav + ./git + ./mesh + ./web + ]; +} diff --git a/config/services/git/default.nix b/config/services/git/default.nix new file mode 100644 index 0000000..1ebc5e6 --- /dev/null +++ b/config/services/git/default.nix @@ -0,0 +1,23 @@ +{ config, pkgs, ... }: + +{ + imports = [ + ./shell-commands + ]; + + users.users.git = { + isSystemUser = true; + group = "git"; + createHome = true; + homeMode = "750"; + home = "/srv/git"; + shell = "${pkgs.git}/bin/git-shell"; + openssh.authorizedKeys.keys = with config.personal.lib.publicKeys.ssh; [ + latitude-7490 + precision-3571 + dragonfly-g4 + ]; + }; + + users.groups.git = { }; +} diff --git a/config/services/git/shell-commands/default.nix b/config/services/git/shell-commands/default.nix new file mode 100644 index 0000000..c27bf9c --- /dev/null +++ b/config/services/git/shell-commands/default.nix @@ -0,0 +1,13 @@ +{ lib, pkgs, ... }: + +let + repo = import ./repo { inherit lib pkgs; }; + gitShellCommands = "/srv/git/git-shell-commands"; +in +{ + system.activationScripts.buildGitShell.text = '' + install --mode u=rX,g=,o= --owner git --group git --directory ${gitShellCommands} + rm -rf ${gitShellCommands}/* + ln -s ${repo} ${gitShellCommands}/repo + ''; +} diff --git a/config/services/git/shell-commands/repo/.gitignore b/config/services/git/shell-commands/repo/.gitignore new file mode 100644 index 0000000..ffdcec4 --- /dev/null +++ b/config/services/git/shell-commands/repo/.gitignore @@ -0,0 +1 @@ +repo \ No newline at end of file diff --git a/config/services/git/shell-commands/repo/default.nix b/config/services/git/shell-commands/repo/default.nix new file mode 100644 index 0000000..bbccbfd --- /dev/null +++ b/config/services/git/shell-commands/repo/default.nix @@ -0,0 +1,19 @@ +{ lib, pkgs }: + +pkgs.stdenvNoCC.mkDerivation { + name = "repo"; + src = lib.fileset.toSource { + root = ./src; + fileset = ./src; + }; + buildInputs = [ pkgs.bashly ]; + unpackPhase = '' + ln --symbolic --no-target-directory "$src" src + ''; + buildPhase = '' + bashly generate + ''; + installPhase = '' + install ./repo "$out" + ''; +} diff --git a/config/services/git/shell-commands/repo/src/bashly.yml b/config/services/git/shell-commands/repo/src/bashly.yml new file mode 100644 index 0000000..6a216ae --- /dev/null +++ b/config/services/git/shell-commands/repo/src/bashly.yml @@ -0,0 +1,83 @@ +name: repo +help: show and configure repositories + +commands: +- name: show + help: show repositories + default: true + + args: + - name: path + required: false + help: path in which to list repositories + + flags: + - long: --verbose + short: -v + help: show repository description + - long: --tree + short: -t + help: show intermediate directories + + examples: + - "repo show # list all repositories" + - "repo show --verbose # list repositories in details" + - "repo show about-me # list repositories in the about-me/ folder" + - "repo show about-me/cv # show the about-me/cv repository" + - "repo show --tree # list all repositories as well as intermediate directories" + +- name: set + help: configure repository + + commands: + - name: description + alias: descr + help: set repository description + + args: + - name: repo + required: true + help: repository path + + examples: + - repo set descr about-me/cv + + - name: privacy + alias: prv + help: recursively set repository visibility + + args: + - name: path + required: true + help: repository path + - name: visibility + required: true + help: new repository visibility + allowed: [public, private] + + examples: + - "repo set prv public about-me/cv # change visibility of a single repository" + - "repo set prv public about-me # change visibility of all repositories in a tree" + +- name: create + help: create bare repositories + + args: + - name: repo + required: true + help: repository path + + examples: + - repo create path/to/repo + +- name: remove + alias: rm + help: remove repository or empty directory + + args: + - name: path + required: true + help: repository path + + examples: + - repo rm path/to/repo diff --git a/config/services/git/shell-commands/repo/src/create_command.sh b/config/services/git/shell-commands/repo/src/create_command.sh new file mode 100644 index 0000000..ab8bf3f --- /dev/null +++ b/config/services/git/shell-commands/repo/src/create_command.sh @@ -0,0 +1,25 @@ +repo=$(realpath --canonicalize-missing /srv/git/"${args[repo]}") + +if [[ ! "$repo" == /srv/git/* ]] +then + red "Forbidden path." + exit 2 +fi + +subpath=/srv/git +IFS='/' read -ra dirs <<< "${repo#/srv/git/}" +for dir in "${dirs[@]}"; do + subpath="$subpath/$dir" + if [[ ! -d "$subpath" ]] + then + break + fi +done + +mkdir --parents "$repo" +chmod u=rwX,g=,o= --recursive "$subpath" +git init --bare "$repo" + +args[path]="$repo" +args[--tree]=1 +repo_show_command diff --git a/config/services/git/shell-commands/repo/src/lib/check-git-repository.sh b/config/services/git/shell-commands/repo/src/lib/check-git-repository.sh new file mode 100644 index 0000000..c974890 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/check-git-repository.sh @@ -0,0 +1,7 @@ +check-git-repository() { + if [[ ! $(is-git-dir "$1") ]] + then + red "Not a git repository." + exit 2 + fi +} diff --git a/config/services/git/shell-commands/repo/src/lib/check-realpath.sh b/config/services/git/shell-commands/repo/src/lib/check-realpath.sh new file mode 100644 index 0000000..c344bd2 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/check-realpath.sh @@ -0,0 +1,9 @@ +check-realpath() { + local path="$1" + if [[ ! -e "$path" ]] \ + || [[ ! "$path" == /srv/git/* ]] + then + red "Forbidden path." + exit 2 + fi +} diff --git a/config/services/git/shell-commands/repo/src/lib/colors.sh b/config/services/git/shell-commands/repo/src/lib/colors.sh new file mode 100644 index 0000000..a78911d --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/colors.sh @@ -0,0 +1,14 @@ +print_in_color() { + local color="$1" + shift + if [[ "${NO_COLOR:-}" == "" ]]; then + printf "$color%b\e[0m\n" "$*" + else + printf "%b\n" "$*" + fi +} + +red() { print_in_color "\e[31m" "$*"; } +green() { print_in_color "\e[32m" "$*"; } +blue() { print_in_color "\e[34m" "$*"; } +bold() { print_in_color "\e[1m" "$*"; } diff --git a/config/services/git/shell-commands/repo/src/lib/is-git-dir.sh b/config/services/git/shell-commands/repo/src/lib/is-git-dir.sh new file mode 100644 index 0000000..d94f2ba --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/is-git-dir.sh @@ -0,0 +1,3 @@ +is-git-dir() { + git rev-parse --resolve-git-dir "$1" 2>/dev/null +} diff --git a/config/services/git/shell-commands/repo/src/lib/show-descr.sh b/config/services/git/shell-commands/repo/src/lib/show-descr.sh new file mode 100644 index 0000000..edf6d34 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/show-descr.sh @@ -0,0 +1,3 @@ +show-descr() { + echo "| $(cat "$1"/description)" +} diff --git a/config/services/git/shell-commands/repo/src/lib/show-privacy.sh b/config/services/git/shell-commands/repo/src/lib/show-privacy.sh new file mode 100644 index 0000000..11df8d1 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/show-privacy.sh @@ -0,0 +1,12 @@ +show-privacy() { + local mode=$(( $(stat -c %a "$1")/10 %10 )) + if [[ $mode == 0 ]] + then + red private + elif [[ $mode == 5 ]] + then + green public + else + blue unknown + fi +} diff --git a/config/services/git/shell-commands/repo/src/lib/show-repo-summary.sh b/config/services/git/shell-commands/repo/src/lib/show-repo-summary.sh new file mode 100644 index 0000000..7c0bf63 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/show-repo-summary.sh @@ -0,0 +1,8 @@ +show-repo-summary() { + local repo="$1" + local name="${repo#/srv/git/}" + local privacy=$(show-privacy "$repo") + local size=$(show-size "$repo") + printf "%-16s %4s " "$privacy" "$size" + bold "$name" +} diff --git a/config/services/git/shell-commands/repo/src/lib/show-repo.sh b/config/services/git/shell-commands/repo/src/lib/show-repo.sh new file mode 100644 index 0000000..d125341 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/show-repo.sh @@ -0,0 +1,6 @@ +show-repo() { + local repo="$1" + show-repo-summary "$repo" + printf "%13s" "" + show-descr "$repo" +} diff --git a/config/services/git/shell-commands/repo/src/lib/show-size.sh b/config/services/git/shell-commands/repo/src/lib/show-size.sh new file mode 100644 index 0000000..739f61d --- /dev/null +++ b/config/services/git/shell-commands/repo/src/lib/show-size.sh @@ -0,0 +1,3 @@ +show-size() { + du --human-readable --summarize "$1" | cut --field 1 +} diff --git a/config/services/git/shell-commands/repo/src/remove_command.sh b/config/services/git/shell-commands/repo/src/remove_command.sh new file mode 100644 index 0000000..b45406f --- /dev/null +++ b/config/services/git/shell-commands/repo/src/remove_command.sh @@ -0,0 +1,10 @@ +path=$(realpath "${args[path]}") + +check-realpath "$path" + +if [[ $(is-git-dir "$path") ]] +then + rm --recursive "$path" +else + rm --dir "$path" +fi diff --git a/config/services/git/shell-commands/repo/src/set_description_command.sh b/config/services/git/shell-commands/repo/src/set_description_command.sh new file mode 100644 index 0000000..b6b40f0 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/set_description_command.sh @@ -0,0 +1,14 @@ +repo=$(realpath "${args[repo]}") + +echo "$repo" +check-realpath "$repo" +check-git-repository "$repo" +echo "Old description:" +show-descr "$repo" +echo "New description:" +echo -n "| " +read descr +echo +echo "$descr" > "$repo"/description +show-repo "$repo" + diff --git a/config/services/git/shell-commands/repo/src/set_privacy_command.sh b/config/services/git/shell-commands/repo/src/set_privacy_command.sh new file mode 100644 index 0000000..db033e6 --- /dev/null +++ b/config/services/git/shell-commands/repo/src/set_privacy_command.sh @@ -0,0 +1,17 @@ +path=$(realpath "${args[path]}") + +check-realpath "$path" + +case "${args[visibility]}" in + public) + mode="rX" + ;; + private) + mode="" + ;; +esac + +chmod g="$mode" --recursive "$path" +args[--tree]=1 +args[path]="$path" +repo_show_command diff --git a/config/services/git/shell-commands/repo/src/show_command.sh b/config/services/git/shell-commands/repo/src/show_command.sh new file mode 100644 index 0000000..77bb92f --- /dev/null +++ b/config/services/git/shell-commands/repo/src/show_command.sh @@ -0,0 +1,35 @@ +if [[ -z "${args[path]}" ]] +then + path=/srv/git/ +else + path=$(realpath "${args[path]}") + check-realpath "$path" +fi + +if [[ $(is-git-dir "$path") ]] +then + args[--verbose]=1 +fi + +dirs=$(find "$path" -type f -name HEAD | while read -r head; do + dir="${head%/*}" + if [[ "${args[--tree]}" ]] + then + while [[ "$dir" != "/srv/git" && -n "$dir" ]]; do + echo "$dir/" + dir="${dir%/*}" + done + else + echo "$dir/" + fi + done | sort -u) + +for dir in $dirs +do + if [[ "${args[--verbose]}" ]] && [[ $(is-git-dir "$dir") ]] + then + show-repo "$dir" + else + show-repo-summary "$dir" + fi +done diff --git a/config/services/git/web b/config/services/git/web new file mode 120000 index 0000000..d590dc7 --- /dev/null +++ b/config/services/git/web @@ -0,0 +1 @@ +../web/git/ \ No newline at end of file diff --git a/config/services/mesh/default.nix b/config/services/mesh/default.nix new file mode 100644 index 0000000..0d596cc --- /dev/null +++ b/config/services/mesh/default.nix @@ -0,0 +1,48 @@ +{ + config, + lib, + ... +}: +let + cfg = config.services.headscale; + url = "mesh.${config.networking.domain}"; +in +{ + networking.firewall.allowedUDPPorts = [ 3478 ]; + + services.headscale = { + enable = true; + port = 8001; + settings = { + server_url = "https://${url}:443"; + derps = { + server = { + enabled = true; + stun_listen_addr = "0.0.0.0:3478"; + }; + urls = [ ]; + }; + dns = { + base_domain = "aristote.mesh"; + override_local_dns = false; + }; + }; + }; + + systemd.services.headscale.personal.monitor = true; + + services.nginx.virtualHosts.mesh = lib.mkIf cfg.enable { + serverName = "${url}"; + forceSSL = true; + enableACME = true; + locations."/" = { + proxyPass = "http://${cfg.address}:${toString cfg.port}"; + proxyWebsockets = true; + extraConfig = '' + proxy_redirect http:// https://; + proxy_buffering off; + add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always; + ''; + }; + }; +} diff --git a/config/services/web/dav/default.nix b/config/services/web/dav/default.nix new file mode 100644 index 0000000..06b9639 --- /dev/null +++ b/config/services/web/dav/default.nix @@ -0,0 +1,15 @@ +{ config, ... }: + +{ + services.nginx.virtualHosts.dav = { + serverName = "dav.${config.networking.domain}"; + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://localhost:5232/"; # default radicale host + extraConfig = '' + proxy_redirect default; + ''; + }; + }; +} diff --git a/config/services/web/default.nix b/config/services/web/default.nix new file mode 100644 index 0000000..cb7038f --- /dev/null +++ b/config/services/web/default.nix @@ -0,0 +1,27 @@ +{ ... }: + +{ + imports = [ + ./dav + ./git + ./quentin + ./rss + ./webkeydirectory + ]; + + security.acme = { + acceptTerms = true; + defaults.email = "quentin@aristote.fr"; + }; + + services.nginx = { + enable = true; + # return 444 when trying to connect to some unknown virtual host + virtualHosts."_" = { + default = true; + extraConfig = '' + return 444; + ''; + }; + }; +} diff --git a/config/services/web/git/about.html b/config/services/web/git/about.html new file mode 100644 index 0000000..32f909c --- /dev/null +++ b/config/services/web/git/about.html @@ -0,0 +1,3 @@ +

+ This website lists my personal Git repositories. See also the Git repositories for my student projects and for my professional projects. +

diff --git a/config/services/web/git/cgit.css b/config/services/web/git/cgit.css new file mode 100644 index 0000000..633fead --- /dev/null +++ b/config/services/web/git/cgit.css @@ -0,0 +1,943 @@ +/* inspired by https://github.com/MatejaMaric/responsive-cgit-css */ + +div#cgit { + padding: 0em; + margin: 0em; + font-family: sans-serif; + font-size: 10pt; + color: #333; + background: white; + padding: 4px; +} + +div#cgit a { + color: blue; + text-decoration: none; +} + +div#cgit a:hover { + text-decoration: underline; +} + +div#cgit table { + border-collapse: collapse; +} + +div#cgit table#header { + width: 100%; + margin-bottom: 1em; +} + +div#cgit table#header td.logo { + width: 96px; + vertical-align: top; +} + +div#cgit table#header td.main { + font-size: 250%; + padding-left: 10px; + white-space: nowrap; +} + +div#cgit table#header td.main a { + color: #000; +} + +div#cgit table#header td.form { + text-align: right; + vertical-align: bottom; + padding-right: 1em; + padding-bottom: 2px; + white-space: nowrap; +} + +div#cgit table#header td.form form, +div#cgit table#header td.form input, +div#cgit table#header td.form select { + font-size: 90%; +} + +div#cgit table#header td.sub { + color: #777; + border-top: solid 1px #ccc; + padding-left: 10px; +} + +div#cgit table.tabs { + border-bottom: solid 3px #ccc; + border-collapse: collapse; + margin-top: 2em; + margin-bottom: 0px; + width: 100%; +} + +div#cgit table.tabs td { + padding: 0px 1em; + vertical-align: bottom; +} + +div#cgit table.tabs td a { + padding: 2px 0.75em; + color: #777; + font-size: 110%; +} + +div#cgit table.tabs td a.active { + color: #000; + background-color: #ccc; +} + +div#cgit table.tabs a[href^="http://"]:after, div#cgit table.tabs a[href^="https://"]:after { + content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgAhcJDQY+gm2TAAAAHWlUWHRDb21tZW50AAAAAABDcmVhdGVkIHdpdGggR0lNUGQuZQcAAABbSURBVAhbY2BABs4MU4CwhYHBh2Erww4wrGFQZHjI8B8IgUIscJWyDHcggltQhI4zGDCcRwhChPggHIggP1QoAVmQkSETrGoHsiAEsACtBYN0oDAMbgU6EBcAAL2eHUt4XUU4AAAAAElFTkSuQmCC); + opacity: 0.5; + margin: 0 0 0 5px; +} + +div#cgit table.tabs td.form { + text-align: right; +} + +div#cgit table.tabs td.form form { + padding-bottom: 2px; + font-size: 90%; + white-space: nowrap; +} + +div#cgit table.tabs td.form input, +div#cgit table.tabs td.form select { + font-size: 90%; +} + +div#cgit div.path { + margin: 0px; + padding: 5px 2em 2px 2em; + color: #000; + background-color: #eee; +} + +div#cgit div.content { + margin: 0px; + padding: 2em; + border-bottom: solid 3px #ccc; +} + + +div#cgit table.list { + width: 100%; + border: none; + border-collapse: collapse; +} + +div#cgit table.list tr { + background: white; +} + +div#cgit table.list tr.logheader { + background: #eee; +} + +div#cgit table.list tr:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr:nth-child(odd) { + background: white; +} + +div#cgit table.list tr:hover { + background: #eee; +} + +div#cgit table.list tr.nohover { + background: white; +} + +div#cgit table.list tr.nohover:hover { + background: white; +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(odd) { + background: white; +} + +div#cgit table.list th { + font-weight: bold; + /* color: #888; + border-top: dashed 1px #888; + border-bottom: dashed 1px #888; + */ + padding: 0.1em 0.5em 0.05em 0.5em; + vertical-align: baseline; +} + +div#cgit table.list td { + border: none; + padding: 0.1em 0.5em 0.1em 0.5em; +} + +div#cgit table.list td.commitgraph { + font-family: monospace; + white-space: pre; +} + +div#cgit table.list td.commitgraph .column1 { + color: #a00; +} + +div#cgit table.list td.commitgraph .column2 { + color: #0a0; +} + +div#cgit table.list td.commitgraph .column3 { + color: #aa0; +} + +div#cgit table.list td.commitgraph .column4 { + color: #00a; +} + +div#cgit table.list td.commitgraph .column5 { + color: #a0a; +} + +div#cgit table.list td.commitgraph .column6 { + color: #0aa; +} + +div#cgit table.list td.logsubject { + font-family: monospace; + font-weight: bold; +} + +div#cgit table.list td.logmsg { + font-family: monospace; + white-space: pre; + padding: 0 0.5em; +} + +div#cgit table.list td a { + color: black; +} + +div#cgit table.list td a.ls-dir { + font-weight: bold; + color: #00f; +} + +div#cgit table.list td a:hover { + color: #00f; +} + +div#cgit img { + border: none; +} + +div#cgit input#switch-btn { + margin: 2px 0px 0px 0px; +} + +div#cgit td#sidebar input.txt { + width: 100%; + margin: 2px 0px 0px 0px; +} + +div#cgit table#grid { + margin: 0px; +} + +div#cgit td#content { + vertical-align: top; + padding: 1em 2em 1em 1em; + border: none; +} + +div#cgit div#summary { + vertical-align: top; + margin-bottom: 1em; +} + +div#cgit table#downloads { + float: right; + border-collapse: collapse; + border: solid 1px #777; + margin-left: 0.5em; + margin-bottom: 0.5em; +} + +div#cgit table#downloads th { + background-color: #ccc; +} + +div#cgit div#blob { + border: solid 1px black; +} + +div#cgit div.error { + color: red; + font-weight: bold; + margin: 1em 2em; +} + +div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod { + font-family: monospace; +} + +div#cgit td.ls-size { + text-align: right; + font-family: monospace; + width: 10em; +} + +div#cgit td.ls-mode { + font-family: monospace; + width: 10em; +} + +div#cgit table.blob { + margin-top: 0.5em; + border-top: solid 1px black; +} + +div#cgit table.blob td.hashes, +div#cgit table.blob td.lines { + margin: 0; padding: 0 0 0 0.5em; + vertical-align: top; + color: black; +} + +div#cgit table.blob td.linenumbers { + margin: 0; padding: 0 0.5em 0 0.5em; + vertical-align: top; + text-align: right; + border-right: 1px solid gray; +} + +div#cgit table.blob pre { + padding: 0; margin: 0; +} + +div#cgit table.blob td.linenumbers a, +div#cgit table.ssdiff td.lineno a { + color: gray; + text-align: right; + text-decoration: none; +} + +div#cgit table.blob td.linenumbers a:hover, +div#cgit table.ssdiff td.lineno a:hover { + color: black; +} + +div#cgit table.blame td.hashes, +div#cgit table.blame td.lines, +div#cgit table.blame td.linenumbers { + padding: 0; +} + +div#cgit table.blame td.hashes div.alt, +div#cgit table.blame td.lines div.alt { + padding: 0 0.5em 0 0.5em; +} + +div#cgit table.blame td.linenumbers div.alt { + padding: 0 0.5em 0 0; +} + +div#cgit table.blame div.alt:nth-child(even) { + background: #eee; +} + +div#cgit table.blame div.alt:nth-child(odd) { + background: white; +} + +div#cgit table.blame td.lines > div { + position: relative; +} + +div#cgit table.blame td.lines > div > pre { + padding: 0 0 0 0.5em; + position: absolute; + top: 0; +} + +div#cgit table.bin-blob { + margin-top: 0.5em; + border: solid 1px black; +} + +div#cgit table.bin-blob th { + font-family: monospace; + white-space: pre; + border: solid 1px #777; + padding: 0.5em 1em; +} + +div#cgit table.bin-blob td { + font-family: monospace; + white-space: pre; + border-left: solid 1px #777; + padding: 0em 1em; +} + +div#cgit table.nowrap td { + white-space: nowrap; +} + +div#cgit table.commit-info { + border-collapse: collapse; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel { + float: right; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel table { + border-collapse: collapse; + border: solid 1px #aaa; + background-color: #eee; +} + +div#cgit div.cgit-panel th { + text-align: center; +} + +div#cgit div.cgit-panel td { + padding: 0.25em 0.5em; +} + +div#cgit div.cgit-panel td.label { + padding-right: 0.5em; +} + +div#cgit div.cgit-panel td.ctrl { + padding-left: 0.5em; +} + +div#cgit table.commit-info th { + text-align: left; + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; + vertical-align: top; +} + +div#cgit table.commit-info td { + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; +} + +div#cgit div.commit-subject { + font-weight: bold; + font-size: 125%; + margin: 1.5em 0em 0.5em 0em; + padding: 0em; +} + +div#cgit div.commit-msg { + white-space: pre; + font-family: monospace; +} + +div#cgit div.notes-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit div.notes { + white-space: pre; + font-family: monospace; + border: solid 1px #ee9; + background-color: #ffd; + padding: 0.3em 2em 0.3em 1em; + float: left; +} + +div#cgit div.notes-footer { + clear: left; +} + +div#cgit div.diffstat-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit table.diffstat { + border-collapse: collapse; + border: solid 1px #aaa; + background-color: #eee; +} + +div#cgit table.diffstat th { + font-weight: normal; + text-align: left; + text-decoration: underline; + padding: 0.1em 1em 0.1em 0.1em; + font-size: 100%; +} + +div#cgit table.diffstat td { + padding: 0.2em 0.2em 0.1em 0.1em; + font-size: 100%; + border: none; +} + +div#cgit table.diffstat td.mode { + white-space: nowrap; +} + +div#cgit table.diffstat td span.modechange { + padding-left: 1em; + color: red; +} + +div#cgit table.diffstat td.add a { + color: green; +} + +div#cgit table.diffstat td.del a { + color: red; +} + +div#cgit table.diffstat td.upd a { + color: blue; +} + +div#cgit table.diffstat td.graph { + width: 500px; + vertical-align: middle; +} + +div#cgit table.diffstat td.graph table { + border: none; +} + +div#cgit table.diffstat td.graph td { + padding: 0px; + border: 0px; + height: 7pt; +} + +div#cgit table.diffstat td.graph td.add { + background-color: #5c5; +} + +div#cgit table.diffstat td.graph td.rem { + background-color: #c55; +} + +div#cgit div.diffstat-summary { + color: #888; + padding-top: 0.5em; +} + +div#cgit table.diff { + width: 100%; +} + +div#cgit table.diff td { + font-family: monospace; + white-space: pre; +} + +div#cgit table.diff td div.head { + font-weight: bold; + margin-top: 1em; + color: black; +} + +div#cgit table.diff td div.hunk { + color: #009; +} + +div#cgit table.diff td div.add { + color: green; +} + +div#cgit table.diff td div.del { + color: red; +} + +div#cgit .sha1 { + font-family: monospace; + font-size: 90%; +} + +div#cgit .left { + text-align: left; +} + +div#cgit .right { + text-align: right; +} + +div#cgit table.list td.reposection { + font-style: italic; + color: #888; +} + +div#cgit a.button { + font-size: 80%; + padding: 0em 0.5em; +} + +div#cgit a.primary { + font-size: 100%; +} + +div#cgit a.secondary { + font-size: 90%; +} + +div#cgit td.toplevel-repo { + +} + +div#cgit table.list td.sublevel-repo { + padding-left: 1.5em; +} + +div#cgit ul.pager { + list-style-type: none; + text-align: center; + margin: 1em 0em 0em 0em; + padding: 0; +} + +div#cgit ul.pager li { + display: inline-block; + margin: 0.25em 0.5em; +} + +div#cgit ul.pager a { + color: #777; +} + +div#cgit ul.pager .current { + font-weight: bold; +} + +div#cgit span.age-mins { + font-weight: bold; + color: #080; +} + +div#cgit span.age-hours { + color: #080; +} + +div#cgit span.age-days { + color: #040; +} + +div#cgit span.age-weeks { + color: #444; +} + +div#cgit span.age-months { + color: #888; +} + +div#cgit span.age-years { + color: #bbb; +} + +div#cgit span.insertions { + color: #080; +} + +div#cgit span.deletions { + color: #800; +} + +div#cgit div.footer { + margin-top: 0.5em; + text-align: center; + font-size: 80%; + color: #ccc; +} + +div#cgit div.footer a { + color: #ccc; + text-decoration: none; +} + +div#cgit div.footer a:hover { + text-decoration: underline; +} + +div#cgit a.branch-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #88ff88; + border: solid 1px #007700; +} + +div#cgit a.tag-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ffff88; + border: solid 1px #777700; +} + +div#cgit a.tag-annotated-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ffcc88; + border: solid 1px #777700; +} + +div#cgit a.remote-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ccccff; + border: solid 1px #000077; +} + +div#cgit a.deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ff8888; + border: solid 1px #770000; +} + +div#cgit div.commit-subject a.branch-deco, +div#cgit div.commit-subject a.tag-deco, +div#cgit div.commit-subject a.tag-annotated-deco, +div#cgit div.commit-subject a.remote-deco, +div#cgit div.commit-subject a.deco { + margin-left: 1em; + font-size: 75%; +} + +div#cgit table.stats { + border: solid 1px black; + border-collapse: collapse; +} + +div#cgit table.stats th { + text-align: left; + padding: 1px 0.5em; + background-color: #eee; + border: solid 1px black; +} + +div#cgit table.stats td { + text-align: right; + padding: 1px 0.5em; + border: solid 1px black; +} + +div#cgit table.stats td.total { + font-weight: bold; + text-align: left; +} + +div#cgit table.stats td.sum { + color: #c00; + font-weight: bold; +/* background-color: #eee; */ +} + +div#cgit table.stats td.left { + text-align: left; +} + +div#cgit table.vgraph { + border-collapse: separate; + border: solid 1px black; + height: 200px; +} + +div#cgit table.vgraph th { + background-color: #eee; + font-weight: bold; + border: solid 1px white; + padding: 1px 0.5em; +} + +div#cgit table.vgraph td { + vertical-align: bottom; + padding: 0px 10px; +} + +div#cgit table.vgraph div.bar { + background-color: #eee; +} + +div#cgit table.hgraph { + border: solid 1px black; + width: 800px; +} + +div#cgit table.hgraph th { + background-color: #eee; + font-weight: bold; + border: solid 1px black; + padding: 1px 0.5em; +} + +div#cgit table.hgraph td { + vertical-align: middle; + padding: 2px 2px; +} + +div#cgit table.hgraph div.bar { + background-color: #eee; + height: 1em; +} + +div#cgit table.ssdiff { + width: 100%; +} + +div#cgit table.ssdiff td { + font-size: 75%; + font-family: monospace; + white-space: pre; + padding: 1px 4px 1px 4px; + border-left: solid 1px #aaa; + border-right: solid 1px #aaa; +} + +div#cgit table.ssdiff td.add { + color: black; + background: #cfc; + min-width: 50%; +} + +div#cgit table.ssdiff td.add_dark { + color: black; + background: #aca; + min-width: 50%; +} + +div#cgit table.ssdiff span.add { + background: #cfc; + font-weight: bold; +} + +div#cgit table.ssdiff td.del { + color: black; + background: #fcc; + min-width: 50%; +} + +div#cgit table.ssdiff td.del_dark { + color: black; + background: #caa; + min-width: 50%; +} + +div#cgit table.ssdiff span.del { + background: #fcc; + font-weight: bold; +} + +div#cgit table.ssdiff td.changed { + color: black; + background: #ffc; + min-width: 50%; +} + +div#cgit table.ssdiff td.changed_dark { + color: black; + background: #cca; + min-width: 50%; +} + +div#cgit table.ssdiff td.lineno { + color: black; + background: #eee; + text-align: right; + width: 3em; + min-width: 3em; +} + +div#cgit table.ssdiff td.hunk { + color: black; + background: #ccf; + border-top: solid 1px #aaa; + border-bottom: solid 1px #aaa; +} + +div#cgit table.ssdiff td.head { + border-top: solid 1px #aaa; + border-bottom: solid 1px #aaa; +} + +div#cgit table.ssdiff td.head div.head { + font-weight: bold; + color: black; +} + +div#cgit table.ssdiff td.foot { + border-top: solid 1px #aaa; + border-left: none; + border-right: none; + border-bottom: none; +} + +div#cgit table.ssdiff td.space { + border: none; +} + +div#cgit table.ssdiff td.space div { + min-height: 3em; +} + +@media only screen and (max-width: 800px) { + /* FORMS */ + /* hide forms */ + div#cgit td.form { + display: none; + } + + /* HEADER */ + /* wrap title text */ + div#cgit table#header td.main { + white-space: normal; + } + /* Don't display author (save space) */ + div#cgit table#header td.sub.right { + display: none; + } + + /* CONTENT */ + div#cgit div.content { + overflow-x: auto; + padding: 0.5em; + } + td.ls-mode { + white-space: nowrap; + } + + /* TABLES */ + div#cgit table.nowrap td { + white-space: normal; + } + div#cgit table.list td { + vertical-align: top; + } + div#cgit { + span.age-mins, span.age-hours, span.age-days, span.age-weeks, span.age-months, span.age-years { + white-space: nowrap; + } + } + + + /* PANEL ALIGNMENT */ + div#cgit div.cgit-panel { + float: left; + } +} \ No newline at end of file diff --git a/config/services/web/git/default.nix b/config/services/web/git/default.nix new file mode 100644 index 0000000..5223927 --- /dev/null +++ b/config/services/web/git/default.nix @@ -0,0 +1,49 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + scanPath = "/srv/git"; + gitconfig = '' + [safe] + directory = ${scanPath}/* + ''; +in +{ + services.cgit.default = { + enable = true; + inherit scanPath; + gitHttpBackend = { + enable = true; + checkExportOkFiles = false; + }; + nginx.virtualHost = "git"; + settings = { + head-include = "${./head.html}"; + root-title = "repositories"; + root-desc = "by Quentin Aristote"; + root-readme = "${./about.html}"; + source-filter = "${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py"; + clone-prefix = "https://git.aristote.fr"; + section-from-path = 1; + snapshots = "tar.gz tar.bz2 tar.xz"; # for nix support + enable-index-owner = 0; + }; + }; + + services.nginx.virtualHosts.git = { + serverName = "git.${config.networking.domain}"; + enableACME = true; + forceSSL = true; + locations."= /cgit.css".alias = lib.mkForce ./cgit.css; + }; + + # give access to the repos + users.users.cgit.extraGroups = [ "git" ]; + ## for the http backend + systemd.services.fcgiwrap-cgit-default.environment.XDG_CONFIG_HOME = + "${pkgs.writeTextDir "git/config" gitconfig}"; +} diff --git a/config/services/web/git/head.html b/config/services/web/git/head.html new file mode 100644 index 0000000..44dca77 --- /dev/null +++ b/config/services/web/git/head.html @@ -0,0 +1 @@ + diff --git a/config/services/web/quentin/default.nix b/config/services/web/quentin/default.nix new file mode 100644 index 0000000..7194190 --- /dev/null +++ b/config/services/web/quentin/default.nix @@ -0,0 +1,20 @@ +{ + config, + lib, + pkgs, + ... +}: { + services.nginx.virtualHosts.quentin = { + serverName = "quentin.${config.networking.domain}"; + locations."/".root = "${pkgs.personal.webpage}"; + forceSSL = true; + enableACME = true; + extraConfig = '' + add_header Cache-Control no-cache; + add_header Content-Security-Policy "default-src 'none'; form-action 'none'; frame-ancestors 'none'; font-src 'self'; img-src 'self'; style-src 'self' 'unsafe-inline';"; + ''; + }; + + # automatically fetch (non-structural) website updates when updating the system + personal.system.autoUpgrade.autoUpdateInputs = lib.mkOptionDefault ["personal-webpage/data"]; +} diff --git a/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php b/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php new file mode 100644 index 0000000..710f8e6 --- /dev/null +++ b/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php @@ -0,0 +1,39 @@ + [ + 'id' => [ + 'name' => 'Identifier', + 'type' => 'text', + 'description' => 'An identifier of the shape [a-z]-[0-9]*. Found at the end of the target URL.', + 'exampleValue' => 's-60040484' + ] + ] + ]; + + const XPATH_EXPRESSION_ITEM = '//div[@class="teaser-wrap"]/a'; + const XPATH_EXPRESSION_ITEM_TITLE = './@title'; + const XPATH_EXPRESSION_ITEM_URI = './@href'; + // not given + // const XPATH_EXPRESSION_ITEM_AUTHOR = + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/time/@datetime'; + // requires javascript + // const XPATH_EXPRESSION_ITEM_ENCLOSURES = './figure/img[2]/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './div[2]/span[1]/text()'; + + + public function getIcon() { + return 'https://learngerman.dw.com/favicon.png'; + } + + public function getSourceUrl() { + return self::URI . $this->getInput('id'); + } +} diff --git a/config/services/web/rss/FipAlbumsBridge.php b/config/services/web/rss/FipAlbumsBridge.php new file mode 100644 index 0000000..aa5e597 --- /dev/null +++ b/config/services/web/rss/FipAlbumsBridge.php @@ -0,0 +1,56 @@ + [ + 'category' => [ + 'name' => 'Category', + 'type' => 'text', + 'description' => 'See examples for available options.', + 'exampleValue' => 'can be empty, "selections" or "album-jazz-de-la-semaine"' + ] + ] + ]; + + const XPATH_EXPRESSION_ITEM = '//div[starts-with(@class, "CardSide ")]'; + const XPATH_EXPRESSION_ITEM_TITLE = './/a/@aria-label'; + const XPATH_EXPRESSION_ITEM_CONTENT = './/img/@alt'; + const XPATH_EXPRESSION_ITEM_URI = './/a/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './/div[starts-with(@class, "title-zone ")]/p[2]/text()'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/div[starts-with(@class, "AdditionalInfos ")]/p[1]/text()'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './/img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './/div[starts-with(@class, "AdditionalInfos ")]/p[2]/text()'; + + public function getSourceUrl() { + return self::URI . $this->getInput('category'); + } + + public function getIcon() { + return 'https://www.radiofrance.fr/dist/favicons/fip/favicon.png'; + } + + protected function formatItemTimestamp($value) { + $monthyear = explode(": ", $value)[1]; + return $GLOBALS['DATE_FORMATTER']->parse('1 ' . $monthyear); + } + + # enclosure links don't have an extension + protected function cleanMediaUrl($mediaUrl) { + return $mediaUrl; + } +} diff --git a/config/services/web/rss/MaisonDeLaRadioBridge.php b/config/services/web/rss/MaisonDeLaRadioBridge.php new file mode 100644 index 0000000..7fd4b4f --- /dev/null +++ b/config/services/web/rss/MaisonDeLaRadioBridge.php @@ -0,0 +1,137 @@ + array ( + 'type' => array( + 'name' => 'Type', + 'type' => 'list', + 'title' => 'Concert types.', + 'values' => array( + 'Tous' => 0, + 'Concert' => 2543, + 'Émission en public' => 1270, + 'Évènement' => 1273, + 'Rencontre' => 1272, + 'Exposition' => 1768, + 'Festival' => 2544, + 'Conert jeune public' => 1482 + ) + ), + 'genre' => array( + 'name' => 'Genre', + 'type' => 'list', + 'title' => 'Music genre.', + 'values' => array( + 'Tous' => 0, + 'Symphonique' => '1207', + 'Opéra' => '1212', + 'Musique baroque' => '1208', + 'Musique chorale' => '1211', + 'Musique de film' => '2542', + 'Récital et musique de chambre' => '1210', + 'Orgue' => '1214', + 'Jazz' => '1761', + 'Création contemporaine' => '1215', + 'Concert Jeune public' => '2584', + 'Tournée' => '2583', + 'Pop, rock et électro' => '2541', + 'Concert Fip' => '1225', + 'Atelier musical' => '1258', + 'Masterclasse' => '1251', + 'Concerts du soir et avant-concerts pour les scolaires' => '2560', + 'Concerts jeune public pour le champ social' =>'2581' + ) + ), + 'formation' => array( + 'name' => 'Formation', + 'type' => 'list', + 'title' => 'Performing formations.', + 'values' => array( + 'Tous' => 0, + 'Orchestre Philharmonique de Radio France' => '864%2B2660%2B3333', + 'Orchestre National de France' => '861%2B1786', + 'Chœur de Radio France' => '703%2B2946', + 'Maîtrise de Radio France' => '832%2B2947' + ) + ), + 'chef' => array( + 'name' => 'Chef', + 'type' => 'number', + 'title' => 'ID of the conductor (optional).', + 'exampleValue' => '53', + ), + 'compositeur' => array( + 'name' => 'Compositeur', + 'type' => 'number', + 'title' => 'ID of the composer (optional).', + 'exampleValue' => '131', + ), + 'soliste' => array( + 'name' => 'Soliste', + 'type' => 'number', + 'title' => 'ID of the solist (optional).', + 'exampleValue' => '3064', + ) + ) + ); + + public function getSourceUrl() { + $query = 'layout=row' . '&a-partir=' . date('Y-m-d'); + foreach(self::PARAMETERS[''] as $param => $paramSpec) { + $val = $this->getInput($param); + if($val != 0 && !is_null($val)) { + if($paramSpec['type'] == 'list') { + $assignmentOp = '[]='; + } else { + $assignmentOp = '='; + } + $query = $query . '&' . $param . $assignmentOp . $val; + } + } + return self::URI . '?' . $query; + } + + public function getIcon() { + return 'https://rf-maisondelaradio-production.s3.eu-west-3.amazonaws.com/s3fs-public/mdlrfavicon22.ico'; + } + + protected function getExpressionItemContent() { + return 'string(.//div[contains(@class, "Serif-small")])'; + } + protected function formatItemContent($value) { + $normalizedWhitespace = preg_replace('/\s\s+/m', ' ', $value); + return preg_replace('/\s*,/', ',', $normalizedWhitespace); + } + + protected function getExpressionItemTimestamp() { + return 'normalize-space(concat(string(' . self::XPATH_EXPRESSION_ITEM_TIMESTAMP . '), .//div[@class="d-flex flex-column"]/div[1]))'; + } + protected function formatItemTimestamp($value) { + return $GLOBALS['DATE_FORMATTER']->parse($value); + } +} diff --git a/config/services/web/rss/RandonavigoBridge.php b/config/services/web/rss/RandonavigoBridge.php new file mode 100644 index 0000000..ebc64c2 --- /dev/null +++ b/config/services/web/rss/RandonavigoBridge.php @@ -0,0 +1,33 @@ +/dev/null + echo Shutting down container ... + sudo nixos-container stop hermes +} + +pushd $(dirname $0) >/dev/null +echo Stopping container for update ... +sudo nixos-container stop hermes || exit 2 +echo Updating container ... +sudo nixos-container update hermes --flake .#hermes-test || exit 2 +echo Starting container ... +sudo nixos-container start hermes || exit 2 + +trap cleanup EXIT +sleep 0.1 +IP=$(nixos-container show-ip hermes) +CURL_FLAGS='--location --silent' + +echo +echo Checking that all the services are running: +declare -A PORTS +PORTS[quentin]=8080 +PORTS[rss]=8082 +PORTS[mesh]=8084 +PORTS[git]=8086 +declare -A SUFFIX +SUFFIX[quentin]="" +SUFFIX[rss]="" +SUFFIX[git]="?p=about" +SUFFIX[mesh]="health" + +for SERVICE in "${!PORTS[@]}" +do + URL="http://$IP:${PORTS[$SERVICE]}/${SUFFIX[$SERVICE]}" + echo Checking connection to container version of $SERVICE.aristote.fr ... + RESULT=$(curl "$URL" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + case "$RESULT" in + 200) echo "Up and running at $URL !";; + 301) echo "Redirected.";; + *) echo "Connection failed.";; + esac +done + + +echo +echo Checking web keys directory: +URL_PREFIX="http://$IP:8083/.well-known/openpgpkey/aristote.vm" +KEYS="$(ls ../config/services/web/webkeydirectory/hu)" +for KEY in $KEYS +do + echo Checking key $KEY ... + RESULT=$(curl "$URL_PREFIX/hu/$KEY" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + if [[ ! "$RESULT" = 200 ]] + then + echo "Connection failed." + fi +done +echo Checking policy file ... +RESULT=$(curl "$URL_PREFIX/policy" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') +if [[ ! "$RESULT" = 200 ]] +then + echo "Connection failed." +fi +echo Done. + + +echo +echo Checking custom RSS bridges: +BRIDGES="$(ls ../config/services/web/rss/*Bridge.php | xargs basename -s Bridge.php)" +for BRIDGE in $BRIDGES +do + echo Checking bridge $BRIDGE ... + RESULT=$(curl "http://$IP:${PORTS[rss]}/?action=display&bridge=$BRIDGE&format=Plaintext" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + if [[ ! "$RESULT" = 200 ]] + then + echo "Connection failed." + fi +done +echo Done. + + +# echo +# echo Checking custom Searx engines: +# declare -A QUERIES +# QUERIES[alternativeto]=Searx +# QUERIES[nlab]='Kan%20extension' +# QUERIES[wfr]=Paris +# QUERIES[wen]=Paris +# for ENGINE in "${!QUERIES[@]}" +# do +# echo Checking engine $ENGINE ... +# REQUEST_URL="http://$IP:${PORTS[searx]}/search?q=${QUERIES[$ENGINE]}+!$ENGINE&format=json" +# JSON_RESULT=$(curl "$REQUEST_URL" $CURL_FLAGS) +# RESULTS=$(echo $JSON_RESULT | jq '.results') +# UNRESPONSIVE_ENGINES=$(echo $JSON_RESULT | jq '.unresponsive_engines') +# if [[ ! "$UNRESPONSIVE_ENGINES" = '[]' ]] +# then +# echo "Engine not responsive." +# elif [[ "$RESULTS" = [] ]] +# then +# echo "No results found." +# fi +# done +# echo Done. + +echo +read -n1 -srp "Press any key to stop the server." -- cgit v1.3.1