Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xandikos: backport systemd socket activation #161690

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions nixos/modules/services/networking/xandikos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ with lib;

let
cfg = config.services.xandikos;

listenStream =
if cfg.address == null then
[ "[::1]:${toString cfg.port}" "127.0.0.1:${toString cfg.port}" ]
else if hasInfix "/" cfg.address then
[ cfg.address ]
else if hasInfix ":" cfg.address then
[ "[${cfg.address}]:${toString cfg.port}" ]
else
[ "${cfg.address}:${toString cfg.port}" ]
;

nginxProxyAddress =
if hasInfix "/" (head listenStream) then
"unix:${head listenStream}"
else
head listenStream
;
in
{

Expand All @@ -19,12 +37,13 @@ in
};

address = mkOption {
type = types.str;
default = "localhost";
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
The IP address on which Xandikos will listen.
The IP address or socket path on which Xandikos will listen.
By default listens on localhost.
'';
example = "/run/xandikos/socket";
};

port = mkOption {
Expand Down Expand Up @@ -92,11 +111,13 @@ in
{
meta.maintainers = with lib.maintainers; [ _0x4A6F ];

systemd.sockets.xandikos = {
wantedBy = [ "sockets.target" ];
socketConfig.ListenStream = listenStream;
};

systemd.services.xandikos = {
description = "A Simple Calendar and Contact Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

serviceConfig = {
User = "xandikos";
Group = "xandikos";
Expand All @@ -122,8 +143,6 @@ in
ExecStart = ''
${cfg.package}/bin/xandikos \
--directory /var/lib/xandikos \
--listen-address ${cfg.address} \
--port ${toString cfg.port} \
--route-prefix ${cfg.routePrefix} \
${lib.concatStringsSep " " cfg.extraOptions}
'';
Expand All @@ -137,7 +156,7 @@ in
enable = true;
virtualHosts."${cfg.nginx.hostName}" = {
locations."/" = {
proxyPass = "http://${cfg.address}:${toString cfg.port}/";
proxyPass = "http://${nginxProxyAddress}";
};
};
};
Expand Down
10 changes: 2 additions & 8 deletions nixos/tests/xandikos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import ./make-test-python.nix (
xandikos_proxy = {
networking.firewall.allowedTCPPorts = [ 80 8080 ];
services.xandikos.enable = true;
services.xandikos.address = "localhost";
services.xandikos.port = 8080;
services.xandikos.routePrefix = "/xandikos-prefix/";
services.xandikos.extraOptions = [
"--defaults"
Expand All @@ -39,9 +37,7 @@ import ./make-test-python.nix (
start_all()

with subtest("Xandikos default"):
xandikos_default.wait_for_unit("multi-user.target")
xandikos_default.wait_for_unit("xandikos.service")
xandikos_default.wait_for_open_port(8080)
xandikos_default.wait_for_unit("sockets.target")
xandikos_default.succeed("curl --fail http://localhost:8080/")
xandikos_default.succeed(
"curl -s --fail --location http://localhost:8080/ | grep -i Xandikos"
Expand All @@ -50,9 +46,7 @@ import ./make-test-python.nix (
xandikos_client.fail("curl --fail http://xandikos_default:8080/")

with subtest("Xandikos proxy"):
xandikos_proxy.wait_for_unit("multi-user.target")
xandikos_proxy.wait_for_unit("xandikos.service")
xandikos_proxy.wait_for_open_port(8080)
xandikos_proxy.wait_for_unit("sockets.target")
xandikos_proxy.succeed("curl --fail http://localhost:8080/")
xandikos_proxy.succeed(
"curl -s --fail --location http://localhost:8080/ | grep -i Xandikos"
Expand Down
10 changes: 10 additions & 0 deletions pkgs/servers/xandikos/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib
, fetchFromGitHub
, fetchpatch
, python3Packages
, nixosTests
}:
Expand All @@ -15,6 +16,14 @@ python3Packages.buildPythonApplication rec {
sha256 = "sha256-KDDk0QSOjwivJFz3vLk+g4vZMlSuX2FiOgHJfDJkpwg=";
};

patches = [
# add support for systemd socket activation
(fetchpatch {
url = "https://github.com/jelmer/xandikos/pull/155.diff";
sha256 = "sha256-h2E0DSeWMkuUytMiu+uUsEJI22fszNCOxEqvPlXMYek=";
})
];

propagatedBuildInputs = with python3Packages; [
aiohttp
dulwich
Expand All @@ -23,6 +32,7 @@ python3Packages.buildPythonApplication rec {
jinja2
multidict
prometheus-client
systemd
];

passthru.tests.xandikos = nixosTests.xandikos;
Expand Down