Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move thymis controller functionality behind settings to activate on device #7

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controller/thymis_controller/models/flake.nix.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
state-json = builtins.fromJSON (builtins.readFile ./state.json);
device-to-nixosConfigurations = d:
let
# device-modules are all files in ./hosts/<hostname> that end with .nix
# device-modules are all files in ./hosts/<identifier> that end with .nix
device-modules = nixpkgs.lib.mapAttrsToList
(path: type: ./hosts/${d.hostname}/${path})
(path: type: ./hosts/${d.identifier}/${path})
(nixpkgs.lib.filterAttrs
(f: t: t == "regular" && nixpkgs.lib.hasSuffix ".nix" (builtins.toString f))
(
builtins.readDir ./hosts/${d.hostname}
builtins.readDir ./hosts/${d.identifier}
));
# for all tags, get them. For each tag, all files in ./tags/<tag> that end with .nix
tag-modules = builtins.concatMap
Expand All @@ -51,7 +51,7 @@
# ];
# };
{
name = d.hostname;
name = d.identifier;
value = nixpkgs.lib.nixosSystem {
modules = device-modules
++ tag-modules
Expand Down
7 changes: 6 additions & 1 deletion controller/thymis_controller/models/modules/thymis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ class ThymisController(Module):
displayName: str = "Thymis Controller"

repo_dir: Setting = Setting(
name="thymis.config.repo-dir",
name="thymis.controller.repo-dir",
type="string",
default="/var/lib/thymis",
description="The directory where the thymis repository is located.",
example="/var/lib/thymis",
)

def write_nix_settings(self, f, module_settings: ModuleSettings, priority: int):
f.write(f" thymis.controller.enable = true;\n")

return super().write_nix_settings(f, module_settings, priority)


class ThymisDevice(Module):
displayName: str = "Thymis Device"
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/lib/BuildStatus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

let stdoutModalOpen = false;
let stderrModalOpen = false;

let errorLinesInStderr: string[] = [];
$: {
const lines = $buildStatus?.stderr?.split('\n') ?? [];
const trimmedLines = lines.map((line) => line.trim());
const errorLines = trimmedLines.filter((line) => line.startsWith('error:'));
const strippedErrorLines = errorLines.map((line) => line.replace('error:', ''));
const trimmedStrippedErrorLines = strippedErrorLines.map((line) => line.trim());
const nonEmptyErrorLines = trimmedStrippedErrorLines.filter((line) => line.length > 0);
errorLinesInStderr = nonEmptyErrorLines;
}
</script>

<div class="flex justify-between items-center gap-1">
Expand Down Expand Up @@ -38,5 +49,16 @@
<pre class="w-full text-sm font-light z-50 hover:z-50">{$buildStatus?.stdout}</pre>
</Modal>
<Modal title="Standard Error" bind:open={stderrModalOpen} autoclose outsideclose size="xl">
<div class="grid gap-1">
<span class="dark:text-white">Error Lines:</span>
<ul class="flex gap-1">
{#each errorLinesInStderr as errorLine}
<li class="text-red-500">{errorLine}</li>
{/each}
</ul>
</div>
<div class="grid gap-1">
<div class="dark:text-white">Full Raw Stderr:</div>
</div>
<pre class="w-full text-sm font-light z-50 hover:z-50">{$buildStatus?.stderr}</pre>
</Modal>
63 changes: 34 additions & 29 deletions thymis-nixos-module.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ config, lib, pkgs, inputs, modulesPath, ... }:
let
cfg = config.thymis.config;
controllerCfg = config.thymis.controller;
use-wifi = cfg.wifi-ssid != "" && cfg.wifi-password != "";
# Define the settings format used for this program
settingsFormat = pkgs.formats.json { };
Expand All @@ -9,7 +10,6 @@ in
{
imports = [
inputs.home-manager.nixosModules.default
# ./devices-module.nix
"${modulesPath}/profiles/base.nix"
];
options = {
Expand Down Expand Up @@ -46,11 +46,17 @@ in
default = { };
description = "Thymis configuration";
};
thymis.controller = {
enable = lib.mkEnableOption "the Thymis controller";
repo-dir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/thymis";
description = "Directory where the controller will store its state";
};
};
};
config = lib.mkMerge [
{
# thymis.config = thymis-config;
system.build.download-path = lib.mkDefault (throw "thymis-config.system.build.download-path is not set");
nix.settings.experimental-features = [ "nix-command" "flakes" ];
users.users.root.password = cfg.password;
services.openssh = {
Expand All @@ -74,27 +80,28 @@ in
system.nixos.distroName = "Thymis - NixOS";
services.getty.autologinUser = lib.mkForce null;
services.xserver.enable = true;
services.xserver.displayManager = {
sddm.enable = true;
autoLogin = {
enable = true;
user = "nixos";
};
};
users.users.nixos = {
isNormalUser = true;
createHome = true;
password = cfg.password;
};
services.xserver.windowManager.i3.enable = true;
services.xserver.windowManager.i3.configFile = pkgs.writeText "i3-config" ''
# i3 config file (v4)
bar mode invisible;
exec ${pkgs.firefox}/bin/firefox --kiosk http://localhost:3000/kiosk
'';
networking.firewall = {
allowedTCPPorts = [ 22 3000 ];
};
}
(lib.mkIf controllerCfg.enable {
systemd.services.thymis-controller = {
description = "Thymis controller";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = "${inputs.thymis.packages.${config.nixpkgs.hostPlatform.system}.thymis-controller}/bin/thymis-controller";
path = [
"/run/current-system/sw"
];
environment = {
REPO_PATH = controllerCfg.state-dir;
};
};
systemd.services.thymis-frontend = {
description = "Thymis frontend";
after = [ "network.target" ];
Expand All @@ -109,18 +116,6 @@ in
"/run/current-system/sw"
];
};
systemd.services.thymis-controller = {
description = "Thymis controller";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = "${inputs.thymis.packages.${config.nixpkgs.hostPlatform.system}.thymis-controller}/bin/thymis-controller";
path = [
"/run/current-system/sw"
];
environment = {
REPO_PATH = "/var/lib/thymis";
};
};
services.nginx = {
enable = true;
virtualHosts.default = {
Expand All @@ -131,6 +126,16 @@ in
};
};
};
}
services.xserver.displayManager.sddm.enable = true;
services.xserver.displayManager.autoLogin.enable = true;
services.xserver.displayManager.autoLogin.user = "nixos";
services.xserver.windowManager.i3.enable = true;
services.xserver.windowManager.i3.configFile = pkgs.writeText "i3-config" ''
# i3 config file (v4)
bar mode invisible;
exec ${pkgs.firefox}/bin/firefox --kiosk http://localhost:3000/kiosk
'';
networking.firewall.allowedTCPPorts = [ 80 443 ];
})
];
}
Loading