1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

rclone: add module

Rclone is a command-line program to manage files on cloud storage, it
also featrues support for FUSE mounts.

"Users call rclone *"The Swiss army knife of cloud storage"* and
*"Technology indistinguishable from magic"*" - https://rclone.org/

This module manages the configuration of rclone remotes.
This commit is contained in:
Jess 2024-12-05 00:01:16 +13:00 committed by Austin Horstman
parent 66f565db48
commit eb5d59dac9
9 changed files with 287 additions and 0 deletions

View file

@ -15,6 +15,7 @@ let
mu = runTest ./standalone/mu;
nh = runTest ./standalone/nh.nix;
nixos-basics = runTest ./nixos/basics.nix;
rclone = runTest ./standalone/rclone;
standalone-flake-basics = runTest ./standalone/flake-basics.nix;
standalone-standard-basics = runTest ./standalone/standard-basics.nix;
};

View file

@ -0,0 +1,91 @@
{ pkgs, ... }:
{
name = "rclone";
nodes.machine = { ... }: {
imports = [ "${pkgs.path}/nixos/modules/installer/cd-dvd/channel.nix" ];
virtualisation.memorySize = 2048;
users.users.alice = {
isNormalUser = true;
description = "Alice Foobar";
password = "foobar";
uid = 1000;
};
};
testScript = ''
start_all()
machine.wait_for_unit("network.target")
machine.wait_for_unit("multi-user.target")
home_manager = "${../../../..}"
def login_as_alice():
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("foobar\n")
machine.wait_until_tty_matches("1", "alice\\@machine")
def logout_alice():
machine.send_chars("exit\n")
def alice_cmd(cmd):
return f"su -l alice --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"
def succeed_as_alice(*cmds):
return machine.succeed(*map(alice_cmd,cmds))
def fail_as_alice(*cmds):
return machine.fail(*map(alice_cmd,cmds))
# Create a persistent login so that Alice has a systemd session.
login_as_alice()
# Set up a home-manager channel.
succeed_as_alice(" ; ".join([
"mkdir -p /home/alice/.nix-defexpr/channels",
f"ln -s {home_manager} /home/alice/.nix-defexpr/channels/home-manager"
]))
with subtest("Home Manager installation"):
succeed_as_alice("nix-shell \"<home-manager>\" -A install")
succeed_as_alice("cp ${
./home.nix
} /home/alice/.config/home-manager/home.nix")
with subtest("Generate with no secrets"):
succeed_as_alice("install -m644 ${
./no-secrets.nix
} /home/alice/.config/home-manager/test-remote.nix")
actual = succeed_as_alice("home-manager switch")
expected = "Activating createRcloneConfig"
assert expected in actual, \
f"expected home-manager switch to contain {expected}, but got {actual}"
succeed_as_alice("diff -u ${
./no-secrets.conf
} /home/alice/.config/rclone/rclone.conf")
with subtest("Generate with secrets from store"):
succeed_as_alice("install -m644 ${
./with-secrets-in-store.nix
} /home/alice/.config/home-manager/test-remote.nix")
actual = succeed_as_alice("home-manager switch")
expected = "Activating createRcloneConfig"
assert expected in actual, \
f"expected home-manager switch to contain {expected}, but got {actual}"
succeed_as_alice("diff -u ${
./with-secrets-in-store.conf
} /home/alice/.config/rclone/rclone.conf")
# TODO: verify correct activation order with the agenix and sops hm modules
logout_alice()
'';
}

View file

@ -0,0 +1,13 @@
{
imports = [ ./test-remote.nix ];
home.username = "alice";
home.homeDirectory = "/home/alice";
home.stateVersion = "24.05"; # Please read the comment before changing.
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
programs.rclone.enable = true;
}

View file

@ -0,0 +1,5 @@
[alices-cool-remote]
host=backup-server
key_file=/key/path/foo
type=sftp
user=alice

View file

@ -0,0 +1,10 @@
{
programs.rclone.remotes = {
alices-cool-remote.config = {
type = "sftp";
host = "backup-server";
user = "alice";
key_file = "/key/path/foo";
};
};
}

View file

@ -0,0 +1,6 @@
[alices-cool-remote-v2]
hard_delete = true
type = b2
account = super-secret-account-id
key = api-key-from-file

View file

@ -0,0 +1,18 @@
{ pkgs, ... }: {
programs.rclone.remotes = {
alices-cool-remote-v2 = {
config = {
type = "b2";
hard_delete = true;
};
secrets = {
account = "${pkgs.writeText "acc" ''
super-secret-account-id
''}";
key = "${pkgs.writeText "key" ''
api-key-from-file
''}";
};
};
};
}