Rclone: Difference between revisions
No edit summary |
Proper way of writing in xdg config directory |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
== Configuration == | == Configuration == | ||
Mounting remote filesystem, in this example via SFTP. The remote profile is called <code>myremote</code>, and authentication is done with user <code>myuser</code> and key file <code>/root/.ssh/id_rsa</code> against <code>192.0.2.2</code>. The remote directory <code>/my_data</code> is then mounted to the local directory <code>/mnt</code>.<syntaxhighlight lang="nix"> | |||
environment.systemPackages = [ pkgs.rclone ]; | |||
environment.etc."rclone-mnt.conf".text = '' | |||
[myremote] | |||
type = sftp | |||
host = 192.0.2.2 | |||
user = myuser | |||
key_file = /root/.ssh/id_rsa | |||
''; | |||
[[Category:Applications]] | fileSystems."/mnt" = { | ||
device = "myremote:/my_data"; | |||
fsType = "rclone"; | |||
options = [ | |||
"nodev" | |||
"nofail" | |||
"allow_other" | |||
"args2env" | |||
"config=/etc/rclone-mnt.conf" | |||
]; | |||
}; | |||
</syntaxhighlight>This can be also done with [[SSHFS]] while Rclone seems to be more robust for unstable connections. | |||
== Configuration with Home-Manager == | |||
Home-manager users may wish to make a user-centric configuration of rclone. To do so add <code>pkgs.rclone</code> to your <code>~/.config/home-manager/home.nix</code> file. You can also configure remotes with home-manager. Here is an example below.<syntaxhighlight lang="nix"> | |||
home.packages = [ pkgs.rclone ]; | |||
xdg.configFile."rclone/rclone.conf".text = '' | |||
[fichier] | |||
type = fichier | |||
user = foo@bar.com | |||
pass = password | |||
''; | |||
</syntaxhighlight> | |||
Particular concern should be made when uploading such configurations online as your passwords will be plainly visible. It is recommended to instead put the passwords in a local file if such is needed. Keep in mind that if you do output to .config/rclone/rclone.conf, every time you switch your home-manager configuration it will be overwritten. It would be wiser to instead output to a separate file, especially if using systemd services as in the example below. | |||
<syntaxhighlight lang="nix"> | |||
xdg.configFile."rclone/example.conf".text = '' | |||
[fichier] | |||
type = fichier | |||
user = foo@bar.com | |||
pass = p4ssw0rd | |||
''; | |||
}; | |||
systemd.user.services.example-mounts = { | |||
Unit = { | |||
Description = "Example programmatic mount configuration with nix and home-manager."; | |||
After = [ "network-online.target" ]; | |||
}; | |||
Service = { | |||
Type = "notify"; | |||
ExecStartPre = "/usr/bin/env mkdir -p %h/Example Sync Dir"; | |||
ExecStart = "${pkgs.rclone}/bin/rclone --config=%h/.config/rclone/example.conf --vfs-cache-mode writes --ignore-checksum mount \"fichier:\" \"Example Sync Dir\""; | |||
ExecStop="/bin/fusermount -u %h/Example Sync Dir/%i"; | |||
}; | |||
Install.WantedBy = [ "default.target" ]; | |||
}; | |||
</syntaxhighlight> | |||
[[Category:Applications]] | |||
[[Category:Backup]] | [[Category:Backup]] |