NixOS on ARM/Raspberry Pi 5: Difference between revisions

DoggoBit (talk | contribs)
DoggoBit (talk | contribs)
Line 83: Line 83:
=== Step 2: Installing NixOS ===
=== Step 2: Installing NixOS ===


Once you're running an installer image, you can use [[nixos-anywhere]] to build and install a fresh NixOS system on your Raspberry Pi 5. You can either install nixos-anywhere on your system by adding it to your system or home packages, or you can directly run it as a flake (see the repository's getting started guide).
Once you're running an installer image, you can create a flake referencing the repository. For example:{{File|filename=flake.nix|language=nix|contents={
  description = "Example Raspberry Pi 5 configuration flake";
    inputs = {
      nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
      nixos-raspberrypi.url = "github:nvmd/nixos-raspberrypi";
    };


If you simply want to install NixOS on the same SD card, make sure to remove the disko phase:<syntaxhighlight lang="shell">
  nixConfig = {
$ nixos-anywhere --flake .#<system> root@<hostname> --build-on remote --phases kexec,install,reboot
    extra-substituters = [
</syntaxhighlight>Alternatively, you can use [[disko]] to set up your disk configuration as well (probably SSD).The nixos-raspberrypi also has an [https://github.com/nvmd/nixos-raspberrypi-demo example configuration].
      "https://nixos-raspberrypi.cachix.org"
    ];
    extra-trusted-public-keys = [
      "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
    ];
  };
 
  outputs = { self, nixpkgs, nixos-raspberrypi }@inputs:
    {
      nixosConfigurations = {
        yourHostname = nixos-raspberrypi.lib.nixosSystem {
          specialArgs = inputs;
          modules = [
            ({...}: {
              imports = with nixos-raspberrypi.nixosModules; [
                raspberry-pi-5.base
                raspberry-pi-5.bluetooth
              ];
            })
            ({ ... }: {
              networking.hostName = "yourHostName";
              users.users.yourUserName = {
                initialPassword = "yourInitialPassword";
                isNormalUser = true;
                extraGroups = [
                  "wheel"
                ];
              };
 
              services.openssh.enable = true;
            })
 
            ({ ... }: {
              fileSystems = {
                "/boot/firmware" = {
                  device = "/dev/disk/by-uuid/2175-794E";
                  fsType = "vfat";
                  options = [
                    "noatime"
                    "noauto"
                    "x-systemd.automount"
                    "x-systemd.idle-timeout=1min"
                  ];
                };
                "/" = {
                  device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
                  fsType = "ext4";
                  options = [ "noatime" ];
                };
              };
            })
          ];
        };
      };
    };
}}}Finally, simply <code>nixos-rebuild switch --flake .#yourHostname</code> the flake.


== Other Solutions ==
== Other Solutions ==