forked from Fediversity/Fediversity
refactor variables (#269)
Reviewed-on: Fediversity/Fediversity#269 Reviewed-by: Valentin Gagarin <valentin.gagarin@tweag.io> Co-authored-by: Kiara Grouwstra <kiara@procolix.eu> Co-committed-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
f8ac63853c
commit
a5c310ad03
5 changed files with 41 additions and 36 deletions
panel
|
@ -6,26 +6,26 @@
|
||||||
config = { };
|
config = { };
|
||||||
overlays = [ (import ./nix/overlay.nix) ];
|
overlays = [ (import ./nix/overlay.nix) ];
|
||||||
},
|
},
|
||||||
}:
|
}@args:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
manage = pkgs.writeScriptBin "manage" ''
|
manage = pkgs.writeScriptBin "manage" ''
|
||||||
exec ${pkgs.lib.getExe pkgs.python3} ${toString ./src/manage.py} $@
|
exec ${pkgs.lib.getExe pkgs.python3} ${toString ./src/manage.py} $@
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
# re-export inputs so they can be overridden granularly
|
||||||
|
# (they can't be accessed from the outside any other way)
|
||||||
|
args
|
||||||
|
// {
|
||||||
shell = pkgs.mkShellNoCC {
|
shell = pkgs.mkShellNoCC {
|
||||||
inputsFrom = [ (pkgs.callPackage ./nix/package.nix { }) ];
|
inputsFrom = [ (pkgs.callPackage ./nix/package.nix { }) ];
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.npins
|
pkgs.npins
|
||||||
manage
|
manage
|
||||||
];
|
];
|
||||||
env = {
|
env = import ./env.nix { inherit lib pkgs; } // {
|
||||||
NPINS_DIRECTORY = toString ../npins;
|
NPINS_DIRECTORY = toString ../npins;
|
||||||
# explicitly use nix, as e.g. lix does not have configurable-impure-env
|
CREDENTIALS_DIRECTORY = toString ./.credentials;
|
||||||
NIX_BIN = lib.getExe pkgs.nix;
|
|
||||||
REPO_DIR = toString ../.;
|
|
||||||
CREDENTIALS_DIRECTORY = builtins.toString ./.credentials;
|
|
||||||
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
|
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
|
||||||
};
|
};
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
@ -39,12 +39,7 @@ in
|
||||||
|
|
||||||
module = import ./nix/configuration.nix;
|
module = import ./nix/configuration.nix;
|
||||||
tests = pkgs.callPackage ./nix/tests.nix { };
|
tests = pkgs.callPackage ./nix/tests.nix { };
|
||||||
|
|
||||||
# re-export inputs so they can be overridden granularly
|
|
||||||
# (they can't be accessed from the outside any other way)
|
|
||||||
inherit
|
|
||||||
sources
|
|
||||||
system
|
|
||||||
pkgs
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
# re-export inputs so they can be overridden granularly
|
||||||
|
# (they can't be accessed from the outside any other way)
|
||||||
|
// args
|
||||||
|
|
18
panel/env.nix
Normal file
18
panel/env.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (builtins) toString;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
REPO_DIR = toString ../.;
|
||||||
|
# explicitly use nix, as e.g. lix does not have configurable-impure-env
|
||||||
|
BIN_PATH = lib.makeBinPath [
|
||||||
|
# explicitly use nix, as e.g. lix does not have configurable-impure-env
|
||||||
|
pkgs.nix
|
||||||
|
# nixops error maybe due to our flake git hook: executing 'git': No such file or directory
|
||||||
|
pkgs.git
|
||||||
|
];
|
||||||
|
}
|
|
@ -23,7 +23,13 @@ let
|
||||||
cfg = config.services.${name};
|
cfg = config.services.${name};
|
||||||
package = pkgs.callPackage ./package.nix { };
|
package = pkgs.callPackage ./package.nix { };
|
||||||
|
|
||||||
database-url = "sqlite:////var/lib/${name}/db.sqlite3";
|
environment = import ../env.nix { inherit lib pkgs; } // {
|
||||||
|
DATABASE_URL = "sqlite:////var/lib/${name}/db.sqlite3";
|
||||||
|
USER_SETTINGS_FILE = pkgs.concatText "configuration.py" [
|
||||||
|
((pkgs.formats.pythonVars { }).generate "settings.py" cfg.settings)
|
||||||
|
(builtins.toFile "extra-settings.py" cfg.extra-settings)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
python-environment = pkgs.python3.withPackages (
|
python-environment = pkgs.python3.withPackages (
|
||||||
ps: with ps; [
|
ps: with ps; [
|
||||||
|
@ -32,11 +38,6 @@ let
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
configFile = pkgs.concatText "configuration.py" [
|
|
||||||
((pkgs.formats.pythonVars { }).generate "settings.py" cfg.settings)
|
|
||||||
(builtins.toFile "extra-settings.py" cfg.extra-settings)
|
|
||||||
];
|
|
||||||
|
|
||||||
manage-service = writeShellApplication {
|
manage-service = writeShellApplication {
|
||||||
name = "manage";
|
name = "manage";
|
||||||
text = ''exec ${package}/bin/manage.py "$@"'';
|
text = ''exec ${package}/bin/manage.py "$@"'';
|
||||||
|
@ -57,12 +58,7 @@ let
|
||||||
--property "Group=${name}" \
|
--property "Group=${name}" \
|
||||||
--property "WorkingDirectory=/var/lib/${name}" \
|
--property "WorkingDirectory=/var/lib/${name}" \
|
||||||
--property "Environment=''
|
--property "Environment=''
|
||||||
+ (toString [
|
+ (toString (lib.mapAttrsToList (name: value: "${name}=${value}") environment))
|
||||||
"NIX_BIN=${lib.getExe pkgs.nix}"
|
|
||||||
"REPO_DIR=${../..}"
|
|
||||||
"DATABASE_URL=${database-url}"
|
|
||||||
"USER_SETTINGS_FILE=${configFile}"
|
|
||||||
])
|
|
||||||
+ "\" \\\n"
|
+ "\" \\\n"
|
||||||
+ optionalString (credentials != [ ]) (
|
+ optionalString (credentials != [ ]) (
|
||||||
(concatStringsSep " \\\n" (map (cred: "--property 'LoadCredential=${cred}'") credentials)) + " \\\n"
|
(concatStringsSep " \\\n" (map (cred: "--property 'LoadCredential=${cred}'") credentials)) + " \\\n"
|
||||||
|
@ -214,12 +210,7 @@ in
|
||||||
# - manipulation should be straightforward in both places; e.g. dumping secrets to a directory that is not git-tracked and adding values to an attrset otherwise
|
# - manipulation should be straightforward in both places; e.g. dumping secrets to a directory that is not git-tracked and adding values to an attrset otherwise
|
||||||
# - error detection and correction; it should be clear where and why one messed up so it can be fixed immediately
|
# - error detection and correction; it should be clear where and why one messed up so it can be fixed immediately
|
||||||
# We may also want to test the development environment in CI in order to make sure that we don't break it inadvertently, because misconfiguration due to multiplpe sources of truth wastes a lot of time.
|
# We may also want to test the development environment in CI in order to make sure that we don't break it inadvertently, because misconfiguration due to multiplpe sources of truth wastes a lot of time.
|
||||||
environment = {
|
inherit environment;
|
||||||
USER_SETTINGS_FILE = "${configFile}";
|
|
||||||
DATABASE_URL = database-url;
|
|
||||||
NIX_BIN = lib.getExe pkgs.nix;
|
|
||||||
REPO_DIR = ../..;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [
|
networking.firewall.allowedTCPPorts = [
|
||||||
|
|
|
@ -192,8 +192,8 @@ 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.
|
||||||
|
|
||||||
# a dir of nix supporting experimental feature `configurable-impure-env`.
|
# PATH to expose to launch button
|
||||||
nix_bin=env['NIX_BIN']
|
bin_path=env['BIN_PATH']
|
||||||
# path of the root flake to trigger nixops from, see #94.
|
# path of the root flake to trigger nixops from, see #94.
|
||||||
# to deploy this should be specified, for dev just use a relative path.
|
# to deploy this should be specified, for dev just use a relative path.
|
||||||
repo_dir = env["REPO_DIR"]
|
repo_dir = env["REPO_DIR"]
|
||||||
|
|
|
@ -58,11 +58,12 @@ class ConfigurationForm(LoginRequiredMixin, FormView):
|
||||||
# serialize back and forth now we still need to manually inject the dummy user
|
# serialize back and forth now we still need to manually inject the dummy user
|
||||||
deployment = json.dumps(dummy_user | json.loads(submission))
|
deployment = json.dumps(dummy_user | json.loads(submission))
|
||||||
env = {
|
env = {
|
||||||
|
"PATH": settings.bin_path,
|
||||||
# pass in form info to our deployment
|
# pass in form info to our deployment
|
||||||
"DEPLOYMENT": deployment,
|
"DEPLOYMENT": deployment,
|
||||||
}
|
}
|
||||||
cmd = [
|
cmd = [
|
||||||
settings.nix_bin,
|
"nix",
|
||||||
"develop",
|
"develop",
|
||||||
# workaround to pass in info to nixops4 thru env vars, tho impure :(
|
# workaround to pass in info to nixops4 thru env vars, tho impure :(
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
|
|
Loading…
Add table
Reference in a new issue