at 16.09-beta 2.1 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.yandex-disk; 8 9 dir = "/var/lib/yandex-disk"; 10 11 u = if cfg.user != null then cfg.user else "yandexdisk"; 12 13in 14 15{ 16 17 ###### interface 18 19 options = { 20 21 services.yandex-disk = { 22 23 enable = mkOption { 24 default = false; 25 description = " 26 Whether to enable Yandex-disk client. See https://disk.yandex.ru/ 27 "; 28 }; 29 30 username = mkOption { 31 default = ""; 32 type = types.string; 33 description = '' 34 Your yandex.com login name. 35 ''; 36 }; 37 38 password = mkOption { 39 default = ""; 40 type = types.string; 41 description = '' 42 Your yandex.com password. Warning: it will be world-readable in /nix/store. 43 ''; 44 }; 45 46 user = mkOption { 47 default = null; 48 description = '' 49 The user the yandex-disk daemon should run as. 50 ''; 51 }; 52 53 directory = mkOption { 54 default = "/home/Yandex.Disk"; 55 description = "The directory to use for Yandex.Disk storage"; 56 }; 57 58 }; 59 60 }; 61 62 63 ###### implementation 64 65 config = mkIf cfg.enable { 66 67 users.extraUsers = mkIf (cfg.user == null) [ { 68 name = u; 69 uid = config.ids.uids.yandexdisk; 70 group = "nogroup"; 71 home = dir; 72 } ]; 73 74 systemd.services.yandex-disk = { 75 description = "Yandex-disk server"; 76 77 after = [ "network.target" ]; 78 79 wantedBy = [ "multi-user.target" ]; 80 81 # FIXME: have to specify ${directory} here as well 82 unitConfig.RequiresMountsFor = dir; 83 84 script = '' 85 mkdir -p -m 700 ${dir} 86 chown ${u} ${dir} 87 88 if ! test -d "${cfg.directory}" ; then 89 mkdir -p -m 755 ${cfg.directory} || 90 exit 1 91 fi 92 93 ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${u} \ 94 -c '${pkgs.yandex-disk}/bin/yandex-disk token -p ${cfg.password} ${cfg.username} ${dir}/token' 95 96 ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${u} \ 97 -c '${pkgs.yandex-disk}/bin/yandex-disk start --no-daemon -a ${dir}/token -d ${cfg.directory}' 98 ''; 99 100 }; 101 }; 102 103} 104