1 { config, pkgs, lib, ... }:
4 cfg = config.services.yandex-disk;
6 dir = "/var/lib/yandex-disk";
8 u = if cfg.user != null then cfg.user else "yandexdisk";
18 services.yandex-disk = {
20 enable = lib.mkOption {
21 type = lib.types.bool;
24 Whether to enable Yandex-disk client. See https://disk.yandex.ru/
28 username = lib.mkOption {
32 Your yandex.com login name.
36 password = lib.mkOption {
40 Your yandex.com password. Warning: it will be world-readable in /nix/store.
46 type = lib.types.nullOr lib.types.str;
48 The user the yandex-disk daemon should run as.
52 directory = lib.mkOption {
53 type = lib.types.path;
54 default = "/home/Yandex.Disk";
55 description = "The directory to use for Yandex.Disk storage";
58 excludes = lib.mkOption {
60 type = lib.types.commas;
61 example = "data,backup";
63 Comma-separated list of directories which are excluded from synchronization.
74 config = lib.mkIf cfg.enable {
76 users.users = lib.mkIf (cfg.user == null) [ {
78 uid = config.ids.uids.yandexdisk;
83 systemd.services.yandex-disk = {
84 description = "Yandex-disk server";
86 after = [ "network.target" ];
88 wantedBy = [ "multi-user.target" ];
90 # FIXME: have to specify ${directory} here as well
91 unitConfig.RequiresMountsFor = dir;
94 mkdir -p -m 700 ${dir}
97 if ! test -d "${cfg.directory}" ; then
98 (mkdir -p -m 755 ${cfg.directory} && chown ${u} ${cfg.directory}) ||
102 ${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${u} \
103 -c '${pkgs.yandex-disk}/bin/yandex-disk token -p ${cfg.password} ${cfg.username} ${dir}/token'
105 ${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${u} \
106 -c '${pkgs.yandex-disk}/bin/yandex-disk start --no-daemon -a ${dir}/token -d ${cfg.directory} --exclude-dirs=${cfg.excludes}'