From beaeecc5f25bea3e9eeb13d114b0dae4ef99e016 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Mon, 16 Feb 2026 06:59:21 +0100 Subject: [PATCH] switch to use immich-go toolkit --- hosts/darwin/home-default.nix | 1 - hosts/darwin/system-default.nix | 2 +- hosts/nixos/nfss/containers.nix | 3 +- hosts/nixos/nfss/home.nix | 11 ------- hosts/nixos/nfss/proxy.nix | 20 ++++++++++++ hosts/nixos/nfss/system.nix | 3 +- hosts/nixos/thinkpad/home.nix | 1 - modules/media/tool.nix | 57 ++++++++------------------------- modules/syncthing.nix | 1 - 9 files changed, 37 insertions(+), 62 deletions(-) diff --git a/hosts/darwin/home-default.nix b/hosts/darwin/home-default.nix index f455681..a9ed9b9 100644 --- a/hosts/darwin/home-default.nix +++ b/hosts/darwin/home-default.nix @@ -22,7 +22,6 @@ Credentials.enable = true; Documents.enable = true; Media.enable = true; - Consume.enable = true; Archive.enable = true; }; diff --git a/hosts/darwin/system-default.nix b/hosts/darwin/system-default.nix index 182c514..0703a34 100644 --- a/hosts/darwin/system-default.nix +++ b/hosts/darwin/system-default.nix @@ -101,7 +101,7 @@ screencapture = { disable-shadow = true; - location = "~/Consume/dcim"; + location = "~/Downloads"; type = "png"; show-thumbnail = true; }; diff --git a/hosts/nixos/nfss/containers.nix b/hosts/nixos/nfss/containers.nix index 36e88e6..4b74247 100644 --- a/hosts/nixos/nfss/containers.nix +++ b/hosts/nixos/nfss/containers.nix @@ -17,8 +17,7 @@ in volumes = [ "/var/lib/immich/config:/config" - "/var/lib/immich/photos:/photos" - "/mnt/storage/DCIM:/library:ro" + "/mnt/storage/photos:/photos" "${immichConfigFile}:/config/immich.json:ro" ]; diff --git a/hosts/nixos/nfss/home.nix b/hosts/nixos/nfss/home.nix index ec18a05..948c50d 100644 --- a/hosts/nixos/nfss/home.nix +++ b/hosts/nixos/nfss/home.nix @@ -5,7 +5,6 @@ ../home-default.nix ../../../modules/syncthing.nix ../../../modules/media/tool.nix - ../../../modules/schedule.nix ]; syncthing-custom.folders = { @@ -13,16 +12,6 @@ Documents = { enable = true; maxAgeDays = 30; }; Media = { enable = true; maxAgeDays = 7; }; Archive = { enable = true; maxAgeDays = 30; }; - Consume = { enable = true; maxAgeDays = 7; }; - }; - - services.scheduled-commands.dcim-consume = { - enable = true; - description = "Move files in dcim consume folder to DCIM"; - interval = "*-*-* *:00/15:00"; - commands = [ - "photo-move -d /home/yanlin/Consume/dcim /mnt/storage/DCIM" - ]; }; } diff --git a/hosts/nixos/nfss/proxy.nix b/hosts/nixos/nfss/proxy.nix index 9a3a96a..b905d37 100644 --- a/hosts/nixos/nfss/proxy.nix +++ b/hosts/nixos/nfss/proxy.nix @@ -27,6 +27,17 @@ }; }; + photo = { + rule = "Host(`photo.home.yanlincs.com`)"; + service = "photo"; + tls = { + certResolver = "cloudflare"; + domains = [{ + main = "*.home.yanlincs.com"; + }]; + }; + }; + }; services = { @@ -39,6 +50,15 @@ }; }; + photo = { + loadBalancer = { + serversTransport = "longTimeout"; + servers = [{ + url = "http://127.0.0.1:8080"; + }]; + }; + }; + }; }; diff --git a/hosts/nixos/nfss/system.nix b/hosts/nixos/nfss/system.nix index 63a6691..ce546a2 100644 --- a/hosts/nixos/nfss/system.nix +++ b/hosts/nixos/nfss/system.nix @@ -144,7 +144,6 @@ }; services.samba-custom.shares = { - DCIM = "/mnt/storage/DCIM"; Downloads = "/home/yanlin/Downloads"; }; @@ -153,7 +152,7 @@ enable = true; repositoryUrl = "ssh://helsinki-box/./nfss"; backupPaths = [ - "/mnt/storage/DCIM" + "/mnt/storage/photos/library" ]; backupFrequency = "*-*-* 01:00:00"; retention = { diff --git a/hosts/nixos/thinkpad/home.nix b/hosts/nixos/thinkpad/home.nix index cb1eab4..6d2c823 100644 --- a/hosts/nixos/thinkpad/home.nix +++ b/hosts/nixos/thinkpad/home.nix @@ -13,7 +13,6 @@ Documents = { enable = true; maxAgeDays = 30; }; Media = { enable = true; maxAgeDays = 7; }; Archive = { enable = true; maxAgeDays = 30; }; - Consume = { enable = true; maxAgeDays = 7; }; }; services.scheduled-commands.aicloud-backup = { diff --git a/modules/media/tool.nix b/modules/media/tool.nix index 9869dbf..9453a10 100644 --- a/modules/media/tool.nix +++ b/modules/media/tool.nix @@ -1,3 +1,5 @@ +# NOTE: Immich credentials file at: `~/.config/immich-env` with IMMICH_URL and IMMICH_APIKEY + { config, pkgs, lib, ... }: { @@ -11,6 +13,7 @@ p7zip imagemagick exiftool + immich-go ]; programs.zsh.initContent = '' @@ -118,56 +121,24 @@ done } - function photo-move() { - local mode=copy - if [[ "$1" == "-d" || "$1" == "--delete" ]]; then - mode=move; shift - elif [[ "$1" == "-l" || "$1" == "--link" ]]; then - mode=link; shift + function photo-upload() { + local envfile="$HOME/.config/immich-env" + if [[ ! -f "$envfile" ]]; then + echo "Missing $envfile" >&2 + return 1 fi - - if [[ $# -ne 2 ]]; then - echo "Usage: photo-move [-d|--delete|-l|--link] " - echo " -d, --delete Move files instead of copying" - echo " -l, --link Hardlink instead of copying" - echo " photo-move /Volumes/CAMERA/DCIM ~/DCIM" + source "$envfile" + if [[ -z "$IMMICH_URL" || -z "$IMMICH_APIKEY" ]]; then + echo "IMMICH_URL and IMMICH_APIKEY must be set in $envfile" >&2 return 1 fi - local src="$1" dest="$2" - - if [[ ! -d "$src" ]]; then - echo "Source not found: $src" >&2 + if [[ $# -eq 0 ]]; then + echo "Usage: photo-upload " >&2 return 1 fi - local name raw_date target - while IFS= read -r -d "" file; do - name=$(basename "$file") - [[ "$name" == .* ]] && continue - - raw_date=$(${pkgs.exiftool}/bin/exiftool -s3 -d '%Y-%m-%d' \ - -DateTimeOriginal -CreateDate -MediaCreateDate "$file" 2>/dev/null | head -1) - - if [[ ! "$raw_date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ || "$raw_date" == "0000-00-00" ]]; then - raw_date=$(${pkgs.coreutils}/bin/date -d "@$(${pkgs.coreutils}/bin/stat -c '%Y' "$file")" +%Y-%m-%d) - fi - - target="$dest/''${raw_date:0:4}/$raw_date" - mkdir -p "$target" - - [[ -e "$target/$name" ]] && continue - - case $mode in - move) mv "$file" "$target/$name" ;; - link) ln "$file" "$target/$name" ;; - *) cp -a "$file" "$target/$name" ;; - esac - done < <(find "$src" -type f \( \ - -iname "*.mp4" -o -iname "*.mov" -o -iname "*.mts" -o -iname "*.m2ts" -o -iname "*.avi" \ - -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.heic" -o -iname "*.heif" \ - -o -iname "*.cr2" -o -iname "*.cr3" -o -iname "*.nef" -o -iname "*.arw" -o -iname "*.dng" -o -iname "*.raf" -o -iname "*.orf" -o -iname "*.rw2" \ - \) -print0) + immich-go upload from-folder --server="$IMMICH_URL" --api-key="$IMMICH_APIKEY" "$1" } function extract() { diff --git a/modules/syncthing.nix b/modules/syncthing.nix index a8f5517..2a57b6c 100644 --- a/modules/syncthing.nix +++ b/modules/syncthing.nix @@ -43,7 +43,6 @@ in Documents = mkFolderOptions "Documents" { devices = pcDevices ++ serverDevices; }; Media = mkFolderOptions "Media" { devices = lib.filter (d: d != "iphone") allDevices; }; Archive = mkFolderOptions "Archive" {}; - Consume = mkFolderOptions "Consume" {}; }; enableGui = lib.mkOption { type = lib.types.bool;