From a3b0864bb0573b571f1eb53127be8003c3ede1b7 Mon Sep 17 00:00:00 2001 From: _ Date: Mon, 29 Jun 2020 19:56:41 +0530 Subject: [PATCH] nixos/onedrive: init --- nixos/modules/module-list.nix | 1 + .../modules/services/networking/onedrive.nix | 72 +++++++++++++++++++ .../modules/services/networking/onedrive.xml | 34 +++++++++ 3 files changed, 107 insertions(+) create mode 100644 nixos/modules/services/networking/onedrive.nix create mode 100644 nixos/modules/services/networking/onedrive.xml diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index cf25ae3157e6..cf1ee0f380cb 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -686,6 +686,7 @@ ./services/networking/ocserv.nix ./services/networking/ofono.nix ./services/networking/oidentd.nix + ./services/networking/onedrive.nix ./services/networking/openfire.nix ./services/networking/openvpn.nix ./services/networking/ostinato.nix diff --git a/nixos/modules/services/networking/onedrive.nix b/nixos/modules/services/networking/onedrive.nix new file mode 100644 index 000000000000..a945250fa9e6 --- /dev/null +++ b/nixos/modules/services/networking/onedrive.nix @@ -0,0 +1,72 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.services.onedrive; + + onedriveLauncher = pkgs.writeShellScriptBin + "onedrive-launcher" + '' + # XDG_CONFIG_HOME is not recognized in the environment here. + if [ -f $HOME/.config/onedrive-launcher ] + then + # Hopefully using underscore boundary helps locate variables + for _onedrive_config_dirname_ in $(cat $HOME/.config/onedrive-launcher | grep -v '[ \t]*#' ) + do + systemctl --user start onedrive@$_onedrive_config_dirname_ + done + else + systemctl --user start onedrive@onedrive + fi + '' + ; + +in { + ### Documentation + # meta.doc = ./onedrive.xml; + + ### Interface + + options.services.onedrive = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable OneDrive service"; + }; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.onedrive; + defaultText = "pkgs.onedrive"; + example = lib.literalExample "pkgs.onedrive"; + description = '' + OneDrive package to use. + ''; + }; + }; +### Implementation + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + + systemd.user.services."onedrive@" = { + description = "Onedrive sync service"; + + serviceConfig = { + Type = "simple"; + ExecStart = '' + ${cfg.package}/bin/onedrive --monitor --verbose --confdir=%h/.config/%i + ''; + Restart="on-failure"; + RestartSec=3; + RestartPreventExitStatus=3; + }; + }; + + systemd.user.services.onedrive-launcher = { + wantedBy = [ "default.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${onedriveLauncher}/bin/onedrive-launcher"; + }; + }; + }; +} diff --git a/nixos/modules/services/networking/onedrive.xml b/nixos/modules/services/networking/onedrive.xml new file mode 100644 index 000000000000..5a9dcf01aeee --- /dev/null +++ b/nixos/modules/services/networking/onedrive.xml @@ -0,0 +1,34 @@ + + Microsoft OneDrive + + Microsoft Onedrive is a popular cloud file-hosting service, used by 85% of Fortune 500 companies. NixOS uses a popular OneDrive client for Linux maintained by github user abraunegg. The Linux client is excellent and allows customization of which files or paths to download, not much unlike the default Windows OneDrive client by Microsoft itself. The client allows syncing with multiple onedrive accounts at the same time, of any type- OneDrive personal, OneDrive business, Office365 and Sharepoint libraries, without any additional charge. + + + For more information, guides and documentation, see . + + + To enable OneDrive support, add the following to your configuration.nix: + + = true; + + This installs the onedrive package and a service onedriveLauncher which will instantiate a onedrive service for all your OneDrive accounts. Follow the steps in documentation of the onedrive client to setup your accounts. To use the service with multiple accounts, create a file named onedrive-launcher in ~/.config and add the filename of the config directory, relative to ~/.config. For example, if you have two OneDrive accounts with configs in ~/.config/onedrive_bob_work and ~/.config/onedrive_bob_personal, add the following lines: + +onedrive_bob_work +# Not in use: +# onedrive_bob_office365 +onedrive_bob_personal + + No such file needs to be created if you are using only a single OneDrive account with config in the default location ~/.config/onedrive, in the absence of ~/.config/onedrive-launcher, only a single service is instantiated, with default config path. + + + + If you wish to use a custom OneDrive package, say from another channel, add the following line: + + = pkgs.unstable.onedrive; + + +