2020-06-29 15:26:41 +01:00
|
|
|
{ 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;
|
|
|
|
|
2020-08-07 14:43:58 +01:00
|
|
|
### Interface
|
2020-06-29 15:26:41 +01:00
|
|
|
|
|
|
|
options.services.onedrive = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Enable OneDrive service";
|
2020-06-29 15:26:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
default = pkgs.onedrive;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = lib.literalExpression "pkgs.onedrive";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-06-29 15:26:41 +01:00
|
|
|
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 = ''
|
2020-09-19 07:02:42 +01:00
|
|
|
${cfg.package}/bin/onedrive --monitor --confdir=%h/.config/%i
|
2020-06-29 15:26:41 +01:00
|
|
|
'';
|
|
|
|
Restart="on-failure";
|
|
|
|
RestartSec=3;
|
|
|
|
RestartPreventExitStatus=3;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.services.onedrive-launcher = {
|
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${onedriveLauncher}/bin/onedrive-launcher";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|