From c66dd11217c3493a4c9012e4830c56a7efcf74b7 Mon Sep 17 00:00:00 2001
From: DerGrumpf
Date: Wed, 26 Nov 2025 15:17:08 +0100
Subject: [PATCH] Added Raspi 4 Conf
---
hosts/rpi4/configuration.nix | 197 ++++++++++++++++++++++++++
hosts/rpi4/fan-controll.nix | 50 +++++++
hosts/rpi4/hardware-configuration.nix | 26 ++++
3 files changed, 273 insertions(+)
create mode 100644 hosts/rpi4/configuration.nix
create mode 100644 hosts/rpi4/fan-controll.nix
create mode 100644 hosts/rpi4/hardware-configuration.nix
diff --git a/hosts/rpi4/configuration.nix b/hosts/rpi4/configuration.nix
new file mode 100644
index 0000000..a37056d
--- /dev/null
+++ b/hosts/rpi4/configuration.nix
@@ -0,0 +1,197 @@
+{ config, lib, pkgs, ... }:
+
+{
+ imports =
+ [ # Include the results of the hardware scan.
+ ./hardware-configuration.nix
+ ./fan-controll.nix
+ ];
+
+ # Use the extlinux boot loader. (NixOS wants to enable GRUB by default)
+ boot.loader.grub.enable = false;
+ # Enables the generation of /boot/extlinux/extlinux.conf
+ boot.loader.generic-extlinux-compatible.enable = true;
+
+ # 📝 Uncomment the default hostname.
+ networking.hostName = "nix-rpi4-1"; # Define your hostname.
+ # Pick only one of the below networking options.
+ # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
+ # 📝 If you are using ethernet to connect to the device, uncomment the NetworkManager option.
+ networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
+
+ # Set your time zone.
+ time.timeZone = "Europe/Berlin";
+
+ # Configure network proxy if necessary
+ # networking.proxy.default = "http://user:password@proxy:port/";
+ # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
+
+ # Select internationalisation properties.
+ # i18n.defaultLocale = "en_US.UTF-8";
+ # console = {
+ # font = "Lat2-Terminus16";
+ # keyMap = "us";
+ # useXkbConfig = true; # use xkb.options in tty.
+ # };
+
+ # Enable the X11 windowing system.
+ # services.xserver.enable = true;
+
+ # Configure keymap in X11
+ # services.xserver.xkb.layout = "us";
+ # services.xserver.xkb.options = "eurosign:e,caps:escape";
+
+ # Enable CUPS to print documents.
+ # services.printing.enable = true;
+
+ # Enable sound.
+ # hardware.pulseaudio.enable = true;
+ # OR
+ # services.pipewire = {
+ # enable = true;
+ # pulse.enable = true;
+ # };
+
+ # Enable touchpad support (enabled default in most desktopManager).
+ # services.libinput.enable = true;
+
+ # Define a user account. Don't forget to set a password with 'passwd'.
+ # users.users.alice = {
+ # isNormalUser = true;
+ # extraGroups = [ "wheel" ]; # Enable 'sudo' for the user.
+ # packages = with pkgs; [
+ # firefox
+ # tree
+ # ];
+ # };
+
+ # Enable Raspberry Pi 4 GPIO support
+ # hardware.raspberry-pi."4".enable = true;
+
+ # 📝 Make sure the `nixos` user stays.
+ users.users.nixos = {
+ isNormalUser = true;
+ extraGroups = [ "wheel" "gpio" ]; # Enable 'sudo' for the user.
+ shell = pkgs.fish;
+ # 📝 Re-add the trusted SSH keys.
+ openssh.authorizedKeys.keys = [
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCaLHfxVylghDMYR8t4QMUpeRRqXasNABQKBEy9MmhbUXCcWiPbPMSZH8FMHON34rm2OrXP1kY/8jQxqBJDA+SqpFR2AZ4Khk9iVMaq5GHxxpn2amZUjoBa+fB29WaiE1npV5JVJV3O0ylw6GtiCnpneE6fGx2MO1vOY/7zKrUX/OK7WfwkDpeEzZgV/j/md917HrzUVeZwdeTq3WCRO8Gew6R8Xs6FRjSiGuH0dq14D4Ow5Zf1cI1jx+JfD/5vGasw8HXPu1NdxsOE+6D7/22IKqGr+S74/lAoyyD5qqk0s05lw8UY/PXBLJaNLZu9Fwx0BqTHpJEvftpmvd9wUxgR3msx9VXtKNSrqivIbDgeU+3oGzzkrGZODl7FCp4XKGmbrX85Z6lKwEGgv5jez4MLZcmT86bxB7m1wIbqSbVtfhS+GI7yPTA/kLzzFa14Im/+LTj95pb8qs2ALMwTMP1j2f9A6D3RriOFihL+68qn+YbK58KuV1R0f+CQRmlfVbk= phil@web.cyperpunk.de"
+ ];
+ # 📝 Give user an empty password.
+ # ⚠️ This is pretty risky, so use only in initial setup.
+ password = "1P2h3i4lon";
+ };
+
+ users.users.phil = {
+ isNormalUser = true;
+ extraGroups = [ "wheel" "gpio" "i2c" ]; # Enable 'sudo' for the user.
+ shell = pkgs.fish;
+ # 📝 Re-add the trusted SSH keys.
+ openssh.authorizedKeys.keys = [
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCaLHfxVylghDMYR8t4QMUpeRRqXasNABQKBEy9MmhbUXCcWiPbPMSZH8FMHON34rm2OrXP1kY/8jQxqBJDA+SqpFR2AZ4Khk9iVMaq5GHxxpn2amZUjoBa+fB29WaiE1npV5JVJV3O0ylw6GtiCnpneE6fGx2MO1vOY/7zKrUX/OK7WfwkDpeEzZgV/j/md917HrzUVeZwdeTq3WCRO8Gew6R8Xs6FRjSiGuH0dq14D4Ow5Zf1cI1jx+JfD/5vGasw8HXPu1NdxsOE+6D7/22IKqGr+S74/lAoyyD5qqk0s05lw8UY/PXBLJaNLZu9Fwx0BqTHpJEvftpmvd9wUxgR3msx9VXtKNSrqivIbDgeU+3oGzzkrGZODl7FCp4XKGmbrX85Z6lKwEGgv5jez4MLZcmT86bxB7m1wIbqSbVtfhS+GI7yPTA/kLzzFa14Im/+LTj95pb8qs2ALMwTMP1j2f9A6D3RriOFihL+68qn+YbK58KuV1R0f+CQRmlfVbk= phil@web.cyperpunk.de"
+ ];
+ # 📝 Give user an empty password.
+ # ⚠️ This is pretty risky, so use only in initial setup.
+ password = "1P2h3i4lon";
+ };
+ # 📝 Remove the need to be prompted for a password when using `sudo`.
+ # ⚠️ This is pretty risky, so use only in initial setup.
+ security.sudo.wheelNeedsPassword = false;
+
+ # List packages installed in system profile. To search, run:
+ # $ nix search wget
+ # 📝 Uncomment system packages to ensure that vim access stays.
+ environment.systemPackages = with pkgs; [
+ vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
+ wget
+ git
+ fastfetch
+ neovim
+ curl
+ fish
+ kitty
+ libgpiod
+ hping
+ gcc
+ libraspberrypi
+ eza
+ fzf
+ stress-ng
+ i2c-tools
+ ];
+
+ # Enable fish shell
+ programs.fish = {
+ enable = true;
+ shellAliases = {
+ ls = "eza";
+ la = "eza -la";
+ f = "fzf";
+ i = "kitty +kitten icat";
+ tw = "tw --theme config";
+ };
+ interactiveShellInit = ''
+ starship init fish | source
+ fzf --fish | source
+ function fish_greeting
+ fastfetch
+ end
+ '';
+ };
+
+ # Some programs need SUID wrappers, can be configured further or are
+ # started in user sessions.
+ # programs.mtr.enable = true;
+ # programs.gnupg.agent = {
+ # enable = true;
+ # enableSSHSupport = true;
+ # };
+
+ # List services that you want to enable:
+
+ # Enable the OpenSSH daemon.
+ # services.openssh.enable = true;
+
+ # 📝 Add SSH access, but only using SSH keys, and to the NixOS user.
+ services.openssh = {
+ enable = true;
+ authorizedKeysInHomedir = true; # Do not trust SSH keys in ~/.ssh/authorized_keys.
+ settings = {
+ PasswordAuthentication = true; # Disable password authentication.
+ AllowUsers = [ "nixos" "phil" ]; # Allow only login via the "nixos" user.
+ PermitRootLogin = "no"; # Disable root login via SSH.
+ };
+ };
+
+ # Open ports in the firewall.
+ # networking.firewall.allowedTCPPorts = [ ... ];
+ # networking.firewall.allowedUDPPorts = [ ... ];
+ # Or disable the firewall altogether.
+ # 📝 Uncomment firewall option if you are okay with disabling the firewall entirely during initial setup.
+ networking.firewall.enable = false;
+
+ # Copy the NixOS configuration file and link it from the resulting system
+ # (/run/current-system/configuration.nix). This is useful in case you
+ # accidentally delete configuration.nix.
+ # system.copySystemConfiguration = true;
+
+ # This option defines the first version of NixOS you have installed on this particular machine,
+ # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
+ #
+ # Most users should NEVER change this value after the initial install, for any reason,
+ # even if you've upgraded your system to a new NixOS release.
+ #
+ # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
+ # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
+ # to actually do that.
+ #
+ # This value being lower than the current NixOS release does NOT mean your system is
+ # out of date, out of support, or vulnerable.
+ #
+ # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
+ # and migrated your data accordingly.
+ #
+ # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
+ system.stateVersion = "24.11"; # Did you read the comment?
+
+}
diff --git a/hosts/rpi4/fan-controll.nix b/hosts/rpi4/fan-controll.nix
new file mode 100644
index 0000000..3e2b2cd
--- /dev/null
+++ b/hosts/rpi4/fan-controll.nix
@@ -0,0 +1,50 @@
+{ pkgs, ... }:
+{
+ environment.systemPackages = with pkgs; [
+ (python3.withPackages (ps: [ ps.smbus2 ]))
+ ];
+
+
+ # Fan control service
+ systemd.services.argon-fan = {
+ description = "Argon40 Fan Control via I2C";
+ after = [ "multi-user.target" ];
+ wantedBy = [ "multi-user.target" ];
+
+ serviceConfig = {
+ Type = "simple";
+ Restart = "always";
+ ExecStart = pkgs.writeScript "argon-fan.py" ''
+ #!${pkgs.python3.withPackages (ps: [ ps.smbus2 ])}/bin/python3
+ import smbus2
+ import time
+ import subprocess
+
+ bus = smbus2.SMBus(1)
+
+ while True:
+ try:
+ # Get temperature
+ temp_output = subprocess.check_output(['${pkgs.libraspberrypi}/bin/vcgencmd', 'measure_temp']).decode()
+ temp = float(temp_output.replace("temp=","").replace("'C\n",""))
+
+ # Set fan speed based on temperature (0-100)
+ if temp < 55:
+ speed = 0
+ elif temp < 60:
+ speed = 25
+ elif temp < 65:
+ speed = 50
+ else:
+ speed = 100
+
+ bus.write_byte(0x1a, speed)
+ print(f"Temp: {temp}°C, Fan: {speed}%")
+ except Exception as e:
+ print(f"Error: {e}")
+
+ time.sleep(30)
+ '';
+ };
+ };
+}
diff --git a/hosts/rpi4/hardware-configuration.nix b/hosts/rpi4/hardware-configuration.nix
new file mode 100644
index 0000000..cd33b81
--- /dev/null
+++ b/hosts/rpi4/hardware-configuration.nix
@@ -0,0 +1,26 @@
+{ config, lib, pkgs, modulesPath, ... }:
+{
+ imports =
+ [ (modulesPath + "/installer/scan/not-detected.nix")
+ ];
+ boot.initrd.availableKernelModules = [ "xhci_pci" ];
+ boot.initrd.kernelModules = [ ];
+ boot.kernelModules = [ ];
+ boot.extraModulePackages = [ ];
+ fileSystems."/" =
+ { device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
+ fsType = "ext4";
+ };
+ fileSystems."/storage" =
+ { device = "/dev/disk/by-label/STORAGE";
+ fsType = "ext4";
+ options = [ "nofail" ];
+ };
+ swapDevices = [
+ { device = "/swapfile";
+ size = 4096;
+ }
+ ];
+ nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
+ hardware.i2c.enable = true;
+}