From 252d5976b14db72f7aab81554d4c2edf3cd104e5 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 8 Apr 2024 15:53:28 +0200 Subject: [PATCH 1/3] Update Thymis Controller and BuildStatus component --- .../thymis_controller/models/flake.nix.j2 | 8 +-- .../models/modules/thymis.py | 7 ++- frontend/src/lib/BuildStatus.svelte | 23 +++++++ thymis-nixos-module.nix | 63 ++++++++++--------- 4 files changed, 67 insertions(+), 34 deletions(-) diff --git a/controller/thymis_controller/models/flake.nix.j2 b/controller/thymis_controller/models/flake.nix.j2 index fd2532a0..676bdf7e 100644 --- a/controller/thymis_controller/models/flake.nix.j2 +++ b/controller/thymis_controller/models/flake.nix.j2 @@ -24,13 +24,13 @@ state-json = builtins.fromJSON (builtins.readFile ./state.json); device-to-nixosConfigurations = d: let - # device-modules are all files in ./hosts/ that end with .nix + # device-modules are all files in ./hosts/ 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/ that end with .nix tag-modules = builtins.concatMap @@ -51,7 +51,7 @@ # ]; # }; { - name = d.hostname; + name = d.identifier; value = nixpkgs.lib.nixosSystem { modules = device-modules ++ tag-modules diff --git a/controller/thymis_controller/models/modules/thymis.py b/controller/thymis_controller/models/modules/thymis.py index b88d80ab..12c121f1 100644 --- a/controller/thymis_controller/models/modules/thymis.py +++ b/controller/thymis_controller/models/modules/thymis.py @@ -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" diff --git a/frontend/src/lib/BuildStatus.svelte b/frontend/src/lib/BuildStatus.svelte index a72cbcd7..9aad9ad4 100644 --- a/frontend/src/lib/BuildStatus.svelte +++ b/frontend/src/lib/BuildStatus.svelte @@ -5,6 +5,18 @@ let stdoutModalOpen = false; let stderrModalOpen = false; + + let errorLinesInStderr: string[] = []; + $: { + const lines = $buildStatus?.stderr?.split('\n') ?? []; + console.log(lines); + 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; + }
@@ -38,5 +50,16 @@
{$buildStatus?.stdout}
+
+ Error Lines: +
    + {#each errorLinesInStderr as errorLine} +
  • {errorLine}
  • + {/each} +
+
+
+
Full Raw Stderr:
+
{$buildStatus?.stderr}
diff --git a/thymis-nixos-module.nix b/thymis-nixos-module.nix index 818eea7f..1dd4a84c 100644 --- a/thymis-nixos-module.nix +++ b/thymis-nixos-module.nix @@ -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 { }; @@ -9,7 +10,6 @@ in { imports = [ inputs.home-manager.nixosModules.default - # ./devices-module.nix "${modulesPath}/profiles/base.nix" ]; options = { @@ -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 = { @@ -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" ]; @@ -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 = { @@ -131,6 +126,16 @@ in }; }; }; - } + services.xserver.displayManager.sddm.enable = true; + services.xserver.displayManager.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 ]; + }) ]; } From 5c9a1069235c332a30abd917ad538eb790f36534 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 8 Apr 2024 16:23:58 +0200 Subject: [PATCH 2/3] Update display manager auto-login configuration --- thymis-nixos-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thymis-nixos-module.nix b/thymis-nixos-module.nix index 1dd4a84c..42104e50 100644 --- a/thymis-nixos-module.nix +++ b/thymis-nixos-module.nix @@ -127,7 +127,7 @@ in }; }; services.xserver.displayManager.sddm.enable = true; - services.xserver.displayManager.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" '' From a6ad892dc03ed20f2fde9ff6ea01a5bc1adc4849 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 8 Apr 2024 16:45:23 +0200 Subject: [PATCH 3/3] Remove console.log statement in BuildStatus.svelte --- frontend/src/lib/BuildStatus.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/lib/BuildStatus.svelte b/frontend/src/lib/BuildStatus.svelte index 9aad9ad4..477099cf 100644 --- a/frontend/src/lib/BuildStatus.svelte +++ b/frontend/src/lib/BuildStatus.svelte @@ -9,7 +9,6 @@ let errorLinesInStderr: string[] = []; $: { const lines = $buildStatus?.stderr?.split('\n') ?? []; - console.log(lines); const trimmedLines = lines.map((line) => line.trim()); const errorLines = trimmedLines.filter((line) => line.startsWith('error:')); const strippedErrorLines = errorLines.map((line) => line.replace('error:', ''));