mirror of
https://github.com/js0ny/dotfiles.git
synced 2026-03-21 18:26:20 +00:00
dot(cron): cleaner
This commit is contained in:
parent
877cabbb42
commit
127709614c
8 changed files with 221 additions and 3 deletions
|
|
@ -8,6 +8,7 @@
|
|||
pkgs.noto-fonts-color-emoji
|
||||
pkgs.nerd-fonts.jetbrains-mono
|
||||
pkgs.nur.repos.definfo.sarasa-term-sc-nerd
|
||||
pkgs.nur.repos.guanran928.harmonyos-sans
|
||||
pkgs.vollkorn
|
||||
pkgs.font-awesome
|
||||
];
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@
|
|||
pass
|
||||
# rar: Unfree, the only way (afaik) to unarchive some very old partition rars
|
||||
rar
|
||||
newsboat
|
||||
]
|
||||
++ (
|
||||
if pkgs.stdenv.isDarwin
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ in {
|
|||
(jetbrains.clion.override {
|
||||
vmopts = ''-Dawt.toolkit.name=WLToolkit'';
|
||||
})
|
||||
|
||||
seafile-client
|
||||
seadrive-gui
|
||||
seafile-shared
|
||||
]
|
||||
++ (mkFcitxIM [
|
||||
pkgs.neovim-qt
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ in {
|
|||
|
||||
fonts = {
|
||||
sansSerif = {
|
||||
package = pkgs.lxgw-neoxihei;
|
||||
name = "LXGW Neo XiHei";
|
||||
package = pkgs.nur.repos.guanran928.harmonyos-sans;
|
||||
name = "HarmonyOS Sans";
|
||||
};
|
||||
|
||||
serif = {
|
||||
|
|
@ -71,7 +71,7 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
base16Scheme = "${pkgs.base16-schemes}/share/themes/material-palenight.yaml";
|
||||
base16Scheme = "${pkgs.base16-schemes}/share/themes/tokyo-night-storm.yaml";
|
||||
image = ./wallpaper.jpg;
|
||||
polarity = "dark";
|
||||
};
|
||||
|
|
|
|||
14
nixcfgs/users/js0ny/programs/cleaner.nix
Normal file
14
nixcfgs/users/js0ny/programs/cleaner.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{config, ...}: {
|
||||
imports = [
|
||||
./lib-cleaner.nix
|
||||
];
|
||||
my.cleanup.jobs = {
|
||||
vicky3-crash-reports = {
|
||||
path = "${config.home.homeDirectory}/.local/share/Paradox Interactive/Victoria 3/crashes/";
|
||||
olderThan = 7;
|
||||
filesOnly = false;
|
||||
recursive = false;
|
||||
onCalendar = "weekly";
|
||||
};
|
||||
};
|
||||
}
|
||||
159
nixcfgs/users/js0ny/programs/lib-cleaner.nix
Normal file
159
nixcfgs/users/js0ny/programs/lib-cleaner.nix
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit
|
||||
(lib)
|
||||
mkOption
|
||||
mkIf
|
||||
types
|
||||
mapAttrs'
|
||||
nameValuePair
|
||||
optionalString
|
||||
escapeShellArg
|
||||
getExe
|
||||
;
|
||||
|
||||
cfg = config.my.cleanup;
|
||||
|
||||
jobType = types.submodule ({name, ...}: {
|
||||
options = {
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
description = "Directory to clean.";
|
||||
};
|
||||
|
||||
olderThan = mkOption {
|
||||
type = types.int;
|
||||
default = 7;
|
||||
description = "Delete entries older than this many days.";
|
||||
};
|
||||
|
||||
filesOnly = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Only delete regular files.";
|
||||
};
|
||||
|
||||
recursive = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether to recurse into subdirectories.";
|
||||
};
|
||||
|
||||
onCalendar = mkOption {
|
||||
type = types.str;
|
||||
default = "daily";
|
||||
description = "systemd timer schedule.";
|
||||
};
|
||||
|
||||
dryRun = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Print what would be deleted without deleting.";
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
mkCleanupScript = jobName: job:
|
||||
pkgs.writeShellApplication {
|
||||
name = "cleanup-${jobName}";
|
||||
runtimeInputs = with pkgs; [fd coreutils gnused];
|
||||
text = ''
|
||||
job_name=${escapeShellArg jobName}
|
||||
dir=${escapeShellArg job.path}
|
||||
dry_run=${
|
||||
if job.dryRun
|
||||
then "true"
|
||||
else "false"
|
||||
}
|
||||
|
||||
log() {
|
||||
printf '[cleanup:%s] %s\n' "$job_name" "$*"
|
||||
}
|
||||
|
||||
if [ ! -d "$dir" ]; then
|
||||
log "skip: directory does not exist: $dir"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "start"
|
||||
|
||||
cmd=(
|
||||
fd
|
||||
"." "$dir"
|
||||
"--hidden"
|
||||
"--no-ignore"
|
||||
${optionalString (!job.recursive) ''"--max-depth" "1"''}
|
||||
${optionalString job.filesOnly ''"--type" "file"''}
|
||||
"--changed-before" "${toString job.olderThan}d"
|
||||
"--absolute-path"
|
||||
)
|
||||
|
||||
count="$("''${cmd[@]}" --print0 | tr -dc '\0' | wc -c)"
|
||||
log "matched=$count"
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
log "nothing to do"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$dry_run" = "true" ]; then
|
||||
log "dry-run: matched entries:"
|
||||
"''${cmd[@]}" | sed 's/^/ /'
|
||||
log "done (dry-run)"
|
||||
else
|
||||
log "deleting matched entries..."
|
||||
# 批量安全删除
|
||||
"''${cmd[@]}" --print0 --exec-batch rm -rf --
|
||||
log "done"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in {
|
||||
options.my.cleanup.jobs = mkOption {
|
||||
type = types.attrsOf jobType;
|
||||
default = {};
|
||||
description = "Cleanup jobs.";
|
||||
};
|
||||
|
||||
config = mkIf (cfg.jobs != {}) {
|
||||
systemd.user.services =
|
||||
mapAttrs' (
|
||||
jobName: job:
|
||||
nameValuePair "cleanup-${jobName}" {
|
||||
Unit = {
|
||||
Description = "Cleanup job ${jobName}";
|
||||
};
|
||||
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = getExe (mkCleanupScript jobName job);
|
||||
};
|
||||
}
|
||||
)
|
||||
cfg.jobs;
|
||||
|
||||
systemd.user.timers =
|
||||
mapAttrs' (
|
||||
jobName: job:
|
||||
nameValuePair "cleanup-${jobName}" {
|
||||
Unit = {
|
||||
Description = "Timer for cleanup job ${jobName}";
|
||||
};
|
||||
|
||||
Timer = {
|
||||
OnCalendar = job.onCalendar;
|
||||
Persistent = true;
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = ["timers.target"];
|
||||
};
|
||||
}
|
||||
)
|
||||
cfg.jobs;
|
||||
};
|
||||
}
|
||||
38
nixcfgs/users/js0ny/programs/newsflash.nix
Normal file
38
nixcfgs/users/js0ny/programs/newsflash.nix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# TODO: Remove pkgs.newsflash in gui.nix once done.
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
mergetools = import ../../../../modules/lib/mergetools.nix {inherit pkgs lib config;};
|
||||
mkMergedJson = mergetools.mkMergedJson;
|
||||
newsflashConfig = mkMergedJson {
|
||||
name = "newsflash_gtk-config";
|
||||
target = "${config.home.homeDirectory}/.config/news-flash/newsflash_gtk.json";
|
||||
settings = {
|
||||
"general" = {
|
||||
};
|
||||
theme = "system";
|
||||
window_has_frame = false;
|
||||
release_channel = "latest";
|
||||
global_media_hotkeys = true;
|
||||
window_window_bar_style = "windows";
|
||||
disable_auto_updates = true;
|
||||
lyrics = [
|
||||
"NetEase"
|
||||
"lrclib.net"
|
||||
];
|
||||
# For window manager (hide on close)
|
||||
window_exit_to_tray = true;
|
||||
window_prevent_sleep_on_playback = true;
|
||||
};
|
||||
};
|
||||
in {
|
||||
home.packages = [
|
||||
pkgs.newsflash
|
||||
];
|
||||
imports = [
|
||||
newsflashConfig
|
||||
];
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
username = config.home.username;
|
||||
in {
|
||||
imports = [
|
||||
./programs/cleaner.nix
|
||||
# General config
|
||||
./default.nix
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue