build(nix): simplify process compose config

This commit is contained in:
dusk 2025-01-05 01:18:59 +09:00
parent ff121ecc51
commit 42ea1e1bb1
No known key found for this signature in database

View file

@ -81,6 +81,7 @@
runtimeInputs = [ runtimeInputs = [
(config.nci.toolchains.mkBuild pkgs) (config.nci.toolchains.mkBuild pkgs)
self'.devShells.services.stdenv.cc self'.devShells.services.stdenv.cc
pkgs.dotnet-sdk_8
pkgs.csharpier pkgs.csharpier
pkgs.coreutils pkgs.coreutils
uniffi-bindgen-cs uniffi-bindgen-cs
@ -159,18 +160,19 @@
settings.processes = settings.processes =
let let
procCfg = composeCfg.settings.processes; procCfg = composeCfg.settings.processes;
mkServiceInitProcess = mkServiceProcess =
name:
{ {
name,
inputs ? [ ], inputs ? [ ],
... ...
}: }@attrs:
let let
shell = rustOutputs.${name}.devShell; shell = rustOutputs.${name}.devShell;
filteredAttrs = lib.removeAttrs attrs ["inputs"];
in in
{ filteredAttrs // {
command = pkgs.writeShellApplication { command = pkgs.writeShellApplication {
name = "pluralkit-${name}-init"; name = "pluralkit-${name}";
runtimeInputs = runtimeInputs =
(with pkgs; [ (with pkgs; [
coreutils coreutils
@ -182,16 +184,16 @@
${sourceDotenv} ${sourceDotenv}
set -x set -x
${pluralkitConfCheck} ${pluralkitConfCheck}
exec cargo build --package ${name} exec cargo run --package ${name}
''; '';
}; };
}; };
in in
{ {
### bot ### ### bot ###
pluralkit-bot-init = { pluralkit-bot = {
command = pkgs.writeShellApplication { command = pkgs.writeShellApplication {
name = "pluralkit-bot-init"; name = "pluralkit-bot";
runtimeInputs = self'.devShells.bot.nativeBuildInputs ++ [ runtimeInputs = self'.devShells.bot.nativeBuildInputs ++ [
pkgs.coreutils pkgs.coreutils
pkgs.git pkgs.git
@ -202,24 +204,9 @@
set -x set -x
${pluralkitConfCheck} ${pluralkitConfCheck}
${self'.apps.generate-command-parser-bindings.program} ${self'.apps.generate-command-parser-bindings.program}
exec dotnet build -c Release -o obj/ exec dotnet run -c Release --project PluralKit.Bot
''; '';
}; };
};
pluralkit-bot = {
command = pkgs.writeShellApplication {
name = "pluralkit-bot";
runtimeInputs = self'.devShells.bot.nativeBuildInputs ++ [
pkgs.coreutils
self'.devShells.bot.stdenv.cc
];
text = ''
${sourceDotenv}
set -x
exec dotnet obj/PluralKit.Bot.dll
'';
};
depends_on.pluralkit-bot-init.condition = "process_completed_successfully";
depends_on.postgres.condition = "process_healthy"; depends_on.postgres.condition = "process_healthy";
depends_on.redis.condition = "process_healthy"; depends_on.redis.condition = "process_healthy";
depends_on.pluralkit-gateway.condition = "process_healthy"; depends_on.pluralkit-gateway.condition = "process_healthy";
@ -227,26 +214,10 @@
ready_log_line = "Received Ready"; ready_log_line = "Received Ready";
}; };
### gateway ### ### gateway ###
pluralkit-gateway-init = mkServiceInitProcess { pluralkit-gateway = mkServiceProcess "gateway" {
name = "gateway"; inputs = with pkgs; [curl gnugrep];
};
pluralkit-gateway = {
command = pkgs.writeShellApplication {
name = "pluralkit-gateway";
runtimeInputs = with pkgs; [
coreutils
curl
gnugrep
];
text = ''
${sourceDotenv}
set -x
exec target/debug/gateway
'';
};
depends_on.postgres.condition = "process_healthy"; depends_on.postgres.condition = "process_healthy";
depends_on.redis.condition = "process_healthy"; depends_on.redis.condition = "process_healthy";
depends_on.pluralkit-gateway-init.condition = "process_completed_successfully";
# configure health checks # configure health checks
# TODO: don't assume port? # TODO: don't assume port?
liveness_probe.exec.command = ''curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/stats | grep "302"''; liveness_probe.exec.command = ''curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/stats | grep "302"'';