Skip to content

What is the desired way to get raspberry pi 4 with >100mb gpu memory? #1505

Open
@cguentherTUChemnitz

Description

@cguentherTUChemnitz

I am trying to setup the raspberry pi 4 with gpu acceleration and a certain amount of gpu memory. Initially i have the problem, that it seems the nixos-generators seem to inject stuff into the kernel build, that a zfs kernel is requested. Nevertheless i am able to get around this by my current minimal example like this:

{

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    nixos-generators = {
      url = "github:nix-community/nixos-generators";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    { self
    , nixpkgs
    , nixos-hardware
    , nixos-generators
    , deploy-rs
    ,
    }:
    let
      # provide pre-compiled deploy-rs packages from nixpackages cachix cache
      system = "aarch64-linux";
      pkgs = import nixpkgs { inherit system; };
      # nixpkgs with deploy-rs overlay but force the nixpkgs package for binary cache
      deployPkgs = import nixpkgs {
        inherit system;
        overlays = [
          deploy-rs.overlays.default
          (self: super: {
            deploy-rs = {
              inherit (pkgs) deploy-rs;
              lib = super.deploy-rs.lib;
            };
          })
        ];
      };
    in
    {
      nixosConfigurations.rpi4test = nixpkgs.lib.nixosSystem {
        system = "aarch64-linux";
        modules = [
          nixos-hardware.nixosModules.raspberry-pi-4
          nixos-generators.nixosModules.all-formats
          ({lib, ...}:
          {
            # somehow the image build triggers a zfs kernel, which fails
            # boot.zfs.enabled = false; --> this is automatically determined
            boot.supportedFilesystems = lib.mkForce [
              "ext4"
              "vfat"
            ];
            services.zfs.autoScrub.enable = false;
            services.zfs.trim.enable = false;

            # Force override the module selection --> sync with nixosHardware for rpi4
            # nixosGenerators does inject other kernel modules, like sun4i-drm which will fail for rpi kernel
            boot.initrd.availableKernelModules = lib.mkForce [
              "usbhid"
              "usb_storage"
              "vc4"
              "pcie_brcmstb" # required for the pcie bus to work
              "reset-raspberrypi" # required for vl805 firmware to load
            ];

            # Enable the fkms-3d option for better GPU support
            boot.kernelParams = [ "cma=128M" ];

            # Basic system configuration
            system.stateVersion = "25.05";

            # Enable SSH for remote access
            services.openssh.enable = true;

            # Create a user account
            users.users.pi = {
              isNormalUser = true;
              extraGroups = [
                "wheel"
                "networkmanager"
              ];             
              initialPassword = "pi";
            };
            users.users."root" = {
              initialPassword = "pi";
            };

            # Enable NetworkManager for easier network management
            networking.networkmanager.enable = true;
            networking.hostName = "rpi4test";

            # Optional: Enable the GPU firmware
            hardware.raspberry-pi."4".fkms-3d.enable = true;
          })
        ];
      };
    };
}

# test gpu memory with: vcgencmd get_mem gpu

My problem is:

i am building the sd card image using nixos-generators with:
nix build ".#nixosConfigurations.rpi4test.config.formats.sd-aarch64"

when i test with vcgencmd get_mem gpu the amount of gpu memory, i have alway a very low amount with > 100mb::

[root@rpi4test:~]# nix-shell --extra-experimental-features flakes -p libraspberrypi
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
[nix-shell:~]# vcgencmd get_mem gpu
gpu=76M

It seems for me that i get i wild mixture of responsibilities. Some of the partitioning and boot setup is handled by the nixos generators. Something is handled by linux_rpi4 and additional nixos hardware is doing some mapping from raspi config to device tree overlays.

On the other hand, other projects are doing the image build on their own and also are doing the firmware handling on their own like this project:
https://codeberg.org/Uli/nixsauce/src/branch/main/lib/rpi-image

This one seems to avoid using the device tree overlay and load the raspi config during own bootloader. What is here the desired state to get it properly working?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions