NixOS on ARM/Raspberry Pi 4: Difference between revisions

imported>Ymarkus
Some clarification (see discussion) and change bootloader
imported>Artturin
add a working configuration
Line 43: Line 43:
''(Until the generic image works, a [https://hydra.nixos.org/job/nixos/trunk-combined/nixos.sd_image_raspberrypi4.aarch64-linux temporary device-specific image is build on Hydra]. Note that this image is not using u-boot, but rather the Raspberry Pi specific bootloader configuration.)''
''(Until the generic image works, a [https://hydra.nixos.org/job/nixos/trunk-combined/nixos.sd_image_raspberrypi4.aarch64-linux temporary device-specific image is build on Hydra]. Note that this image is not using u-boot, but rather the Raspberry Pi specific bootloader configuration.)''


=== Minimal configuration ===
=== Configuration ===


Using <code>nixos-generate-config</code> will not generate the required minimal configuration. Change the lines about booting to the following (from [https://github.com/NixOS/nixpkgs/pull/68265#issuecomment-532040372 this PR comment]) (and don't forget to set a user).
Using <code>nixos-generate-config</code> will not generate the required minimal configuration.
 
Remember to add the nixos-unstable channel.


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ pkgs, ... }:
{ config, pkgs, lib, ... }:


{
{
# This configuration worked on 09-03-2021 nixos-unstable @ commit 102eb68ceec
# The image used https://hydra.nixos.org/build/134720986
  boot = {
    kernelPackages = pkgs.linuxPackages_rpi4;
    tmpOnTmpfs = true;
    initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
    # ttyAMA0 is the serial console broken out to the GPIO
    kernelParams = [
        "8250.nr_uarts=1"
        "console=ttyAMA0,115200"
        "console=tty1"
        # Some gui programs need this
        "cma=128M"
    ];
  };
  boot.loader.raspberryPi = {
    enable = true;
    version = 4;
  };
  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;
  # Required for the Wireless firmware
  hardware.enableRedistributableFirmware = true;
  networking = {
    hostName = "nixos-raspi-4"; # Define your hostname.
    networkmanager = {
      enable = true;
    };
  };
  environment.systemPackages = with pkgs; [
    neovim
  ];
  users = {
    defaultUserShell = pkgs.zsh;
    mutableUsers = false;
    users.root = {
      password = "apassword";
    };
    users.anormaluser = {
      isNormalUser = true;
      password = "apassword";
      extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
    };
  };
  environment.variables = {
    EDITOR = "nvim";
  };
  programs.zsh = {
    enable = true;
    syntaxHighlighting.enable = true;
    interactiveShellInit = ''
      source ${pkgs.grml-zsh-config}/etc/zsh/zshrc
    '';
    promptInit = ""; # otherwise it'll override the grml prompt
  };
  nix = {
    autoOptimiseStore = true;
    gc = {
      automatic = true;
      dates = "weekly";
      options = "--delete-older-than 30d";
    };
    # Free up to 1GiB whenever there is less than 100MiB left.
    extraOptions = ''
      min-free = ${toString (100 * 1024 * 1024)}
      max-free = ${toString (1024 * 1024 * 1024)}
    '';
  };
   # Assuming this is installed on top of the disk image.
   # Assuming this is installed on top of the disk image.
   fileSystems = {
   fileSystems = {
Line 56: Line 136:
       device = "/dev/disk/by-label/NIXOS_SD";
       device = "/dev/disk/by-label/NIXOS_SD";
       fsType = "ext4";
       fsType = "ext4";
      options = [ "noatime" ];
     };
     };
   };
   };
  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;
  # Mainline doesn't work yet
  boot.kernelPackages = pkgs.linuxPackages_rpi4;


   # ttyAMA0 is the serial console broken out to the GPIO
   nixpkgs.config = {
  boot.kernelParams = [
     allowUnfree = true;
     "8250.nr_uarts=1" # may be required only when using u-boot
  };
    "console=ttyAMA0,115200"
  powerManagement.cpuFreqGovernor = "ondemand";
    "console=tty1"
  system.stateVersion = "20.09";
  ];
   #swapDevices = [ { device = "/swapfile"; size = 3072; } ];
 
   # Required for the Wireless firmware
  hardware.enableRedistributableFirmware = true;
}
}
</nowiki>}}
</nowiki>}}