-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
description = "A flake for the construct matrix homeserver"; | ||
|
||
outputs = { self, nixpkgs }: let | ||
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" ]; | ||
in { | ||
|
||
overlay = final: prev: rec { | ||
matrix-construct-source = let | ||
inherit (prev) lib linkFarm; | ||
srcFilter = n: t: (lib.hasSuffix ".cc" n || lib.hasSuffix ".h" n || lib.hasSuffix ".S" n | ||
|| lib.hasSuffix ".md" n || t == "directory"); | ||
repo = lib.cleanSourceWith { filter = srcFilter; src = lib.cleanSource "./."; }; | ||
|
||
buildFileWith = root: name: type: rec { | ||
inherit name; file = "${root}/${name}"; | ||
path = if type == "directory" then buildFarmFrom name file else "${file}"; | ||
}; | ||
buildFarm = root: lib.mapAttrsToList (buildFileWith root) (builtins.readDir root); | ||
buildFarmFrom = basename: root: linkFarm (lib.strings.sanitizeDerivationName basename) (buildFarm root); | ||
in buildFarmFrom "construct" self; | ||
|
||
matrix-construct = prev.callPackage ./nix/package { | ||
rev = if self ? rev then self.rev else "development"; | ||
source = matrix-construct-source; | ||
}; | ||
}; | ||
|
||
packages = forAllSystems (system: let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
in self.overlay pkgs pkgs); | ||
|
||
defaultPackage = forAllSystems (system: self.packages.${system}.matrix-construct); | ||
|
||
nixosModules = { | ||
matrix-construct = import ./nix/module self; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
self: { config, system, pkgs, lib, ... }: | ||
|
||
let | ||
cfg = config.services.matrix-construct; | ||
in { | ||
options.services.matrix-construct = with lib; { | ||
enable = mkEnableOption "the construct server"; | ||
|
||
useScreen = mkOption { | ||
type = types.bool; | ||
default = true; | ||
example = false; | ||
description = '' | ||
Run construct in screen for stdio access. | ||
''; | ||
}; | ||
|
||
setupUnbound = mkOption { | ||
type = types.bool; | ||
default = true; | ||
example = false; | ||
description = '' | ||
Setup default unbound forwardAddresses. | ||
''; | ||
}; | ||
|
||
extraArgs = mkOption { | ||
type = with types; listOf str; | ||
default = []; | ||
example = [ "-6" "--debug" ]; | ||
description = '' | ||
Extra flags to pass to construct. | ||
''; | ||
}; | ||
|
||
package = mkOption { | ||
type = types.package; | ||
default = self.packages.${system}.matrix-construct; | ||
defaultText = "pkgs.matrix-construct"; | ||
description = '' | ||
Guix package to use. | ||
''; | ||
}; | ||
|
||
server = mkOption { | ||
type = types.str; | ||
default = null; | ||
example = "matrix.example.org"; | ||
description = '' | ||
Server configuration to run construct with. | ||
''; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
environment.systemPackages = [ cfg.package ] ++ lib.optional cfg.useScreen pkgs.screen; | ||
|
||
systemd.services.construct = { | ||
description = "Matrix Construct"; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
## bin/construct host.tld [servername] | ||
## Connect to screen | ||
## Wait for init, then press ctrl-c | ||
## Create listener with `net listen matrix * 8448 privkey.pem cert.pem chain.pem` | ||
## ..I used /var/lib/acme/xa0.uk/key.pem /(...)/xa0.uk/fullchain.pem /(...)/xa0.uk/fullchain.pem` | ||
## Route and test with https://matrix.org/federationtester/api/report?server_name=host.tld | ||
## Restart, or reload with `mod reload web_root` | ||
## Exit screen | ||
script = '' cd $STATE_DIRECTORY && exec '' | ||
+ (if cfg.useScreen then '' ${pkgs.screen}/bin/screen -D -m '' else "") | ||
+ '' ${cfg.package}/bin/construct ${cfg.server} ${lib.concatStringsSep " " cfg.extraArgs} ''; | ||
|
||
serviceConfig = { | ||
Restart = "on-failure"; | ||
ConfigurationDirectory = "construct"; | ||
RuntimeDirectory = "construct"; | ||
StateDirectory = "construct"; # Todo: bootstrap | ||
LogsDirectory = "construct"; | ||
StandardOutput = "syslog"; | ||
StandardError = "syslog"; | ||
TimeoutStopSec = "120"; | ||
KillSignal = "SIGQUIT"; | ||
}; | ||
}; | ||
|
||
services.unbound.forwardAddresses = lib.mkIf cfg.setupUnbound [ "4.2.2.1" "4.2.2.2" "4.2.2.3" "4.2.2.4" "4.2.2.5" "4.2.2.6" ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters