mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2025-01-01 00:12:39 +03:00
nixos/mxisd: add support for ma1sd
both servers only differ slighly so the module can be reused
This commit is contained in:
parent
ce587047e6
commit
176b1aeb4e
@ -3,6 +3,15 @@
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
isMa1sd =
|
||||
package:
|
||||
lib.hasPrefix "ma1sd" package.name;
|
||||
|
||||
isMxisd =
|
||||
package:
|
||||
lib.hasPrefix "mxisd" package.name;
|
||||
|
||||
cfg = config.services.mxisd;
|
||||
|
||||
server = optionalAttrs (cfg.server.name != null) { inherit (cfg.server) name; }
|
||||
@ -12,37 +21,41 @@ let
|
||||
matrix.domain = cfg.matrix.domain;
|
||||
key.path = "${cfg.dataDir}/signing.key";
|
||||
storage = {
|
||||
provider.sqlite.database = "${cfg.dataDir}/mxisd.db";
|
||||
provider.sqlite.database = if isMa1sd cfg.package
|
||||
then "${cfg.dataDir}/ma1sd.db"
|
||||
else "${cfg.dataDir}/mxisd.db";
|
||||
};
|
||||
} // optionalAttrs (server != {}) { inherit server; };
|
||||
|
||||
# merges baseConfig and extraConfig into a single file
|
||||
fullConfig = recursiveUpdate baseConfig cfg.extraConfig;
|
||||
|
||||
configFile = pkgs.writeText "mxisd-config.yaml" (builtins.toJSON fullConfig);
|
||||
configFile = if isMa1sd cfg.package
|
||||
then pkgs.writeText "ma1sd-config.yaml" (builtins.toJSON fullConfig)
|
||||
else pkgs.writeText "mxisd-config.yaml" (builtins.toJSON fullConfig);
|
||||
|
||||
in {
|
||||
options = {
|
||||
services.mxisd = {
|
||||
enable = mkEnableOption "mxisd matrix federated identity server";
|
||||
enable = mkEnableOption "matrix federated identity server";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.mxisd;
|
||||
defaultText = "pkgs.mxisd";
|
||||
description = "The mxisd package to use";
|
||||
description = "The mxisd/ma1sd package to use";
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.str;
|
||||
default = "/var/lib/mxisd";
|
||||
description = "Where data mxisd uses resides";
|
||||
description = "Where data mxisd/ma1sd uses resides";
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
description = "Extra options merged into the mxisd configuration";
|
||||
description = "Extra options merged into the mxisd/ma1sd configuration";
|
||||
};
|
||||
|
||||
matrix = {
|
||||
@ -62,7 +75,7 @@ in {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Public hostname of mxisd, if different from the Matrix domain.
|
||||
Public hostname of mxisd/ma1sd, if different from the Matrix domain.
|
||||
'';
|
||||
};
|
||||
|
||||
@ -103,11 +116,13 @@ in {
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
serviceConfig = let
|
||||
executable = if isMa1sd cfg.package then "ma1sd" else "mxisd";
|
||||
in {
|
||||
Type = "simple";
|
||||
User = "mxisd";
|
||||
Group = "mxisd";
|
||||
ExecStart = "${cfg.package}/bin/mxisd -c ${configFile}";
|
||||
ExecStart = "${cfg.package}/bin/${executable} -c ${configFile}";
|
||||
WorkingDirectory = cfg.dataDir;
|
||||
Restart = "on-failure";
|
||||
};
|
||||
|
@ -10,12 +10,22 @@ import ./make-test.nix ({ pkgs, ... } : {
|
||||
services.mxisd.enable = true;
|
||||
services.mxisd.matrix.domain = "example.org";
|
||||
};
|
||||
|
||||
server_ma1sd = args : {
|
||||
services.mxisd.enable = true;
|
||||
services.mxisd.matrix.domain = "example.org";
|
||||
services.mxisd.package = pkgs.ma1sd;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
startAll;
|
||||
$server_mxisd->waitForUnit("mxisd.service");
|
||||
$server_mxisd->waitForOpenPort(8090);
|
||||
$server_mxisd->succeed("curl -Ssf \"http://127.0.0.1:8090/_matrix/identity/api/v1\"")
|
||||
$server_mxisd->succeed("curl -Ssf \"http://127.0.0.1:8090/_matrix/identity/api/v1\"");
|
||||
$server_ma1sd->waitForUnit("mxisd.service");
|
||||
$server_ma1sd->waitForOpenPort(8090);
|
||||
$server_ma1sd->succeed("curl -Ssf \"http://127.0.0.1:8090/_matrix/identity/api/v1\"")
|
||||
|
||||
'';
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user