From 7cdc89ddeb58dfd101e3dd38710e2d8d14a8c2b7 Mon Sep 17 00:00:00 2001
From: roxwize <rae@roxwize.xyz>
Date: Mon, 3 Mar 2025 19:09:08 -0500
Subject: [PATCH] ~

---
 TODO                                        |   1 +
 nixos/flake.lock                            | 199 +++++++++++++++++++-
 nixos/flake.nix                             |  18 +-
 nixos/hosts/desktop.nix                     |   6 +-
 nixos/hosts/near/configuration.nix          |  13 ++
 nixos/hosts/near/hardware-configuration.nix |  20 ++
 nixos/packages.nix                          |   1 +
 7 files changed, 247 insertions(+), 11 deletions(-)
 create mode 100644 nixos/hosts/near/configuration.nix
 create mode 100644 nixos/hosts/near/hardware-configuration.nix

diff --git a/TODO b/TODO
index 87d60c8..cf1da87 100644
--- a/TODO
+++ b/TODO
@@ -40,6 +40,7 @@
 [ ] Personally i think your desktop fucking sucks and you should just switch to kde plasma
  +- [ ] Just see if you can write a yambar plugin that gives you a taskbar...........
 [ ] Should you be using both libretro easyrpg and standalone easyrpg at the same time like you are now ????????
+[ ] FUN IDEA::: Do you see ? https://github.com/nix-community/raspberry-pi-nix/blob/master/rpi/default.nix ??? see if it might be worth trying to make an options set across your config for very non granular at a glance configurations ... (see also https://github.com/nanzhong/env/blob/master/machines/devpi/configuration.nix)
 
 [x] Get PulseAudio sound controls on polybar to work
 [x] Add desktop switching to windows (context menu?)
diff --git a/nixos/flake.lock b/nixos/flake.lock
index 36064f3..830b12d 100644
--- a/nixos/flake.lock
+++ b/nixos/flake.lock
@@ -63,6 +63,40 @@
         "type": "github"
       }
     },
+    "libcamera-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1725630279,
+        "narHash": "sha256-KH30jmHfxXq4j2CL7kv18DYECJRp9ECuWNPnqPZajPA=",
+        "owner": "raspberrypi",
+        "repo": "libcamera",
+        "rev": "69a894c4adad524d3063dd027f5c4774485cf9db",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "repo": "libcamera",
+        "rev": "69a894c4adad524d3063dd027f5c4774485cf9db",
+        "type": "github"
+      }
+    },
+    "libpisp-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1724944683,
+        "narHash": "sha256-Fo2UJmQHS855YSSKKmGrsQnJzXog1cdpkIOO72yYAM4=",
+        "owner": "raspberrypi",
+        "repo": "libpisp",
+        "rev": "28196ed6edcfeda88d23cc5f213d51aa6fa17bb3",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "v1.0.7",
+        "repo": "libpisp",
+        "type": "github"
+      }
+    },
     "nix-flatpak": {
       "locked": {
         "lastModified": 1734128415,
@@ -111,6 +145,22 @@
         "type": "github"
       }
     },
+    "nixpkgs_2": {
+      "locked": {
+        "lastModified": 1736061677,
+        "narHash": "sha256-DjkQPnkAfd7eB522PwnkGhOMuT9QVCZspDpJJYyOj60=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "cbd8ec4de4469333c82ff40d057350c30e9f7d36",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-24.11",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
     "nur": {
       "inputs": {
         "flake-parts": "flake-parts",
@@ -133,6 +183,33 @@
         "type": "github"
       }
     },
+    "raspberry-pi-nix": {
+      "inputs": {
+        "libcamera-src": "libcamera-src",
+        "libpisp-src": "libpisp-src",
+        "nixpkgs": "nixpkgs_2",
+        "rpi-bluez-firmware-src": "rpi-bluez-firmware-src",
+        "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src",
+        "rpi-firmware-src": "rpi-firmware-src",
+        "rpi-linux-6_12_17-src": "rpi-linux-6_12_17-src",
+        "rpi-linux-6_6_78-src": "rpi-linux-6_6_78-src",
+        "rpi-linux-stable-src": "rpi-linux-stable-src",
+        "rpicam-apps-src": "rpicam-apps-src"
+      },
+      "locked": {
+        "lastModified": 1740928520,
+        "narHash": "sha256-NL5qZi0iEEvQK9kMF6r48FOk5WMdQExCqodRH3kEr0g=",
+        "owner": "nix-community",
+        "repo": "raspberry-pi-nix",
+        "rev": "3bfda6add79c55f9bf143fac928f54484d450e87",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "raspberry-pi-nix",
+        "type": "github"
+      }
+    },
     "root": {
       "inputs": {
         "fenix": "fenix",
@@ -140,7 +217,127 @@
         "nix-flatpak": "nix-flatpak",
         "nixpkgs": "nixpkgs",
         "nixpkgs-unstable": "nixpkgs-unstable",
-        "nur": "nur"
+        "nur": "nur",
+        "raspberry-pi-nix": "raspberry-pi-nix"
+      }
+    },
+    "rpi-bluez-firmware-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1708969706,
+        "narHash": "sha256-KakKnOBeWxh0exu44beZ7cbr5ni4RA9vkWYb9sGMb8Q=",
+        "owner": "RPi-Distro",
+        "repo": "bluez-firmware",
+        "rev": "78d6a07730e2d20c035899521ab67726dc028e1c",
+        "type": "github"
+      },
+      "original": {
+        "owner": "RPi-Distro",
+        "ref": "bookworm",
+        "repo": "bluez-firmware",
+        "type": "github"
+      }
+    },
+    "rpi-firmware-nonfree-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1723266537,
+        "narHash": "sha256-T7eTKXqY9cxEMdab8Snda4CEOrEihy5uOhA6Fy+Mhnw=",
+        "owner": "RPi-Distro",
+        "repo": "firmware-nonfree",
+        "rev": "4b356e134e8333d073bd3802d767a825adec3807",
+        "type": "github"
+      },
+      "original": {
+        "owner": "RPi-Distro",
+        "ref": "bookworm",
+        "repo": "firmware-nonfree",
+        "type": "github"
+      }
+    },
+    "rpi-firmware-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1728405098,
+        "narHash": "sha256-4gnK0KbqFnjBmWia9Jt2gveVWftmHrprpwBqYVqE/k0=",
+        "owner": "raspberrypi",
+        "repo": "firmware",
+        "rev": "7bbb5f80d20a2335066a8781459c9f33e5eebc64",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "1.20241008",
+        "repo": "firmware",
+        "type": "github"
+      }
+    },
+    "rpi-linux-6_12_17-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1740765145,
+        "narHash": "sha256-hoCsGc4+RC/2LmxDtswLBL5ZhWlw4vSiL4Vkl39r2MU=",
+        "owner": "raspberrypi",
+        "repo": "linux",
+        "rev": "5985ce32e511f4e8279a841a1b06a8c7d972b386",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "rpi-6.12.y",
+        "repo": "linux",
+        "type": "github"
+      }
+    },
+    "rpi-linux-6_6_78-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1740503700,
+        "narHash": "sha256-Y8+ot4Yi3UKwlZK3ap15rZZ16VZDvmeFkD46+6Ku7bE=",
+        "owner": "raspberrypi",
+        "repo": "linux",
+        "rev": "2e071057fded90e789c0101498e45a1778be93fe",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "rpi-6.6.y",
+        "repo": "linux",
+        "type": "github"
+      }
+    },
+    "rpi-linux-stable-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1728403745,
+        "narHash": "sha256-phCxkuO+jUGZkfzSrBq6yErQeO2Td+inIGHxctXbD5U=",
+        "owner": "raspberrypi",
+        "repo": "linux",
+        "rev": "5aeecea9f4a45248bcf564dec924965e066a7bfd",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "stable_20241008",
+        "repo": "linux",
+        "type": "github"
+      }
+    },
+    "rpicam-apps-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1727515047,
+        "narHash": "sha256-qCYGrcibOeGztxf+sd44lD6VAOGoUNwRqZDdAmcTa/U=",
+        "owner": "raspberrypi",
+        "repo": "rpicam-apps",
+        "rev": "a8ccf9f3cd9df49875dfb834a2b490d41d226031",
+        "type": "github"
+      },
+      "original": {
+        "owner": "raspberrypi",
+        "ref": "v1.5.2",
+        "repo": "rpicam-apps",
+        "type": "github"
       }
     },
     "rust-analyzer-src": {
diff --git a/nixos/flake.nix b/nixos/flake.nix
index 4599df3..01df7c6 100644
--- a/nixos/flake.nix
+++ b/nixos/flake.nix
@@ -19,25 +19,25 @@
             url = "github:nix-community/fenix";
             inputs.nixpkgs.follows = "nixpkgs";
         };
+        # Raspberry Pi support
+        raspberry-pi-nix.url = "github:nix-community/raspberry-pi-nix";
     };
 
     outputs = { self, nixpkgs, home-manager, nix-flatpak, ... }@inputs: {
         nixosConfigurations =
             let
-                system = hostname: {
+                mkSystem = hostname: arch: with nixpkgs; {
                     name = hostname;
-                    value = nixpkgs.lib.nixosSystem {
-                        system = "x86_64-linux";
+                    value = lib.nixosSystem {
+                        system = "${arch}-linux";
                         specialArgs = { inherit inputs; };
-                        modules = [
-                            nix-flatpak.nixosModules.nix-flatpak
-                            ./hosts/${hostname}/configuration.nix
-                        ];
+                        modules = [ ./hosts/${hostname}/configuration.nix ];
                     };
                 };
             in builtins.listToAttrs [
-                (system "ioides")
-                (system "qemu")
+                (mkSystem "ioides" "x86_64")    # main pc
+                (mkSystem "qemu"   "x86_64")    # emulatr...........
+                (mkSystem "near"   "aarch_64")  # raspberry pi 5 home server
             ];
 
         homeConfigurations.rae = home-manager.lib.homeManagerConfiguration {
diff --git a/nixos/hosts/desktop.nix b/nixos/hosts/desktop.nix
index bd74d28..edd50ff 100644
--- a/nixos/hosts/desktop.nix
+++ b/nixos/hosts/desktop.nix
@@ -1,6 +1,7 @@
 { config, pkgs, inputs, ... }:
 {
     imports = [
+        inputs.nix-flatpak.nixosModules.nix-flatpak
         ../packages.nix
     ];
 
@@ -14,7 +15,10 @@
 
     security.polkit.enable = true;
 
-    nix.settings.experimental-features = [ "nix-command" "flakes" ];
+    nix.settings = {
+        experimental-features = [ "nix-command" "flakes" ];
+        trusted-users = [ "root" "rae" ];
+    };
     nixpkgs = {
         config.allowUnfree = true;
         overlays = import ../overlays.nix inputs;
diff --git a/nixos/hosts/near/configuration.nix b/nixos/hosts/near/configuration.nix
new file mode 100644
index 0000000..62f1921
--- /dev/null
+++ b/nixos/hosts/near/configuration.nix
@@ -0,0 +1,13 @@
+{ inputs, ... }: {
+	imports = [
+		inputs.raspberry-pi-nix.nixosModules.raspberry-pi
+		inputs.raspberry-pi-nix.nixosModules.sd-image
+		./hardware-configuration.nix
+	];
+
+    networking.hostName = "near";
+
+    time.timeZone = "America/New_York";
+
+    system.stateVersion = "24.11";
+}
diff --git a/nixos/hosts/near/hardware-configuration.nix b/nixos/hosts/near/hardware-configuration.nix
new file mode 100644
index 0000000..c52b989
--- /dev/null
+++ b/nixos/hosts/near/hardware-configuration.nix
@@ -0,0 +1,20 @@
+{ ... }: {
+	raspberry-pi-nix.board = "bcm2712"; # RPI5 64bit
+	hardware.raspberry-pi.config.all = let 
+		o = k: v: {
+			name = k;
+			value = {
+				enable = true;
+				value = v;
+			};
+		};
+	in {
+		base-dt-params = builtins.listToAttrs [
+			(o "BOOT_UART" 1)
+			(o "uart_2ndstage" 1)
+		];
+		dt-overlays = builtins.listToAttrs [
+			(o "disable-bt" {})
+		];
+	};
+}
diff --git a/nixos/packages.nix b/nixos/packages.nix
index 297b1a1..d3c05e5 100644
--- a/nixos/packages.nix
+++ b/nixos/packages.nix
@@ -63,6 +63,7 @@
 		posy-cursors                                             # Posy's Improved Cursors for Linux
 		pantheon.elementary-gtk-theme                            # GTK theme designed to be smooth, attractive, fast, and usable
 		# network
+		cachix                                                   # Command-line client for Nix binary cache hosting
 		ngrok                                                    # Allows you to expose a web server running on your local machine to the internet
 		nicotine-plus                                            # Graphical client for the SoulSeek peer-to-peer system
 		playit-agent                                             # The playit program