1
1
Fork 0

Compare commits

...

3 Commits

3 changed files with 85 additions and 2 deletions

View File

@ -11,11 +11,12 @@
#./amanuensis.nix #./amanuensis.nix
./catacomb.nix ./catacomb.nix
./gitea.nix ./gitea.nix
./sync-pipeline.nix
]; ];
beatific.hostName = "empyrean"; beatific.hostName = "empyrean";
beatific.isLighthouse = true; beatific.isLighthouse = true;
beatific.defaults.tvbSync = false; beatific.defaults.tvbSync = true;
# Use the GRUB 2 boot loader. # Use the GRUB 2 boot loader.
boot.loader.grub = { boot.loader.grub = {
@ -39,6 +40,7 @@
networking.interfaces.eth0.useDHCP = true; networking.interfaces.eth0.useDHCP = true;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
exiftool
tinc_pre tinc_pre
gitea gitea
]; ];

View File

@ -0,0 +1,74 @@
{ pkgs, ... }:
# exiftool config and script based on that of @numinit
let
# An exiftool config that adds the OriginTimestamp property containing the best guess for file creation time
exiftool-config = pkgs.writeText "exiftool.config" ''
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
OriginTimestamp => {
Desire => {
0 => 'CreateDate',
1 => 'DateTimeOriginal',
2 => 'FileModifyDate'
},
ValueConv => '$val[0] || $val[1] || $val[2] || undef',
PrintConv => '$self->ConvertDateTime($val)',
PrintConvInv => '$self->InverseDateTime($val)'
}
}
)
'';
# A tool to use `find` and `exiftool` to sort images into YMD folders
sibd = pkgs.writeShellScriptBin "sort-images-by-date" ''
set -euo pipefail
if [ $# -lt 3 ]; then
echo "Usage: $0 [prefix] [src] [dest] [exiftool args...]" >&2
exit 1
fi
prefix="$1"
src="$2"
dest="$3"
# Remove $1, $2, $3 from $@ so the remainder can be passed to exiftool
shift; shift; shift
# This find expression matches .jpg/.png modified 14+ days ago.
# The -not (-name -prune) expressions exclude directories from the results by name.
# The exiftool command will move matched files to $dest/$prefix/year/month/day/filename.ext.
# -config loads the config defined above, which adds the OriginTimestamp composite property
# -filename tells exiftool to move each file to a new filename, $OriginTimestamp
# -d defines how the timestamp will be converted to a string, which ends up handling the pathing
${pkgs.findutils}/bin/find $src \
-not \( -name FalseKnees -prune \) \
-not \( -name Background -prune \) \
-type f \
-mtime +14 \
\( -name "*.jpg" -or -name "*.png" \) \
-exec ${pkgs.exiftool}/bin/exiftool \
-config ${exiftool-config} \
-api largefilesupport=1 \
-progress \
-filename'<OriginTimestamp' \
-d "''${dest}/''${prefix}/%Y-%m-%d/%%f%%-c.%%le" \
"$@" \
{} +
'';
# Script for cron jobs that sends output to journalctl -t sync-pipeline
sibd-cron = prefix: src: dest: pkgs.writeShellScript "sibd-cron" ''
${systemd}/bin/systemd-cat -t sync-pipeline ${sibd}/bin/sort-images-by-date ${prefix} ${src} ${dest}
'';
in {
environment.systemPackages = [ sort-images-by-date ];
services.cron = {
enable = true;
systemCronJobs = [
"0 0 * * 1 tvb ${sibd-cron "nokia" "/home/tvb/phone-sync/DCIM" "/home/tvb/phone-sync/staging"}"
"0 0 * * 1 tvb ${sibd-cron "nokia" "/home/tvb/phone-sync/Pictures" "/home/tvb/phone-sync/staging"}"
];
}

View File

@ -53,8 +53,15 @@ in {
# Options to always set # Options to always set
networking.hostName = cfg.hostName; networking.hostName = cfg.hostName;
nix.extraOptions = "experimental-features = nix-command flakes"; nix.extraOptions = "experimental-features = nix-command flakes";
# Link /etc/nixos to the flake source
environment.etc.nixos.source = ./..; environment.etc.nixos.source = ./..;
environment.shellAliases.nr = "sudo nixos-rebuild --flake $HOME/nixos-configs"; environment.shellAliases = {
# Shortcut for nixos-rebuild
nr = "sudo nixos-rebuild --flake $HOME/nixos-configs";
# Set some user-friendly defaults (use e.g. "command cp" to skip the alias)
# -r (recursively copy dirs) -p (preserve mode, ownership, timestamps)
cp = "cp -rp";
};
security.sudo.extraRules = [{ security.sudo.extraRules = [{
users = [ "tvb" ]; users = [ "tvb" ];
commands = [ { command = "/run/current-system/sw/bin/nixos-rebuild"; options = [ "NOPASSWD" ]; } ]; commands = [ { command = "/run/current-system/sw/bin/nixos-rebuild"; options = [ "NOPASSWD" ]; } ];