From 21de12cd6e63adf463674942f1a8f9b658f47945 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Thu, 9 Apr 2026 13:14:01 -0500 Subject: jta changes --- modules/desktop/hjem/programs/foot.nix | 2 +- modules/desktop/hjem/wm/sway.nix | 50 +++++++ modules/nix/nixos/default.nix | 5 +- modules/services/nixos/jta/assignments.html | 148 +++++++++++++++++++++ modules/services/nixos/jta/default.nix | 1 + modules/services/nixos/jta/index.html | 199 ++++++++++++++-------------- modules/services/nixos/jta/main.go | 31 +++++ modules/services/nixos/jta/style.css | 29 ++++ modules/user/nixos/default.nix | 18 +-- 9 files changed, 374 insertions(+), 109 deletions(-) create mode 100644 modules/services/nixos/jta/assignments.html (limited to 'modules') diff --git a/modules/desktop/hjem/programs/foot.nix b/modules/desktop/hjem/programs/foot.nix index 7fe88ab..d10db24 100644 --- a/modules/desktop/hjem/programs/foot.nix +++ b/modules/desktop/hjem/programs/foot.nix @@ -15,7 +15,7 @@ # key-bindings.spawn-terminal = "Control+Return"; - colors = with config.collinux.palette; { + colors-dark = with config.collinux.palette; { alpha = "0.6"; foreground = base05; diff --git a/modules/desktop/hjem/wm/sway.nix b/modules/desktop/hjem/wm/sway.nix index a0bfa4e..441670b 100644 --- a/modules/desktop/hjem/wm/sway.nix +++ b/modules/desktop/hjem/wm/sway.nix @@ -6,6 +6,54 @@ }: let cfg = config.collinux.desktop.wm.sway; + batteryNotify = pkgs.writeShellApplication { + name = "battery-notify"; + runtimeInputs = [ + pkgs.coreutils + pkgs.libnotify + ]; + text = '' + energy_now=$(cat /sys/class/power_supply/BAT0/energy_now) + energy_full=$(cat /sys/class/power_supply/BAT0/energy_full) + percentage=$((energy_now * 100 / energy_full)) + percent_display=$(printf "%.0f%%" "$percentage") + + notify-send \ + -t 2000 \ + -h int:value:"$percentage" \ + -h string:x-dunst-stack-tag:battery \ + "Battery" \ + "$percent_display" + ''; + }; + + powerMenu = pkgs.writeShellApplication { + name = "power-menu"; + runtimeInputs = [ + pkgs.fuzzel + pkgs.systemd + pkgs.sway + ]; + text = '' + selection=$(printf '%s\n' logout suspend reboot shutdown | fuzzel --dmenu --prompt "power: ") + + case "$selection" in + logout) + swaymsg exit + ;; + suspend) + systemctl suspend + ;; + reboot) + systemctl reboot + ;; + shutdown) + systemctl poweroff + ;; + esac + ''; + }; + settings = with config.collinux.palette; '' exec { ${config.collinux.desktop.wallpaper_cmd} @@ -59,7 +107,9 @@ Mod4+Return exec foot Mod4+Space exec fuzzel + Mod4+Escape exec '${powerMenu}/bin/power-menu' Mod4+b exec firefox + Mod4+k exec '${batteryNotify}/bin/battery-notify' Mod4+w exec '${pkgs.iwmenu}/bin/iwmenu -l fuzzel -i font -s 2' Mod4+e exec '${pkgs.bzmenu}/bin/bzmenu -l fuzzel -i font -s 2' diff --git a/modules/nix/nixos/default.nix b/modules/nix/nixos/default.nix index 7441236..f39f368 100644 --- a/modules/nix/nixos/default.nix +++ b/modules/nix/nixos/default.nix @@ -19,12 +19,11 @@ daemonIOSchedClass = "idle"; settings = { + flake-registry = "${inputs.flake-registry}/flake-registry.json"; + extra-experimental-features = ["nix-command" "flakes" "pipe-operators"]; auto-optimise-store = true; use-xdg-base-directories = true; - - # lazy-trees = true; - # eval-cores = 0; }; # Disable channels diff --git a/modules/services/nixos/jta/assignments.html b/modules/services/nixos/jta/assignments.html new file mode 100644 index 0000000..3031a29 --- /dev/null +++ b/modules/services/nixos/jta/assignments.html @@ -0,0 +1,148 @@ + + + + + + jta@ganymede + + + + +
Juksere Trives Aldri
+ +
+ + + + diff --git a/modules/services/nixos/jta/default.nix b/modules/services/nixos/jta/default.nix index c1ea012..d2908bc 100644 --- a/modules/services/nixos/jta/default.nix +++ b/modules/services/nixos/jta/default.nix @@ -33,6 +33,7 @@ in { environment = { PORT = toString cfg.port; ROOT_DIR = "/media/jta"; + AUTH_PASSWORD_HASH = "550b6785c4bce2ab41a5e2eaa1eb43172d5abbd58237f1c78cd32cb190edc2c5"; # alfreddabuttlerwithtwots }; serviceConfig = { diff --git a/modules/services/nixos/jta/index.html b/modules/services/nixos/jta/index.html index fd93de6..96b6f5f 100644 --- a/modules/services/nixos/jta/index.html +++ b/modules/services/nixos/jta/index.html @@ -3,127 +3,132 @@ - jta@ganymede + JTA Login -
Juksere Trives Aldri
+
+

JTA Portal

+

Public landing page. Login is required to view assignments and all other pages.

+ +
+ +
-
+
+
diff --git a/modules/services/nixos/jta/main.go b/modules/services/nixos/jta/main.go index 3e5fc1f..1390d7f 100644 --- a/modules/services/nixos/jta/main.go +++ b/modules/services/nixos/jta/main.go @@ -29,8 +29,28 @@ var styleCSS string //go:embed index.html var indexHTML string +//go:embed assignments.html +var assignmentsHTML string + var pageTmpl = template.Must(template.New("md_template.html").Parse(mdTemplate)) +const authCookieName = "jta_auth" + +func isAuthenticated(r *http.Request) bool { + expectedHash := strings.TrimSpace(os.Getenv("AUTH_PASSWORD_HASH")) + if expectedHash == "" { + return false + } + + cookie, err := r.Cookie(authCookieName) + if err != nil { + return false + } + + providedHash := strings.TrimSpace(cookie.Value) + return strings.EqualFold(providedHash, expectedHash) +} + func serveMarkdown(w http.ResponseWriter, r *http.Request) { // Prevent path traversal clean := filepath.Clean(r.URL.Path) @@ -81,6 +101,17 @@ func main() { return } + if !isAuthenticated(r) { + http.Error(w, "unauthorized", http.StatusUnauthorized) + return + } + + if r.URL.Path == "/assignments" || r.URL.Path == "/assignments.html" { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write([]byte(assignmentsHTML)) + return + } + // Intercept markdown files if strings.HasSuffix(r.URL.Path, ".md") { serveMarkdown(w, r) diff --git a/modules/services/nixos/jta/style.css b/modules/services/nixos/jta/style.css index 1d52d19..ec09ca9 100644 --- a/modules/services/nixos/jta/style.css +++ b/modules/services/nixos/jta/style.css @@ -124,6 +124,35 @@ code { border-radius: 6px; } +img { + display: block; + max-width: 100%; + height: auto; + margin: 1rem 0; + border-radius: 10px; +} + +p > img, +li > img { + margin: 0.75rem 0; +} + +a > img { + transition: transform 0.15s ease, box-shadow 0.15s ease; +} + +a:hover > img { + transform: translateY(-1px); + box-shadow: 0 8px 20px rgba(2, 6, 23, 0.45); +} + +img[width], +img[height] { + width: auto; + height: auto; + max-width: 100%; +} + /* Links */ a { color: #93c5fd; diff --git a/modules/user/nixos/default.nix b/modules/user/nixos/default.nix index 71f6c14..68238d6 100644 --- a/modules/user/nixos/default.nix +++ b/modules/user/nixos/default.nix @@ -34,14 +34,16 @@ in { programs.ssh = { systemd-ssh-proxy.enable = false; - knownHosts = builtins.mapAttrs (_: data: - { - publicKey = data.host_pubkey; - } - // (lib.optionalAttrs (data ? hostnames) { - hostNames = data.hostnames; - })) - hosts; + knownHosts = + hosts + |> lib.filterAttrs (_: data: data ? host_pubkey) + |> builtins.mapAttrs (_: data: + { + publicKey = data.host_pubkey; + } + // (lib.optionalAttrs (data ? hostnames) { + hostNames = data.hostnames; + })); }; hjem = { -- cgit v1.3.1