2024-03-14 12:53:32 +05:00
|
|
|
{
|
2024-07-25 12:48:09 +05:00
|
|
|
description = "Oscuro is a fancy multibot";
|
2024-03-14 12:53:32 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
nixConfig = {
|
2024-07-25 12:48:09 +05:00
|
|
|
extra-substituters = [
|
|
|
|
"https://cache.elnafo.ru"
|
|
|
|
"https://bonfire.cachix.org"
|
|
|
|
];
|
|
|
|
extra-trusted-public-keys = [
|
|
|
|
"cache.elnafo.ru:j3VD+Hn+is2Qk3lPXDSdPwHJQSatizk7V82iJ2RP1yo="
|
|
|
|
"bonfire.cachix.org-1:mzAGBy/Crdf8NhKail5ciK7ZrGRbPJJobW6TwFb7WYM="
|
|
|
|
];
|
2024-07-10 01:23:07 +05:00
|
|
|
};
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
inputs = {
|
|
|
|
bonfire = {
|
|
|
|
url = "github:L-Nafaryus/bonfire";
|
2024-07-25 12:48:09 +05:00
|
|
|
inputs = {
|
|
|
|
oscuro.follows = "";
|
|
|
|
};
|
2024-04-26 16:44:22 +05:00
|
|
|
};
|
2024-07-10 01:23:07 +05:00
|
|
|
nixpkgs.follows = "bonfire/nixpkgs";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
bonfire,
|
|
|
|
...
|
|
|
|
}: let
|
2024-07-25 12:48:09 +05:00
|
|
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
|
|
|
lib = pkgs.lib;
|
|
|
|
fenixPkgs = bonfire.inputs.fenix.packages.x86_64-linux;
|
|
|
|
craneLib = (bonfire.inputs.crane.mkLib pkgs).overrideToolchain fenixPkgs.complete.toolchain;
|
2024-07-10 01:23:07 +05:00
|
|
|
in {
|
2024-07-25 12:48:09 +05:00
|
|
|
packages.x86_64-linux = rec {
|
|
|
|
oscuro = let
|
|
|
|
common = {
|
|
|
|
pname = "oscuro";
|
|
|
|
version = "0.1.0";
|
|
|
|
|
|
|
|
src = pkgs.lib.cleanSourceWith {
|
|
|
|
src = ./.;
|
|
|
|
filter = path: type: (craneLib.filterCargoSources path type);
|
|
|
|
};
|
2024-07-10 01:23:07 +05:00
|
|
|
|
2024-07-25 12:48:09 +05:00
|
|
|
strictDeps = true;
|
2024-07-10 01:23:07 +05:00
|
|
|
|
2024-07-25 12:48:09 +05:00
|
|
|
nativeBuildInputs = [pkgs.pkg-config];
|
2024-07-10 01:23:07 +05:00
|
|
|
|
2024-07-25 12:48:09 +05:00
|
|
|
buildInputs = [pkgs.openssl];
|
|
|
|
};
|
|
|
|
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly common;
|
|
|
|
in
|
|
|
|
craneLib.buildPackage (common // {inherit cargoArtifacts;});
|
|
|
|
|
|
|
|
default = oscuro;
|
|
|
|
};
|
|
|
|
|
|
|
|
devShells.x86_64-linux.default = pkgs.mkShell {
|
|
|
|
nativeBuildInputs = [pkgs.pkg-config];
|
|
|
|
buildInputs = [
|
|
|
|
fenixPkgs.complete.toolchain
|
|
|
|
pkgs.cargo-release
|
|
|
|
pkgs.openssl
|
|
|
|
];
|
|
|
|
LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.openssl];
|
|
|
|
};
|
2024-07-10 01:23:07 +05:00
|
|
|
|
2024-07-25 12:48:09 +05:00
|
|
|
nixosModules = rec {
|
2024-07-10 01:23:07 +05:00
|
|
|
oscuro = {
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.services.oscuro;
|
|
|
|
opt = options.services.oscuro;
|
|
|
|
pkg = self.packages.${pkgs.system}.oscuro;
|
|
|
|
configFile = pkgs.writeText "config.toml" ''
|
|
|
|
discord_token = "#discord_token#"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
options.services.oscuro = {
|
|
|
|
enable = mkEnableOption "Enables the Oscuro bot";
|
2024-03-14 12:53:32 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
package = mkPackageOption pkgs "oscuro" {};
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/oscuro";
|
|
|
|
description = lib.mdDoc "Directory to store Oscuro files";
|
2024-04-26 16:44:22 +05:00
|
|
|
};
|
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
discordToken = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "Bot TOKENTOKENTOKEN";
|
|
|
|
};
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
discordTokenFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "/var/lib/secrets/oscuro/discord_token";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.discordToken != null || cfg.discordTokenFile != null;
|
|
|
|
message = "Discord token must be set. Use `services.oscuro.discordToken` or `services.oscuro.discordTokenFile`.";
|
|
|
|
}
|
|
|
|
];
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
users.users.oscuro = {
|
|
|
|
description = "Oscuro bot service user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "oscuro";
|
2024-04-26 16:44:22 +05:00
|
|
|
};
|
2024-07-10 01:23:07 +05:00
|
|
|
users.groups.oscuro = {};
|
|
|
|
|
|
|
|
systemd.services.oscuro = {
|
|
|
|
description = "Oscuro";
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
after = ["network.target"];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${pkg}/bin/oscuro";
|
|
|
|
User = "oscuro";
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
preStart = let
|
|
|
|
runConfig = "${cfg.dataDir}/config.toml";
|
|
|
|
replaceSecret = "${pkgs.replace-secret}/bin/replace-secret";
|
|
|
|
in ''
|
|
|
|
cp -f '${configFile}' '${runConfig}'
|
|
|
|
chmod u+w '${runConfig}'
|
|
|
|
|
|
|
|
${lib.optionalString (cfg.discordTokenFile != null) ''
|
|
|
|
${replaceSecret} '#discord_token#' '${cfg.discordTokenFile}' '${runConfig}'
|
|
|
|
''}
|
|
|
|
${lib.optionalString (cfg.discordToken != null) ''
|
|
|
|
sed -i 's/#discord_token#/${cfg.discordToken}/g' '${runConfig}'
|
|
|
|
''}
|
|
|
|
|
|
|
|
'';
|
2024-04-26 16:44:22 +05:00
|
|
|
};
|
2024-07-10 01:23:07 +05:00
|
|
|
};
|
2024-03-14 12:53:32 +05:00
|
|
|
};
|
|
|
|
|
2024-07-25 12:48:09 +05:00
|
|
|
default = oscuro;
|
2024-07-10 01:23:07 +05:00
|
|
|
};
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
nixosConfigurations.oscuro = nixpkgs.lib.nixosSystem {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules = [
|
|
|
|
self.nixosModules.oscuro
|
|
|
|
({pkgs, ...}: {
|
|
|
|
boot.isContainer = true;
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
networking.hostName = "oscuro";
|
|
|
|
networking.useDHCP = false;
|
2024-04-26 16:44:22 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
services.oscuro = {
|
|
|
|
enable = true;
|
|
|
|
discordToken = ""; # insert token
|
|
|
|
};
|
2024-03-14 12:53:32 +05:00
|
|
|
|
2024-07-10 01:23:07 +05:00
|
|
|
system.stateVersion = "24.05";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-03-14 12:53:32 +05:00
|
|
|
}
|