From df6db78f77ab7dce2fe66bb22de6484379a17f39 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Tue, 15 Mar 2022 18:43:27 -0700 Subject: [PATCH] Move downloads organizer to common configuration --- common/home.nix | 31 +++++++++++++++++++++++++++++++ hosts/main/home.nix | 32 -------------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/common/home.nix b/common/home.nix index ccbb2e0..885a664 100644 --- a/common/home.nix +++ b/common/home.nix @@ -117,6 +117,25 @@ let ${exiftool}/bin/exiftool -overwrite_original -TagsFromFile "$input" -all:all -ICC_Profile "$output" ''); + organize-downloads = pkgs.writeShellScriptBin "organize-downloads" (with pkgs; '' + set -Eeuo pipefail + shopt -s nullglob + + mkdir --parents --verbose '/home/ak/screenshots' + + for source in /home/ak/Downloads/Screen{s,\ S}hot\ *.png; do + while (( $(date +%s) - $(date '+%s' --reference "$source") <= 1 )); do + echo "Waiting for file to settle: $source" + sleep 1s + done + + destination="/home/ak/screenshots/$(basename "$source")" + + mv --no-clobber --verbose "$source" "$destination" + ${oxipng}/bin/oxipng --opt 'max' --strip 'safe' --interlace '0' "$destination" + done + ''); + palette = import ./palette.nix; in { @@ -134,6 +153,18 @@ in # User home.file.".face".source = ./andrew.jpg; + # Services + systemd.user.paths.organize-downloads = { + Unit.Description = "Watch downloads"; + Path.PathExistsGlob = "%h/Downloads/Screen{s,\\ S}hot\\ *.png"; + Install.WantedBy = [ "default.target" ]; + }; + systemd.user.services.organize-downloads = { + Unit.Description = "Organize downloads"; + Service.ExecStart = "${organize-downloads}/bin/organize-downloads"; + Service.Nice = 10; + }; + # Applications home.packages = with pkgs; [ darktable diff --git a/hosts/main/home.nix b/hosts/main/home.nix index f2ade47..af1485e 100644 --- a/hosts/main/home.nix +++ b/hosts/main/home.nix @@ -1,25 +1,5 @@ { config, lib, pkgs, ... }: -let - organize-downloads = pkgs.writeShellScriptBin "organize-downloads" (with pkgs; '' - set -Eeuo pipefail - shopt -s nullglob - - mkdir --parents --verbose '/home/ak/screenshots' - - for source in /home/ak/Downloads/Screen{s,\ S}hot\ *.png; do - while (( $(date +%s) - $(date '+%s' --reference "$source") <= 1 )); do - echo "Waiting for file to settle: $source" - sleep 1s - done - - destination="/home/ak/screenshots/$(basename "$source")" - - mv --no-clobber --verbose "$source" "$destination" - ${oxipng}/bin/oxipng --opt 'max' --strip 'safe' --interlace '0' "$destination" - done - ''); -in { imports = [ ../../common/home.nix @@ -37,18 +17,6 @@ in (builtins.readFile ../../common/Compose) + (builtins.readFile ./local/Compose); - # Services - systemd.user.paths.organize-downloads = { - Unit.Description = "Watch downloads"; - Path.PathExistsGlob = "%h/Downloads/Screen{s,\\ S}hot\\ *.png"; - Install.WantedBy = [ "default.target" ]; - }; - systemd.user.services.organize-downloads = { - Unit.Description = "Organize downloads"; - Service.ExecStart = "${organize-downloads}/bin/organize-downloads"; - Service.Nice = 10; - }; - # Applications home.packages = with pkgs; [ awscli2