Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rclone helpers #1016

Merged
merged 11 commits into from
Jan 1, 2025
Merged
7 changes: 7 additions & 0 deletions config/rclone.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ echo "Mounting Google Drive on $mount_to"
rclone mount google-drive-Foo-Vault: "$mount_to" --vfs-cache-mode writes --log-level INFO
```

I don't use systemd in these operations to avoid the saving secrets in this repository.\
So use helper script `rclone-fzf` which is introduced in GH-1016.

### macOS

I don't use rclone in macOS. See GH-1016 and GH-911.

## GUI on Linux

Don't use <https://github.com/germanztz/gnome-shell-extension-rclone-manager> with the encrypted rclone config. (Looks like supporting, but I don't favor the [giving echo PASS](https://github.com/germanztz/gnome-shell-extension-rclone-manager/blob/72f1a2ac4a1205069bc2bda5d1e5906e83a2b4ab/fileMonitorHelper.js#L125) style as [written by rclone author](https://github.com/rclone/rclone/issues/7875#issuecomment-2155656214). And [cannot be intgerated with env style](https://github.com/germanztz/gnome-shell-extension-rclone-manager/blob/72f1a2ac4a1205069bc2bda5d1e5906e83a2b4ab/fileMonitorHelper.js#L594) of `RCLONE_PASSWORD_COMMAND` and `RCLONE_CONFIG_PASS`)
3 changes: 0 additions & 3 deletions home-manager/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@

STACK_XDG = "https://github.com/commercialhaskell/stack/blob/72f0a1273dd1121740501a159988fc23df2fb362/doc/stack_root.md?plain=1#L7-L11";

# Don't add needless quotation in the arguments. For example `gopass show 'rclone'` does not work. It should be `gopass show rclone`.
RCLONE_PASSWORD_COMMAND = "${lib.getExe pkgs.gopass} show rclone";

STARSHIP_CONFIG = "${../config/starship/starship.toml}";
};

Expand Down
54 changes: 33 additions & 21 deletions home-manager/linux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,46 @@
home = {
homeDirectory = lib.mkDefault "/home/${config.home.username}";

packages = with pkgs; [
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
glibc
sessionVariables = {
# Don't add needless quotation in the arguments. For example `gopass show 'rclone'` does not work. It should be `gopass show rclone`.
RCLONE_PASSWORD_COMMAND = "${lib.getExe pkgs.gopass} show rclone";
};

packages =
(with pkgs; [
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
glibc

# https://github.com/nix-community/home-manager/blob/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04/modules/services/ssh-agent.nix#L37
openssh
# https://github.com/nix-community/home-manager/blob/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04/modules/services/ssh-agent.nix#L37
openssh

iputils # `ping` etc
iputils # `ping` etc

# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/iw/iw/package.nix
iw # replacement of wireless-tools(iwconfig)
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/iw/iw/package.nix
iw # replacement of wireless-tools(iwconfig)

# - Enable special module for Nix OS.
# - Linux package does not contain podman-remote, you should install uidmap with apt and use this podman as actual engine
# https://github.com/NixOS/nixpkgs/blob/194846768975b7ad2c4988bdb82572c00222c0d7/pkgs/applications/virtualization/podman/default.nix#L112-L116
podman
podman-tui
docker-compose
rclone

kubectl
stern
unstable.k9s # https://github.com/NixOS/nixpkgs/pull/356238, https://github.com/NixOS/nixpkgs/pull/360993
# - Enable special module for Nix OS.
# - Linux package does not contain podman-remote, you should install uidmap with apt and use this podman as actual engine
# https://github.com/NixOS/nixpkgs/blob/194846768975b7ad2c4988bdb82572c00222c0d7/pkgs/applications/virtualization/podman/default.nix#L112-L116
podman
podman-tui
docker-compose

# Keybindigs: https://git.sr.ht/~bptato/chawan/tree/master/item/res/config.toml
chawan # `cha`
kubectl
stern
unstable.k9s # https://github.com/NixOS/nixpkgs/pull/356238, https://github.com/NixOS/nixpkgs/pull/360993

my.renmark # Depend on chawan
];
# Keybindigs: https://git.sr.ht/~bptato/chawan/tree/master/item/res/config.toml
chawan # `cha`
])
++ (with pkgs.my; [
renmark # Depend on chawan
rclone-list-mounted
rclone-mount
rclone-fzf
]);
};

# xdg-user-dirs NixOS module does not work or is not enough for me to keep English dirs even in Japanese locale.
Expand Down
2 changes: 0 additions & 2 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@

pastel

rclone

# How to get the installed font names
# fontconfig by nix: `fc-list : family style`
# darwin: system_profiler SPFontsDataType
Expand Down
1 change: 1 addition & 0 deletions nixos/desktop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
evince # document viewer
gnome-calendar
gnome-music # does not support flac by defaults
gnome-online-accounts # See GH-1015
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still appeared in UI 🤔

];

# Recommended to be uninstalled by gnupg. I prefer this way, even though disabling gpg-agent ssh integrations.
Expand Down
9 changes: 8 additions & 1 deletion pkgs/fzf.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

- `--preview`: the placeholder will be quoted by singlequote, so do not add excess double quote as "{}". This will be evaluated the given `` and $()
- `--nth`: Match there
- `--with-nth`: Whole display and outputs. None of only outputs: See <https://github.com/junegunn/fzf/issues/1323>
- `--with-nth`: Whole display and outputs.
- `--bind 'enter:become(...)'`: Replace process, and no execution if not match
- `--ansi`: Handle colored input, but remember the output is dirty with the ANSI for another tools. You may need strip them before use.

## Traps

- Cannot copy from preview window
- `become` with `export -f the_func` is broken in darwin. Create another command and inejct it
- [No feature to output only nth](https://github.com/junegunn/fzf/issues/1323)
- [No multiple modifiers for binding](https://github.com/junegunn/fzf/pull/3996)
11 changes: 11 additions & 0 deletions pkgs/rclone-fzf/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs, ... }:
pkgs.writeShellApplication rec {
name = "rclone-fzf";
text = builtins.readFile ./${name}.bash;
runtimeInputs = with pkgs; [
fzf
rclone
my.rclone-mount
my.rclone-list-mounted
];
}
18 changes: 18 additions & 0 deletions pkgs/rclone-fzf/rclone-fzf.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if [ $# -ge 1 ]; then
query="$1"
else
query=""
fi

# Don't use --preview for this. It omits some columns, and this will not be changed with selected entry
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And cannot copy from the preview window

rclone-list-mounted >&2

# Don't use rclone in fzf --preview, it runs query and be slow
rclone listremotes | fzf --query "$query" --border-label '☁️ Rclone Remotes' \
--layout=reverse --height=85% --min-height=20 --border \
--border-label-pos=2 \
--color='header:italic:underline,label:blue' \
--header $'Ctrl-/ (Mount) / Alt-A (Inspect)\n\n' \
--bind 'ctrl-/:become(rclone-mount {})' \
--bind 'alt-a:become(rclone about {})' \
--bind 'enter:become(echo {})'
1 change: 1 addition & 0 deletions pkgs/rclone-list-mounted/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs, ... }: pkgs.writers.writeNuBin "rclone-list-mounted" (builtins.readFile ./script.nu)
2 changes: 2 additions & 0 deletions pkgs/rclone-list-mounted/script.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't use mount command to support darwin with same implementation
ps --long | where name =~ rclone and command =~ mount | select pid ppid command | upsert command { |row| $row.command | parse --regex '\A\S+rclone\S+ mount (?<remote>\S+?:) (?P<local>\S+)' } | flatten -a | select remote local pid
11 changes: 11 additions & 0 deletions pkgs/rclone-mount/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs, lib, ... }:
pkgs.writeShellApplication rec {
name = "rclone-mount";
text = builtins.readFile ./${name}.bash;
runtimeInputs = with pkgs; [
coreutils # `mktemp`
rclone
];
# Didn't work on Darwin. It might work when disabling --daemon or replacing the default NFS with FUSE. However, I'm very tired to consider Darwin.
meta.platforms = lib.platforms.linux;
}
11 changes: 11 additions & 0 deletions pkgs/rclone-mount/rclone-mount.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rclone-mount() {
local -r remote="$1" # e.g `foo:`
# TODO: Return the path if already mounted the remote
local -r mount_to="$(mktemp --tmpdir --directory "rclone.${remote%:}.XXXX")"
# Use `kill``, not `kill -9`. If exists the garbages in `mount --types fuse.rclone`, `fusermount -u THE_PATH`
# See https://www.reddit.com/r/rclone/comments/nh576p/how_to_stop_an_rclone_daemon/
rclone mount "$remote" "$mount_to" --vfs-cache-mode writes --daemon
echo "$mount_to"
}

rclone-mount "$@"
Loading