Skip to content

Commit

Permalink
flake: add mono-node and multi-node tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RaitoBezarius committed May 19, 2023
1 parent 0c2cfb0 commit ac229a0
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[workspace]
package.name = "sable"
package.version = "0.0.1"
members = [
"sable_macros",
"sable_network",
Expand Down
187 changes: 187 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 54 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,62 @@
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "nixpkgs/nixos-unstable";
};

outputs = { self, crane, fenix, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system: {
packages.default =
let
craneLib = crane.lib.${system}.overrideToolchain
fenix.packages.${system}.minimal.toolchain;
in
craneLib.buildPackage {
src = ./sable_ircd;
outputs = { self, crane, fenix, flake-utils, flake-parts, nixpkgs }@inputs: flake-parts.lib.mkFlake { inherit inputs; } ({ moduleWithSystem, ... }: {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];

flake.nixosModules.sable = moduleWithSystem (
{ config }:
{ ... }: {
imports = [
./nix/modules/sable.nix
];
}
);

systems = [
"x86_64-linux"

# Not actively tested, but may work:
# "aarch64-linux"
];

perSystem = { config, system, pkgs, ... }:
let
pkgs = import nixpkgs {
system = system;
overlays = [
self.overlays.default
];
};
inherit (pkgs) lib;
in {
packages.sable =
let
craneLib = crane.lib.${system}.overrideToolchain
(fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-kadEI6Hg6v+Xw68334b8XpfNah1pZAJZQ+i6ViN+QyQ=";
});
in
craneLib.buildPackage {
src = ./.;
};

overlayAttrs = {
inherit (config.packages) sable;
};

checks = (import ./nix/tests/sable.nix {
inherit pkgs;
sableModule = self.nixosModules.sable;
});
};
});
});
}
94 changes: 94 additions & 0 deletions nix/modules/sable.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.services.sable;

settingsFormat = pkgs.formats.json { };
serverConfigFile = settingsFormat.generate "server.json" cfg.server.settings;
networkConfigFile =
settingsFormat.generate "network.json" cfg.network.settings;
bootstrapFile =
settingsFormat.generate "bootstrap.json" cfg.network.bootstrap;
in {
options.services.sable = {
enable = mkEnableOption "the Libera Chat's Sable IRCd";

network = {
configFile = mkOption {
type = types.path;
default = networkConfigFile;
};

settings = mkOption rec {
type = types.submodule { freeformType = settingsFormat.type; };

default = { };
};

bootstrap = mkOption {
type = types.nullOr (types.submodule { freeformType = settingsFormat.type; });
default = null;
};
};

server.configFile = mkOption {
type = types.path;
default = serverConfigFile;
};

server.settings = mkOption {
type = types.submodule { freeformType = settingsFormat.type; };

default = { };

description = ''
Server configuration of the IRCd.
'';
};
};

config = mkIf cfg.enable {
services.sable.server.settings.log = lib.mapAttrs (n: lib.mkDefault) {
dir = "/var/log/sable/";
# stdout = "stdout.log";
# stderr = "stderr.log";
pidfile = "/run/sable/sable.pid";
module-levels = {
tokio = "trace";
runtime = "trace";
rustls = "error";
tracing = "warn";
sable = "trace";
"" = "debug";
};

targets = [
{
target = "stdout";
level = "trace";
modules = [ "sable"];
}
{
target = { filename = "sable.log"; level = "info"; };
level = "info";
}
{
target = { filename = "trace.log"; level = "trace"; };
level = "trace";
}
];

console-address = "127.0.0.1:9999";
};
systemd.services.sable-ircd = {
description = "Sable IRC daemon";
wantedBy = [ "multi-user.target" ];
restartTriggers = [ cfg.network.configFile cfg.server.configFile ];
serviceConfig = {
LogsDirectory = "sable";
PIDFile = "sable.pid";
ExecStart = "${pkgs.sable}/bin/sable_ircd --foreground ${optionalString (cfg.network.bootstrap != null) "--bootstrap-network ${bootstrapFile}"} --network-conf ${cfg.network.configFile} --server-conf ${cfg.server.configFile}";
};
};
};
}
Loading

0 comments on commit ac229a0

Please sign in to comment.