subDesTagesMitExtraKaese 1 month ago
commit
b3473ab8df
4 changed files with 74 additions and 0 deletions
  1. 14 0
      docker-compose.yml
  2. 11 0
      nix-builder/Dockerfile
  3. 6 0
      workspace/build.sh
  4. 43 0
      workspace/rpi2.nix

+ 14 - 0
docker-compose.yml

@@ -0,0 +1,14 @@
+services:
+  nixos-builder:
+    container_name: nixos-builder
+    stdin_open: true
+    tty: true
+    privileged: true
+    build: ./nix-builder
+
+    volumes:
+      #- ./nix:/nix
+      - ./workspace:/workspace
+      
+    environment:
+      - USER=root

+ 11 - 0
nix-builder/Dockerfile

@@ -0,0 +1,11 @@
+FROM nixos/nix
+
+RUN nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs \
+    && nix-channel --update
+
+RUN nix-env -iA nixpkgs.qemu nixpkgs.nixos-generators
+
+RUN mkdir /workspace
+
+WORKDIR /workspace
+CMD ["nix-shell", "-p", "nixos-generators"]

+ 6 - 0
workspace/build.sh

@@ -0,0 +1,6 @@
+
+nix-build '<nixpkgs/nixos>' \
+  -A config.system.build.sdImage \
+  --argstr system armv7l-linux \
+  --arg pkgs 'import <nixpkgs> { crossSystem = { system = "armv7l-linux"; }; }' \
+  -I nixos-config=./rpi2.nix

+ 43 - 0
workspace/rpi2.nix

@@ -0,0 +1,43 @@
+{ config, pkgs, lib, ... }:
+
+{
+  imports = [ <nixpkgs/nixos/modules/installer/sd-card/sd-image.nix> ];
+
+  # Define the image name
+  sdImage.imageBaseName = "nixos-rpi2";
+  sdImage.compressImage = false;
+
+  # Required: Set populateRootCommands
+  sdImage.populateRootCommands = ''
+    mkdir -p ./files
+    echo "NixOS for Raspberry Pi 2" > ./files/welcome.txt
+  '';
+  sdImage.populateFirmwareCommands = "";
+
+  # Bootloader: Use U-Boot for Raspberry Pi 2
+  boot.loader.generic-extlinux-compatible.enable = true;
+  hardware.deviceTree.enable = true;
+  hardware.deviceTree.name = "bcm2836-rpi-2-b.dtb"; # Correct DTB for RPi2
+
+  # Disable GRUB (not used on Raspberry Pi)
+  boot.loader.grub.enable = false;
+
+  # Networking
+  networking.hostName = "nixos-rpi2";
+  networking.wireless.enable = false; # Enable this if using WiFi
+  networking.interfaces.eth0.useDHCP = true;
+
+  # Enable SSH
+  services.openssh.enable = true;
+
+  # User setup
+  users.users.nixos = {
+    isNormalUser = true;
+    initialPassword = "nixos";
+    extraGroups = [ "wheel" ];
+  };
+  users.groups.nixos = {};
+  
+  # Set system version (avoid warnings)
+  system.stateVersion = "25.05";
+}