From 2b72edad9b3c2426600b27e48e70f2e038382313 Mon Sep 17 00:00:00 2001 From: Sergey Mironov Date: Sun, 30 Mar 2014 00:07:31 +0400 Subject: [PATCH] yandex-disk: fix the url; introduce systemd.service #2228 --- nixos/modules/misc/ids.nix | 1 + nixos/modules/module-list.nix | 1 + .../network-filesystems/yandex-disk.nix | 104 ++++++++++++++++++ .../tools/filesystems/yandex-disk/default.nix | 6 +- 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 nixos/modules/services/network-filesystems/yandex-disk.nix 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}' + ''; + + }; + }; + +} + diff --git a/pkgs/tools/filesystems/yandex-disk/default.nix b/pkgs/tools/filesystems/yandex-disk/default.nix index c9078a0cb8be..e33f46ea9ccd 100644 --- a/pkgs/tools/filesystems/yandex-disk/default.nix +++ b/pkgs/tools/filesystems/yandex-disk/default.nix @@ -6,17 +6,17 @@ let p = if stdenv.is64bit then { arch = "x86_64"; gcclib = "${stdenv.gcc.gcc}/lib64"; - sha256 = "1fmmlvvh97d60n9k08bn4k6ghwr3yhs8sib82025nwpw1sq08vim"; + sha256 = "09kw7f0qsvx3vx1c1zb117yf3yk7kkz66agspz5xx9b0zh6i82jw"; } else { arch = "i386"; gcclib = "${stdenv.gcc.gcc}/lib"; - sha256 = "3940420bd9d1fe1ecec1a117bfd9d21d545bca59f5e0a4364304ab808c976f7f"; + sha256 = "0f2230c91120f05159281b39c620ab6bad6559ce8a17a0874d0a82350ebba426"; }; in stdenv.mkDerivation rec { - name = "yandex-disk-0.1.2.481"; + name = "yandex-disk-0.1.4.504"; src = fetchurl { url = "http://repo.yandex.ru/yandex-disk/rpm/stable/${p.arch}/${name}-1.fedora.${p.arch}.rpm";