mirror of
https://github.com/lightly-toasted/nix-config.git
synced 2025-12-10 03:49:44 +00:00
feat(y2q): add opengist
- Add environment and environmentFile options to runit module to support environment variables - Add opengist runit service that uses these options
This commit is contained in:
parent
bd9cb2afff
commit
3b3476c110
5 changed files with 69 additions and 16 deletions
|
|
@ -18,6 +18,16 @@
|
||||||
description = "Shell commands executed as the service's main process";
|
description = "Shell commands executed as the service's main process";
|
||||||
};
|
};
|
||||||
log.enable = lib.mkEnableOption "Enable logging";
|
log.enable = lib.mkEnableOption "Enable logging";
|
||||||
|
environment = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf lib.types.str;
|
||||||
|
default = {};
|
||||||
|
description = "Environment variables passed to the service's processes";
|
||||||
|
};
|
||||||
|
environmentFile = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
default = null;
|
||||||
|
description = "Environment file passed to the service";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
@ -28,10 +38,31 @@
|
||||||
config = {
|
config = {
|
||||||
home.file = lib.mkMerge (
|
home.file = lib.mkMerge (
|
||||||
lib.mapAttrsToList (serviceName: sCfg:
|
lib.mapAttrsToList (serviceName: sCfg:
|
||||||
|
let
|
||||||
|
envExports = lib.concatStringsSep "\n" (
|
||||||
|
lib.mapAttrsToList (k: v: "export ${k}='${v}'") sCfg.environment
|
||||||
|
);
|
||||||
|
envFile = lib.mkIf (sCfg.environmentFile != null) {
|
||||||
|
"runit/services/${serviceName}/.env" = {
|
||||||
|
source = sCfg.environmentFile;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
envFileSetup = if sCfg.environmentFile != null then ''
|
||||||
|
set -a
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
'' else "";
|
||||||
|
in
|
||||||
|
lib.mkMerge [
|
||||||
{
|
{
|
||||||
# run script
|
# run script
|
||||||
"runit/services/${serviceName}/run" = {
|
"runit/services/${serviceName}/run" = {
|
||||||
text = sCfg.script;
|
text = ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
${envExports}
|
||||||
|
${envFileSetup}
|
||||||
|
${sCfg.script}
|
||||||
|
'';
|
||||||
executable = true;
|
executable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,8 +72,11 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
exec svlogd -t ./main
|
exec svlogd -t ./main
|
||||||
'';
|
'';
|
||||||
|
executable = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
envFile
|
||||||
|
]
|
||||||
) config.runit.services
|
) config.runit.services
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
{
|
{
|
||||||
runit.services.glances = {
|
runit.services.glances = {
|
||||||
script = ''
|
script = ''
|
||||||
#!/bin/bash
|
exec ${pkgs.glances}/bin/glances -w
|
||||||
${pkgs.glances}/bin/glances -w
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
home/modules/runit/services/opengist.nix
Normal file
20
home/modules/runit/services/opengist.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{ pkgs, rootPath, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
runit.services.opengist = {
|
||||||
|
script = ''
|
||||||
|
exec ${pkgs.opengist}/bin/opengist start
|
||||||
|
'';
|
||||||
|
|
||||||
|
environment = {
|
||||||
|
OG_HTTP_HOST = "127.0.0.1";
|
||||||
|
OG_HTTP_PORT = "6157";
|
||||||
|
OG_SSH_HOST = "127.0.0.1";
|
||||||
|
OG_SSH_PORT = "6522";
|
||||||
|
};
|
||||||
|
|
||||||
|
environmentFile = rootPath + /secrets/gitcrypt/opengist.env;
|
||||||
|
|
||||||
|
log.enable = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
BIN
secrets/gitcrypt/opengist.env
Normal file
BIN
secrets/gitcrypt/opengist.env
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue