Compare commits

...
Sign in to create a new pull request.

1 commit

5 changed files with 29 additions and 16 deletions

View file

@ -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";

View file

@ -1,9 +0,0 @@
{
...
}:
let
inherit (builtins) toString;
in
{
REPO_DIR = toString ../.;
}

View file

@ -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 {

View file

@ -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"]

View file

@ -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,
) )