mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
require config path via cli, remove env var
This commit is contained in:
parent
3650fde0ac
commit
9b115b4110
4 changed files with 11 additions and 23 deletions
|
|
@ -85,17 +85,12 @@ in
|
||||||
systemd.services.grapevine = {
|
systemd.services.grapevine = {
|
||||||
description = "Grapevine (Matrix homeserver)";
|
description = "Grapevine (Matrix homeserver)";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
environment = lib.mkMerge [
|
environment = cfg.extraEnvironment;
|
||||||
{
|
|
||||||
GRAPEVINE_CONFIG = configFile;
|
|
||||||
}
|
|
||||||
cfg.extraEnvironment
|
|
||||||
];
|
|
||||||
|
|
||||||
# Keep sorted
|
# Keep sorted
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
ExecStart = "${lib.getExe cfg.package}";
|
ExecStart = "${lib.getExe cfg.package} --config ${configFile}";
|
||||||
LockPersonality = true;
|
LockPersonality = true;
|
||||||
MemoryDenyWriteExecute = true;
|
MemoryDenyWriteExecute = true;
|
||||||
PrivateDevices = true;
|
PrivateDevices = true;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
//! Integration with `clap`
|
//! Integration with `clap`
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
/// Command line arguments
|
/// Command line arguments
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(about, version = crate::version())]
|
#[clap(about, version = crate::version())]
|
||||||
pub(crate) struct Args;
|
pub(crate) struct Args {
|
||||||
|
/// Path to the configuration file
|
||||||
|
#[clap(long, short)]
|
||||||
|
pub(crate) config: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse command line arguments into structured data
|
/// Parse command line arguments into structured data
|
||||||
pub(crate) fn parse() -> Args {
|
pub(crate) fn parse() -> Args {
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,6 @@ impl fmt::Display for DisplayWithSources<'_> {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub(crate) enum Main {
|
pub(crate) enum Main {
|
||||||
#[error(
|
|
||||||
"the `{0}` environment variable must either be set to a configuration \
|
|
||||||
file path or set to an empty string to force configuration through \
|
|
||||||
environment variables"
|
|
||||||
)]
|
|
||||||
ConfigPathUnset(&'static str),
|
|
||||||
|
|
||||||
#[error("invalid configuration")]
|
#[error("invalid configuration")]
|
||||||
ConfigInvalid(#[from] figment::Error),
|
ConfigInvalid(#[from] figment::Error),
|
||||||
|
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -108,17 +108,11 @@ async fn main() -> ExitCode {
|
||||||
async fn try_main() -> Result<(), error::Main> {
|
async fn try_main() -> Result<(), error::Main> {
|
||||||
use error::Main as Error;
|
use error::Main as Error;
|
||||||
|
|
||||||
args::parse();
|
let args = args::parse();
|
||||||
|
|
||||||
// Initialize config
|
// Initialize config
|
||||||
let raw_config = Figment::new()
|
let raw_config = Figment::new()
|
||||||
.merge(
|
.merge(Toml::file(&args.config).nested())
|
||||||
Toml::file({
|
|
||||||
let name = "GRAPEVINE_CONFIG";
|
|
||||||
Env::var(name).ok_or(Error::ConfigPathUnset(name))?
|
|
||||||
})
|
|
||||||
.nested(),
|
|
||||||
)
|
|
||||||
.merge(Env::prefixed("GRAPEVINE_").global());
|
.merge(Env::prefixed("GRAPEVINE_").global());
|
||||||
|
|
||||||
let config = raw_config.extract::<Config>()?;
|
let config = raw_config.extract::<Config>()?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue