From 1d7eb45286933ed5aa98b6f63b93c1991fad481b Mon Sep 17 00:00:00 2001
From: clerie <git@clerie.de>
Date: Sun, 23 Mar 2025 14:30:17 +0100
Subject: [PATCH] profiles/serial-console: Add profile for serial console and
 enable on mercury VMs be default

---
 profiles/default.nix                |  1 +
 profiles/mercury-vm/default.nix     |  1 +
 profiles/serial-console/default.nix | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+)
 create mode 100644 profiles/serial-console/default.nix

diff --git a/profiles/default.nix b/profiles/default.nix
index 087804c..0b0b95f 100644
--- a/profiles/default.nix
+++ b/profiles/default.nix
@@ -13,6 +13,7 @@
     ./mercury-vm
     ./netcup
     ./network-fallback-dhcp
+    ./serial-console
     ./wg-clerie
   ];
 
diff --git a/profiles/mercury-vm/default.nix b/profiles/mercury-vm/default.nix
index 819a284..f8dde20 100644
--- a/profiles/mercury-vm/default.nix
+++ b/profiles/mercury-vm/default.nix
@@ -11,6 +11,7 @@ with lib;
   config = mkIf config.profiles.clerie.mercury-vm.enable {
 
     profiles.clerie.fem-net.enable = true;
+    profiles.clerie.serial-console.enable = true;
 
     services.qemuGuest.enable = true;
 
diff --git a/profiles/serial-console/default.nix b/profiles/serial-console/default.nix
new file mode 100644
index 0000000..ce896c0
--- /dev/null
+++ b/profiles/serial-console/default.nix
@@ -0,0 +1,26 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+
+  cfg = config.profiles.clerie.serial-console;
+
+in {
+
+  options.profiles.clerie.serial-console = {
+    enable = mkEnableOption "Use first serial console as termial";
+  };
+
+  config = mkIf cfg.enable {
+
+    boot.kernelParams = [ "console=ttyS0,115200n8" ];
+
+    boot.loader.grub.extraConfig = "
+      serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
+      terminal_input serial
+      terminal_output serial
+    ";
+
+  };
+}