nixos/keybase, nixos/kbfs: update service configs; add redirector
This commit is contained in:
parent
8a7cc62063
commit
b4bacff13f
|
@ -1,6 +1,7 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
|
inherit (config.security) wrapperDir;
|
||||||
cfg = config.services.kbfs;
|
cfg = config.services.kbfs;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
@ -17,6 +18,16 @@ in {
|
||||||
description = "Whether to mount the Keybase filesystem.";
|
description = "Whether to mount the Keybase filesystem.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enableRedirector = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to enable the Keybase root redirector service, allowing
|
||||||
|
any user to access KBFS files via <literal>/keybase</literal>,
|
||||||
|
which will show different contents depending on the requester.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
mountPoint = mkOption {
|
mountPoint = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "%h/keybase";
|
default = "%h/keybase";
|
||||||
|
@ -41,26 +52,67 @@ in {
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
{
|
||||||
|
# Upstream: https://github.com/keybase/client/blob/master/packaging/linux/systemd/kbfs.service
|
||||||
|
systemd.user.services.kbfs = {
|
||||||
|
description = "Keybase File System";
|
||||||
|
|
||||||
systemd.user.services.kbfs = {
|
# Note that the "Requires" directive will cause a unit to be restarted whenever its dependency is restarted.
|
||||||
description = "Keybase File System";
|
# Do not issue a hard dependency on keybase, because kbfs can reconnect to a restarted service.
|
||||||
requires = [ "keybase.service" ];
|
# Do not issue a hard dependency on keybase-redirector, because it's ok if it fails (e.g., if it is disabled).
|
||||||
after = [ "keybase.service" ];
|
wants = [ "keybase.service" ] ++ optional cfg.enableRedirector "keybase-redirector.service";
|
||||||
path = [ "/run/wrappers" ];
|
path = [ "/run/wrappers" ];
|
||||||
unitConfig.ConditionUser = "!@system";
|
unitConfig.ConditionUser = "!@system";
|
||||||
serviceConfig = {
|
|
||||||
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p ${cfg.mountPoint}";
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.kbfs}/bin/kbfsfuse ${toString cfg.extraFlags} ${cfg.mountPoint}";
|
Type = "notify";
|
||||||
ExecStopPost = "/run/wrappers/bin/fusermount -u ${cfg.mountPoint}";
|
# Keybase notifies from a forked process
|
||||||
Restart = "on-failure";
|
EnvironmentFile = [
|
||||||
PrivateTmp = true;
|
"-%E/keybase/keybase.autogen.env"
|
||||||
|
"-%E/keybase/keybase.env"
|
||||||
|
];
|
||||||
|
ExecStartPre = [
|
||||||
|
"${pkgs.coreutils}/bin/mkdir -p \"${cfg.mountPoint}\""
|
||||||
|
"-${wrapperDir}/fusermount -uz \"${cfg.mountPoint}\""
|
||||||
|
];
|
||||||
|
ExecStart = "${pkgs.kbfs}/bin/kbfsfuse ${toString cfg.extraFlags} \"${cfg.mountPoint}\"";
|
||||||
|
ExecStop = "${wrapperDir}/fusermount -uz \"${cfg.mountPoint}\"";
|
||||||
|
Restart = "on-failure";
|
||||||
|
PrivateTmp = true;
|
||||||
|
};
|
||||||
|
wantedBy = [ "default.target" ];
|
||||||
};
|
};
|
||||||
wantedBy = [ "default.target" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
services.keybase.enable = true;
|
services.keybase.enable = true;
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.kbfs ];
|
environment.systemPackages = [ pkgs.kbfs ];
|
||||||
};
|
}
|
||||||
|
|
||||||
|
(mkIf cfg.enableRedirector {
|
||||||
|
security.wrappers."keybase-redirector".source = "${pkgs.kbfs}/bin/redirector";
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = [ "d /keybase 0755 root root 0" ];
|
||||||
|
|
||||||
|
# Upstream: https://github.com/keybase/client/blob/master/packaging/linux/systemd/keybase-redirector.service
|
||||||
|
systemd.user.services.keybase-redirector = {
|
||||||
|
description = "Keybase Root Redirector for KBFS";
|
||||||
|
wants = [ "keybase.service" ];
|
||||||
|
unitConfig.ConditionUser = "!@system";
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
EnvironmentFile = [
|
||||||
|
"-%E/keybase/keybase.autogen.env"
|
||||||
|
"-%E/keybase/keybase.env"
|
||||||
|
];
|
||||||
|
# Note: The /keybase mount point is not currently configurable upstream.
|
||||||
|
ExecStart = "${wrapperDir}/keybase-redirector /keybase";
|
||||||
|
Restart = "on-failure";
|
||||||
|
PrivateTmp = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
wantedBy = [ "default.target" ];
|
||||||
|
};
|
||||||
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,18 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
# Upstream: https://github.com/keybase/client/blob/master/packaging/linux/systemd/keybase.service
|
||||||
systemd.user.services.keybase = {
|
systemd.user.services.keybase = {
|
||||||
description = "Keybase service";
|
description = "Keybase service";
|
||||||
unitConfig.ConditionUser = "!@system";
|
unitConfig.ConditionUser = "!@system";
|
||||||
|
environment.KEYBASE_SERVICE_TYPE = "systemd";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = ''
|
Type = "notify";
|
||||||
${pkgs.keybase}/bin/keybase service --auto-forked
|
EnvironmentFile = [
|
||||||
'';
|
"-%E/keybase/keybase.autogen.env"
|
||||||
|
"-%E/keybase/keybase.env"
|
||||||
|
];
|
||||||
|
ExecStart = "${pkgs.keybase}/bin/keybase service";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
PrivateTmp = true;
|
PrivateTmp = true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue