mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 16:53:00 +00:00
feat(pdf2zh): pdf2zh podman definition and config
This commit is contained in:
parent
8cf2f0af5e
commit
5b546eff0d
10 changed files with 329 additions and 63 deletions
|
|
@ -1,14 +1,13 @@
|
|||
{...}: let
|
||||
editFzfPosix = ''
|
||||
edit-fzf() {
|
||||
# 1. Declare a variable that is local to the function.
|
||||
local _file
|
||||
|
||||
if command -v fd >/dev/null 2>&1; then
|
||||
_file=$(fd --type f | fzf --height 40% --reverse -1 -q "$1")
|
||||
_file=$(fd --type f --exclude '*.lock' | fzf --height 40% --reverse -1 -q "$1")
|
||||
else
|
||||
# Fallback to 'find'
|
||||
_file=$(find . -type f | fzf --height 40% --reverse -1 -q "$1")
|
||||
_file=$(find . -type f ! -name '*.lock' | fzf --height 40% --reverse -1 -q "$1")
|
||||
fi
|
||||
|
||||
# In POSIX shell, if fzf is cancelled (Esc/Ctrl-C),
|
||||
|
|
@ -34,9 +33,9 @@ in {
|
|||
set -l file
|
||||
|
||||
if command -q fd
|
||||
set file (fd --type f | fzf --height 40% --reverse -1 -q "$argv[1]")
|
||||
set file (fd --type f --exclude '*.lock' | fzf --height 40% --reverse -1 -q "$argv[1]")
|
||||
else
|
||||
set file (find . -type f | fzf --height 40% --reverse -1 -q "$argv[1]")
|
||||
set file (find . -type f ! -name '*.lock' | fzf --height 40% --reverse -1 -q "$argv[1]")
|
||||
end
|
||||
|
||||
set -l fzf_status $status
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
{pkgs, ...}: {
|
||||
home.packages = [pkgs.libreoffice];
|
||||
home.file.".local/share/kio/servicemenus/office2pdf.desktop" = {
|
||||
enable = true;
|
||||
executable = true;
|
||||
text = ''
|
||||
[Desktop Entry]
|
||||
Type=Service
|
||||
|
|
|
|||
52
nixcfgs/users/js0ny/programs/pdf2zh.nix
Normal file
52
nixcfgs/users/js0ny/programs/pdf2zh.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{pkgs, ...}: let
|
||||
imageTag = "ghcr.io/pdfmathtranslate/pdfmathtranslate-next";
|
||||
# version = "2.6.4";
|
||||
pdf2zhRunner = pkgs.writeShellScriptBin "pdf2zh" ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE_TAG="${imageTag}"
|
||||
|
||||
if ! podman image exists "$IMAGE_TAG"; then
|
||||
echo "[pdf2zh] Pulling image $IMAGE_TAG ..."
|
||||
podman pull "$IMAGE_TAG"
|
||||
fi
|
||||
|
||||
podman run --rm -it \
|
||||
-p 7860:7860 \
|
||||
-v "$(pwd):/data" \
|
||||
-w /data \
|
||||
"$IMAGE_TAG" "pdf2zh" "$@"
|
||||
'';
|
||||
descEn = "PDF scientific paper translation with preserved formats";
|
||||
descZh = "基于 AI 完整保留排版的 PDF 文档全文双语翻译";
|
||||
in {
|
||||
services.podman.enable = true;
|
||||
|
||||
# Declare an image, do not instantiate as a container
|
||||
services.podman.images.pdf2zh = {
|
||||
image = imageTag;
|
||||
description = " ${descEn} - ${descZh},支持 Google/DeepL/Ollama/OpenAI 等服务,提供 CLI/GUI/Docker";
|
||||
};
|
||||
|
||||
home.packages = [pdf2zhRunner];
|
||||
|
||||
home.file.".local/share/kio/servicemenus/pdf2zh.desktop" = {
|
||||
enable = true;
|
||||
executable = true;
|
||||
text = ''
|
||||
[Desktop Entry]
|
||||
Type=Service
|
||||
MimeType=application/pdf;
|
||||
Actions=translateToZh
|
||||
Icon=translate
|
||||
X-KDE-Priority=TopLevel
|
||||
X-KDE-StartupNotify=false
|
||||
|
||||
[Desktop Action translateToZh]
|
||||
Name=翻译为中文
|
||||
Icon=translate
|
||||
Exec=pdf2zh --openaicompatible "%f"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
@ -1,27 +1,28 @@
|
|||
{config, ...}: {
|
||||
{
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
home.packages = with pkgs; [
|
||||
sops
|
||||
];
|
||||
sops = {
|
||||
# enable = true;
|
||||
defaultSopsFile = ../../secrets/secrets.yaml;
|
||||
defaultSopsFile = ../../../secrets/secrets.yaml;
|
||||
age.keyFile = "${config.xdg.configHome}/sops/age/keys.txt";
|
||||
age.generateKey = true;
|
||||
secrets = {
|
||||
"OPENROUTER_API_KEY" = {
|
||||
key = "openrouter_api";
|
||||
};
|
||||
"TAVILY_API_KEY" = {
|
||||
key = "tavily_api";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# home.sessionVariables = {
|
||||
# OPENROUTER_API_KEY = config.sops.secrets."OPENROUTER_API_KEY".path;
|
||||
# };
|
||||
|
||||
systemd.user.services.sops-envvar = {
|
||||
Unit.Description = "[sops-envvar] Auto-source environment variables defined via sops-nix";
|
||||
Service = {
|
||||
ExecStart = pkgs.writeShellScript "start" ''
|
||||
export OPENROUTER_API_KEY=$(cat ${config.sops.secrets."OPENROUTER_API_KEY".path})
|
||||
'';
|
||||
};
|
||||
Install.WantedBy = ["default.target"];
|
||||
home.sessionVariables = {
|
||||
OPENROUTER_API_KEY = "$(cat ${config.sops.secrets."OPENROUTER_API_KEY".path})";
|
||||
TAVILY_API_KEY = "$(cat ${config.sops.secrets."TAVILY_API_KEY".path})";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
./programs/libreoffice.nix
|
||||
./programs/nvim.nix
|
||||
./programs/ollama.nix
|
||||
./programs/sops.nix
|
||||
./programs/pdf2zh.nix
|
||||
|
||||
# Desktop Linux
|
||||
./programs/desktop/plasma.nix
|
||||
|
|
@ -64,21 +66,5 @@
|
|||
rose-pine-cursor
|
||||
];
|
||||
|
||||
sops = {
|
||||
# enable = true;
|
||||
defaultSopsFile = ../../secrets/secrets.yaml;
|
||||
age.keyFile = "${config.xdg.configHome}/sops/age/keys.txt";
|
||||
age.generateKey = true;
|
||||
secrets = {
|
||||
"OPENROUTER_API_KEY" = {
|
||||
key = "openrouter_api";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
home.sessionVariables = {
|
||||
OPENROUTER_API_KEY = "$(cat ${config.sops.secrets."OPENROUTER_API_KEY".path})";
|
||||
};
|
||||
|
||||
home.stateVersion = "25.05";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue