split home-manager into their own submodules
This commit is contained in:
25
modules/scripts/download/common.nix
Normal file
25
modules/scripts/download/common.nix
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
}:
|
||||
let
|
||||
inherit (inputs.jawz-scripts.packages.x86_64-linux) download;
|
||||
gallerySecretsPath = lib.attrByPath [ "sops" "secrets" "gallery-dl/secrets" "path" ] null config;
|
||||
in
|
||||
{
|
||||
inherit gallerySecretsPath;
|
||||
wrappedDownload =
|
||||
if gallerySecretsPath != null then
|
||||
pkgs.symlinkJoin {
|
||||
name = "download-with-secrets";
|
||||
paths = [ download ];
|
||||
buildInputs = [ pkgs.makeWrapper ];
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/download --run 'if [ -r "${gallerySecretsPath}" ]; then set -a; source "${gallerySecretsPath}"; set +a; fi'
|
||||
'';
|
||||
}
|
||||
else
|
||||
download;
|
||||
}
|
||||
25
modules/scripts/download/home.nix
Normal file
25
modules/scripts/download/home.nix
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
osConfig ? null,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
shellType = inputs.self.lib.hmShellType config osConfig;
|
||||
enabled =
|
||||
inputs.self.lib.hmOnlyUser config osConfig "jawz"
|
||||
&& (osConfig.my.units.download.enable || osConfig.my.units.downloadManga.enable);
|
||||
download = import ./common.nix {
|
||||
config = if osConfig == null then { } else osConfig;
|
||||
inherit inputs lib pkgs;
|
||||
};
|
||||
in
|
||||
{
|
||||
config = lib.mkIf enabled {
|
||||
programs.${shellType}.shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases {
|
||||
dl = "${download.wrappedDownload}/bin/download -u jawz -i";
|
||||
};
|
||||
};
|
||||
}
|
||||
95
modules/scripts/download/nixos.nix
Normal file
95
modules/scripts/download/nixos.nix
Normal file
@@ -0,0 +1,95 @@
|
||||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
download = import ./common.nix {
|
||||
inherit
|
||||
config
|
||||
inputs
|
||||
lib
|
||||
pkgs
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.my.units = {
|
||||
download.enable = lib.mkEnableOption "media download automation scripts";
|
||||
downloadManga.enable = lib.mkEnableOption "manga download automation";
|
||||
};
|
||||
config = {
|
||||
systemd.user = {
|
||||
services =
|
||||
let
|
||||
mkDownloadService = desc: execStartCmd: {
|
||||
restartIfChanged = true;
|
||||
description = "Downloads ${desc}";
|
||||
wantedBy = [ "default.target" ];
|
||||
path = [ pkgs.bash ];
|
||||
serviceConfig = {
|
||||
TimeoutStartSec = 2000;
|
||||
TimeoutStopSec = 2000;
|
||||
Restart = "on-failure";
|
||||
RestartSec = 30;
|
||||
ExecStart = "${download.wrappedDownload}/bin/download ${execStartCmd}";
|
||||
}
|
||||
// lib.optionalAttrs (download.gallerySecretsPath != null) {
|
||||
EnvironmentFile = download.gallerySecretsPath;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
tuhmayto = lib.mkIf config.my.units.download.enable (
|
||||
mkDownloadService "tuhmayto stuff" ''
|
||||
-u jawz -i https://x.com/tuhmayto/media \
|
||||
https://www.furaffinity.net/user/tuhmayto/ \
|
||||
https://bsky.app/profile/tumayto.bsky.social''
|
||||
);
|
||||
"download@" = lib.mkIf (config.my.units.download.enable || config.my.units.downloadManga.enable) (
|
||||
mkDownloadService "post from multiple sources" "%I"
|
||||
);
|
||||
"instagram@" = lib.mkIf config.my.units.download.enable (
|
||||
mkDownloadService "post types from instagram" "instagram -u jawz -t %I"
|
||||
);
|
||||
};
|
||||
timers =
|
||||
let
|
||||
downloadTimer = time: delay: {
|
||||
enable = true;
|
||||
description = "Downloads post types from different sites";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = time;
|
||||
RandomizedDelaySec = delay;
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
"download@main" = lib.mkIf config.my.units.download.enable (
|
||||
downloadTimer "*-*-* 06,18:02:00" 30 // { }
|
||||
);
|
||||
"download@push" = lib.mkIf config.my.units.download.enable (downloadTimer "*:0/5" 30 // { });
|
||||
"download@manga" = lib.mkIf config.my.units.downloadManga.enable (
|
||||
downloadTimer "*-*-* 03:08:00" 30 // { }
|
||||
);
|
||||
tuhmayto = lib.mkIf config.my.units.download.enable {
|
||||
enable = true;
|
||||
description = "Downloads tuhmayto stuff";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig.OnCalendar = "*:0/10";
|
||||
};
|
||||
};
|
||||
};
|
||||
my.scripts.download = {
|
||||
enable = lib.mkDefault false;
|
||||
install = true;
|
||||
service = false;
|
||||
name = "download";
|
||||
package = download.wrappedDownload;
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user