From 1fafec482e7828cf23fbdb71c111f18faa79fee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Wed, 4 Jun 2025 16:02:39 +0200 Subject: [PATCH] FediPanel: allow configuring flake and deployment --- panel/default.nix | 4 +++- panel/env.nix | 9 --------- panel/nix/configuration.nix | 21 ++++++++++++++++++++- panel/src/panel/settings.py | 7 ++++--- panel/src/panel/views.py | 4 ++-- 5 files changed, 29 insertions(+), 16 deletions(-) delete mode 100644 panel/env.nix diff --git a/panel/default.nix b/panel/default.nix index 7b72e360..c6749611 100644 --- a/panel/default.nix +++ b/panel/default.nix @@ -26,7 +26,9 @@ in pkgs.nix pkgs.openssh ]; - env = import ./env.nix { } // { + env = { + DEPLOYMENT_FLAKE = ../.; + DEPLOYMENT_NAME = "test"; NPINS_DIRECTORY = toString ../npins; CREDENTIALS_DIRECTORY = toString ./.credentials; DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3"; diff --git a/panel/env.nix b/panel/env.nix deleted file mode 100644 index c95af586..00000000 --- a/panel/env.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - ... -}: -let - inherit (builtins) toString; -in -{ - REPO_DIR = toString ../.; -} diff --git a/panel/nix/configuration.nix b/panel/nix/configuration.nix index 1996f2df..e4de7b81 100644 --- a/panel/nix/configuration.nix +++ b/panel/nix/configuration.nix @@ -23,7 +23,9 @@ let cfg = config.services.${name}; 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"; USER_SETTINGS_FILE = pkgs.concatText "configuration.py" [ ((pkgs.formats.pythonVars { }).generate "settings.py" cfg.settings) @@ -144,6 +146,23 @@ in 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 { diff --git a/panel/src/panel/settings.py b/panel/src/panel/settings.py index 14b1a96f..d613e0ec 100644 --- a/panel/src/panel/settings.py +++ b/panel/src/panel/settings.py @@ -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. # 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. -# to deploy this should be specified, for dev just use a relative path. -repo_dir = env["REPO_DIR"] +# Path of the root flake to trigger nixops from, see #94, and name of the +# deployment. +deployment_flake = env["DEPLOYMENT_FLAKE"] +deployment_name = env["DEPLOYMENT_NAME"] diff --git a/panel/src/panel/views.py b/panel/src/panel/views.py index 84f25430..2f603002 100644 --- a/panel/src/panel/views.py +++ b/panel/src/panel/views.py @@ -96,13 +96,13 @@ class DeploymentStatus(ConfigurationForm): cmd = [ "nixops4", "apply", - "test", + settings.deployment_name, "--show-trace", "--no-interactive", ] deployment_result = subprocess.run( cmd, - cwd = settings.repo_dir, + cwd = settings.deployment_flake, env = env, stderr = subprocess.STDOUT, )