1 { config, pkgs, lib, ... }:
7 cfg = config.services.yandex-disk;
9 dir = "/var/lib/yandex-disk";
11 u = if cfg.user != null then cfg.user else "yandexdisk";
21 services.yandex-disk = {
26 description = lib.mdDoc ''
27 Whether to enable Yandex-disk client. See https://disk.yandex.ru/
34 description = lib.mdDoc ''
35 Your yandex.com login name.
42 description = lib.mdDoc ''
43 Your yandex.com password. Warning: it will be world-readable in /nix/store.
49 type = types.nullOr types.str;
50 description = lib.mdDoc ''
51 The user the yandex-disk daemon should run as.
55 directory = mkOption {
57 default = "/home/Yandex.Disk";
58 description = lib.mdDoc "The directory to use for Yandex.Disk storage";
64 example = "data,backup";
65 description = lib.mdDoc ''
66 Comma-separated list of directories which are excluded from synchronization.
77 config = mkIf cfg.enable {
79 users.users = mkIf (cfg.user == null) [ {
81 uid = config.ids.uids.yandexdisk;
86 systemd.services.yandex-disk = {
87 description = "Yandex-disk server";
89 after = [ "network.target" ];
91 wantedBy = [ "multi-user.target" ];
93 # FIXME: have to specify ${directory} here as well
94 unitConfig.RequiresMountsFor = dir;
97 mkdir -p -m 700 ${dir}
100 if ! test -d "${cfg.directory}" ; then
101 (mkdir -p -m 755 ${cfg.directory} && chown ${u} ${cfg.directory}) ||
105 ${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${u} \
106 -c '${pkgs.yandex-disk}/bin/yandex-disk token -p ${cfg.password} ${cfg.username} ${dir}/token'
108 ${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${u} \
109 -c '${pkgs.yandex-disk}/bin/yandex-disk start --no-daemon -a ${dir}/token -d ${cfg.directory} --exclude-dirs=${cfg.excludes}'