diff options
author | Sergey Mironov <grrwlf@gmail.com> | 2014-03-30 00:07:31 +0400 |
---|---|---|
committer | Michael Raskin <7c6f434c@mail.ru> | 2014-09-03 12:36:29 +0400 |
commit | 2b72edad9b3c2426600b27e48e70f2e038382313 (patch) | |
tree | a4da10bbc9816a1a31fa7e46308de1f8048dace2 /nixos | |
parent | 56102642fa957ab1c7c3b22675ae0113303097f4 (diff) | |
download | nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar.gz nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar.bz2 nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar.lz nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar.xz nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.tar.zst nixlib-2b72edad9b3c2426600b27e48e70f2e038382313.zip |
yandex-disk: fix the url; introduce systemd.service #2228
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/misc/ids.nix | 1 | ||||
-rwxr-xr-x | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/network-filesystems/yandex-disk.nix | 104 |
3 files changed, 106 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index d72649cd33d4..a535a8d7604e 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -150,6 +150,7 @@ zookeeper = 140; dnsmasq = 141; uhub = 142; + yandexdisk=143; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7679d3e6ac44..1135534263c6 100755 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -193,6 +193,7 @@ ./services/network-filesystems/rsyncd.nix ./services/network-filesystems/samba.nix ./services/network-filesystems/diod.nix + ./services/network-filesystems/yandex-disk.nix ./services/networking/amuled.nix ./services/networking/atftpd.nix ./services/networking/avahi-daemon.nix diff --git a/nixos/modules/services/network-filesystems/yandex-disk.nix b/nixos/modules/services/network-filesystems/yandex-disk.nix new file mode 100644 index 000000000000..df9626d17c92 --- /dev/null +++ b/nixos/modules/services/network-filesystems/yandex-disk.nix @@ -0,0 +1,104 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.services.yandex-disk; + + dir = "/var/lib/yandex-disk"; + + u = if cfg.user != null then cfg.user else "yandexdisk"; + +in + +{ + + ###### interface + + options = { + + services.yandex-disk = { + + enable = mkOption { + default = false; + description = " + Whether to enable Yandex-disk client. See https://disk.yandex.ru/ + "; + }; + + username = mkOption { + default = ""; + type = types.string; + description = '' + Your yandex.com login name. + ''; + }; + + password = mkOption { + default = ""; + type = types.string; + description = '' + Your yandex.com password. Warning: it will be world-readable in /nix/store. + ''; + }; + + user = mkOption { + default = null; + description = '' + The user the yandex-disk daemon should run as. + ''; + }; + + directory = mkOption { + default = "/home/Yandex.Disk"; + description = "The directory to use for Yandex.Disk storage"; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + users.extraUsers = mkIf (cfg.user == null) [ { + name = u; + uid = config.ids.uids.yandexdisk; + group = "nogroup"; + home = dir; + } ]; + + systemd.services.yandex-disk = { + description = "Yandex-disk server"; + + after = [ "network.target" ]; + + wantedBy = [ "multi-user.target" ]; + + # FIXME: have to specify ${directory} here as well + unitConfig.RequiresMountsFor = dir; + + script = '' + mkdir -p -m 700 ${dir} + chown ${u} ${dir} + + if ! test -d "${cfg.directory}" ; then + mkdir -p -m 755 ${cfg.directory} || + exit 1 + fi + + ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${u} \ + -c '${pkgs.yandex-disk}/bin/yandex-disk token -p ${cfg.password} ${cfg.username} ${dir}/token' + + ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${u} \ + -c '${pkgs.yandex-disk}/bin/yandex-disk start --no-daemon -a ${dir}/token -d ${cfg.directory}' + ''; + + }; + }; + +} + |