aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/networking/onedrive.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/networking/onedrive.nix')
-rw-r--r--nixpkgs/nixos/modules/services/networking/onedrive.nix72
1 files changed, 72 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/networking/onedrive.nix b/nixpkgs/nixos/modules/services/networking/onedrive.nix
new file mode 100644
index 00000000000..210d2217b27
--- /dev/null
+++ b/nixpkgs/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";
+ };
+ };
+ };
+}