Compare commits

...

15 commits

Author SHA1 Message Date
f50ee049f2
import the regular way, fixing error: attribute 'age' missing 2025-03-17 15:13:23 +01:00
e872b3fde0
comment fediversity.eu option as its subdomains named after our services are used for production instances
08d109cc82/services/fediversity/sharedOptions.nix (L44)
2025-03-17 15:13:23 +01:00
42a0a798e7
pass in dummy initialUser to trigger orchestration from the panel 2025-03-17 15:13:23 +01:00
98b3947a8e
default form to .net as .eu subdomains are used for live services 2025-03-17 15:13:23 +01:00
7c5259181f
add openssh to devshell, as seemingly needed to trigger nixops4 by flake in django 2025-03-17 15:13:23 +01:00
782bbc4d8e
move from documenting to automating configurable-impure-env 2025-03-17 15:13:23 +01:00
2a8ae9d320
pass flake path as inputs.self.outPath? 2025-03-17 15:13:23 +01:00
5355e57378
WIP: change env to environment 2025-03-17 15:13:23 +01:00
76ff180ca7
use imputs over self 2025-03-17 15:13:23 +01:00
ae08673c1b
pass self thru in flake 2025-03-17 15:13:23 +01:00
e86712beec
Remove addding nixpkgs (did not fix the issue) 2025-03-17 15:13:23 +01:00
cc5101063b
Pass REPO_DIR implicitly 2025-03-17 15:13:23 +01:00
6bc3016585
add NIX_DIR 2025-03-17 15:13:23 +01:00
fcbbce0405
Convert configuration form to json
WIP: Get nix in scope
2025-03-17 15:13:23 +01:00
1411136f75
WIP: trigger nixops from panel
Closes #76.

Note I had not yet manage to successfully test this.

Manually trying the parameterized NixOps4 I tried using the following
command, tho I had yet to get this to work as well:

```sh
DEPLOYMENT='{"domain": "fediversity.net", "mastodon": {"enable": false},
"pixelfed": {"enable": true}, "peertube": {"enable": false}}' nix
develop --extra-experimental-features "configurable-impure-env"
--command nixops4 apply test
```

(or rather, I used a hardcoded Nix here so as to make it not use Lix.)

So far this had failed for me with:

```
the following units failed:
acme-mastodon.web.garage.fediversity.net.service
...
nixops4 error: Failed to create resource garage-configuration
```
2025-03-17 15:13:23 +01:00
7 changed files with 70 additions and 6 deletions

View file

@ -58,7 +58,10 @@
packages = [
pkgs.nil
inputs'.agenix.packages.default
inputs'.nixops4.packages.default
(inputs'.nixops4.packages.default.overrideAttrs {
impureEnvVars = [ "DEPLOYMENT" ];
})
pkgs.openssh
pkgs.httpie
pkgs.jq
];

View file

@ -143,7 +143,17 @@ in
## - We add a “test” deployment with all test machines.
nixops4Deployments = genAttrs machines makeDeployment' // {
default = makeDeployment machines;
test = makeTestDeployment (fromJSON (readFile ./test-machines/configuration.json));
test = makeTestDeployment (
fromJSON (
let
env = builtins.getEnv "DEPLOYMENT";
in
if env != "" then
env
else
builtins.trace "env var DEPLOYMENT not set, falling back to ./test-machines/configuration.json!" (readFile ./test-machines/configuration.json)
)
);
};
flake.nixosConfigurations =
genAttrs machines (makeConfiguration false)

View file

@ -1,17 +1,25 @@
{
inputs,
config,
pkgs,
...
}:
let
name = "panel";
panel = (import ../../../panel/default.nix { }).package;
in
# builtins.trace args.pkgs
{
imports = [
../../../panel/nix/configuration.nix
];
nix.settings = {
extra-experimental-features = "configurable-impure-env";
};
environment.systemPackages = [
inputs.self.outPath
panel
];
@ -36,4 +44,8 @@ in
STATIC_ROOT = "/var/lib/${name}/static";
};
};
systemd.services.${name}.environment = {
REPO_DIR = inputs.self.outPath;
NIX_DIR = pkgs.nix;
};
}

View file

@ -34,6 +34,7 @@ in
export CREDENTIALS_DIRECTORY=${builtins.toString ./.credentials}
export DATABASE_URL="sqlite:///${toString ./src}/db.sqlite3"
'';
NIX_DIR = pkgs.nix;
};
tests = pkgs'.callPackage ./nix/tests.nix { };

View file

@ -39,11 +39,11 @@ class Configuration(BaseModel):
# XXX: hard-code available apex domains for now,
# they will be prefixed by the user name
class Domain(Enum):
EU = "fediversity.eu"
# EU = "fediversity.eu"
NET = "fediversity.net"
domain: Domain = Field(
default=Domain.EU,
default=Domain.NET,
description="DNS domain where to expose services"
)

View file

@ -5,7 +5,7 @@
{{ form.as_p }}
<button class="button" disabled>Deploy</button>
<button class="button" type="submit" >Save</button>
<button class="button" type="submit" name="deploy">Deploy</button>
<button class="button" type="submit" name="save">Save</button>
</form>
{% endblock %}

View file

@ -1,6 +1,10 @@
from enum import Enum
import os
import json
from django.urls import reverse_lazy
import os
import subprocess
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.views.generic import TemplateView, DetailView
@ -10,6 +14,7 @@ from panel import models
from panel.configuration import forms
class Index(TemplateView):
template_name = 'index.html'
@ -41,6 +46,39 @@ class ConfigurationForm(LoginRequiredMixin, FormView):
operator=self.request.user,
)
# Check for deploy button
if "deploy" in self.request.POST.keys():
print("DEPLOYING:")
print(os.getenv("REPO_DIR"))
print(os.getenv("NIX_DIR"))
submission = obj.parsed_value.model_dump_json()
deployment = json.dumps(json.loads(submission) | {
"initialUser": {
"displayName": "Testy McTestface",
"username": "test",
"password": "testtest",
"email": "test@test.com",
},
})
env = {
"DEPLOYMENT": deployment,
"PATH": f"{os.getenv("NIX_DIR")}/bin/",
}
print(f"env: {env}")
print(f"Path: {os.getcwd()}/..")
cmd = [
"nix",
"develop",
"--extra-experimental-features",
"configurable-impure-env",
"--command",
"nixops4",
"--show-trace",
"--verbose",
"apply",
"test",
]
subprocess.run(cmd, cwd=os.getenv("REPO_DIR") or f"{os.getcwd()}/..", env=env)
return obj
# TODO(@fricklerhandwerk):