forked from Fediversity/Fediversity
FediPanel: allow configuring flake and deployment (#376)
Last part of #361. Builds on top of #375. Reviewed-on: Fediversity/Fediversity#376 Reviewed-by: kiara Grouwstra <kiara@procolix.eu> Co-authored-by: Nicolas “Niols” Jeannerod <nicolas.jeannerod@moduscreate.com> Co-committed-by: Nicolas “Niols” Jeannerod <nicolas.jeannerod@moduscreate.com>
This commit is contained in:
parent
ace56e754e
commit
3a3a083793
5 changed files with 29 additions and 16 deletions
|
@ -26,7 +26,9 @@ in
|
||||||
pkgs.nix
|
pkgs.nix
|
||||||
pkgs.openssh
|
pkgs.openssh
|
||||||
];
|
];
|
||||||
env = import ./env.nix { } // {
|
env = {
|
||||||
|
DEPLOYMENT_FLAKE = ../.;
|
||||||
|
DEPLOYMENT_NAME = "test";
|
||||||
NPINS_DIRECTORY = toString ../npins;
|
NPINS_DIRECTORY = toString ../npins;
|
||||||
CREDENTIALS_DIRECTORY = toString ./.credentials;
|
CREDENTIALS_DIRECTORY = toString ./.credentials;
|
||||||
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
|
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (builtins) toString;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
REPO_DIR = toString ../.;
|
|
||||||
}
|
|
|
@ -23,7 +23,9 @@ let
|
||||||
cfg = config.services.${name};
|
cfg = config.services.${name};
|
||||||
package = pkgs.callPackage ./package.nix { };
|
package = pkgs.callPackage ./package.nix { };
|
||||||
|
|
||||||
environment = import ../env.nix { } // {
|
environment = {
|
||||||
|
DEPLOYMENT_FLAKE = cfg.deployment.flake;
|
||||||
|
DEPLOYMENT_NAME = cfg.deployment.name;
|
||||||
DATABASE_URL = "sqlite:////var/lib/${name}/db.sqlite3";
|
DATABASE_URL = "sqlite:////var/lib/${name}/db.sqlite3";
|
||||||
USER_SETTINGS_FILE = pkgs.concatText "configuration.py" [
|
USER_SETTINGS_FILE = pkgs.concatText "configuration.py" [
|
||||||
((pkgs.formats.pythonVars { }).generate "settings.py" cfg.settings)
|
((pkgs.formats.pythonVars { }).generate "settings.py" cfg.settings)
|
||||||
|
@ -144,6 +146,23 @@ in
|
||||||
this workaround.
|
this workaround.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deployment = {
|
||||||
|
flake = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
default = ../..;
|
||||||
|
description = ''
|
||||||
|
The path to the flake containing the deployment. This is used to run the deployment button.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "test";
|
||||||
|
description = ''
|
||||||
|
The name of the deployment within the flake.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
|
@ -240,6 +240,7 @@ if user_settings_file is not None:
|
||||||
# The correct thing to do here would be using a helper function such as with `get_secret()` that will catch the exception and explain what's wrong and where to put the right values.
|
# The correct thing to do here would be using a helper function such as with `get_secret()` that will catch the exception and explain what's wrong and where to put the right values.
|
||||||
# Replacing the `USER_SETTINGS_FILE` mechanism following the comment there would probably be a good thing.
|
# Replacing the `USER_SETTINGS_FILE` mechanism following the comment there would probably be a good thing.
|
||||||
|
|
||||||
# path of the root flake to trigger nixops from, see #94.
|
# Path of the root flake to trigger nixops from, see #94, and name of the
|
||||||
# to deploy this should be specified, for dev just use a relative path.
|
# deployment.
|
||||||
repo_dir = env["REPO_DIR"]
|
deployment_flake = env["DEPLOYMENT_FLAKE"]
|
||||||
|
deployment_name = env["DEPLOYMENT_NAME"]
|
||||||
|
|
|
@ -96,13 +96,13 @@ class DeploymentStatus(ConfigurationForm):
|
||||||
cmd = [
|
cmd = [
|
||||||
"nixops4",
|
"nixops4",
|
||||||
"apply",
|
"apply",
|
||||||
"test",
|
settings.deployment_name,
|
||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--no-interactive",
|
"--no-interactive",
|
||||||
]
|
]
|
||||||
deployment_result = subprocess.run(
|
deployment_result = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
cwd = settings.repo_dir,
|
cwd = settings.deployment_flake,
|
||||||
env = env,
|
env = env,
|
||||||
stderr = subprocess.STDOUT,
|
stderr = subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue