06-22-2023, 08:05 PM
Hey there, just thought I'd write a bit about the current state of NixOS on PineTab 2. I've been running my own custom image essentially since day 1, but my personal configs are not very useful to the General User
For this reason, I've built a more "general purpose" config that should help folks get started.
Firstly, my work is based on the wonder work from Nabam on github, and so the first step in getting NixOS working on your PineTab 2 is to download the PineTab 2 image from the releases page. This image boots to a console with a default user and no password. That's our starting point.
nixos-rockchip: https://github.com/nabam/nixos-rockchip
If you've played around at all with the PineTab 2, you'll know WiFi doesn't work yet. However you normally get internet on your tablet, you'll want to do that next. You can check whether the network device has been found with the `ip a` command.
After you have internet, download the PineTab 2 flake I've created to the tablet. It should be placed at `/etc/nixos/flake.nix`.
repo link: https://git.asonix.dog/asonix/pinetab2-nixos
raw file link: https://git.asonix.dog/asonix/pinetab2-n.../flake.nix
After you've done this, run the following commands:
After the tablet reboots, it should launch GNOME's login screen with a user called `pinetab2`. The default password for this account is `changeme`. You can log into the GNOME session and configure it to your liking.
Below is a More In Depth explanation of everything. It's optional reading
If you don't have experience with NixOS, you may not understand all the contents of the flake, and even if you do, you may not have used flakes before, or you may be confused about why you need to rebuild twice. Here's a more in-depth explanation:
the "inputs" section declares the configuration's dependencies. In this case, the dependencies are `nixpkgs` and `nabam/nixos-rockchip`. There's a bit of configuration to ensure that nixos-rockchip uses the same versions of nixpkgs that we do in our flake.
the "outputs" section declares what the flake should produce. We have a big "let ... in" block that defines a few variables, before finally constructing a couple nixos configurations at the bottom.
The first one is called "nixosConfigurations.${hostname}". This is the "final" configuration that we'll be loading. `hostname` is set as a variable in the "let .. in" block. The second one is called `nixosConfigurations.nixos` This is the "first" configuration that we'll be loading. In the installation instructions, I say to run `nixos-rebuild` twice. The first time will run the `nixos` configuration, since the image's default hostname is `nixos`. The second time it will run the `${hostname}` configuration, since setting the hostname to something else is part of the first configuration. I'll talk more about why it works this way in a bit. We can see that the configurations are slightly different. the ${hostname} configuration uses a kernel specific to the pinetab while the nixos configuration uses an upstream kernel.
Going back up to our "let .. in" block, we have a few variables up front: system, hostname, username, and initialPassword. These should all be pretty self-explanatory. "system" is the architecture & operating system that dictates which packages nixos should use. "hostname" is the name we're giving the pinetab. "username" is the username for the account we're creating. "initialPassword" is the password we give to that account.
Next, we have a `pkgs` declaration, which allows us to reference packages from nixos in the flake.
Then, we have a function called buildNixosConfiguration, which is a function that takes a record as an argument, and returns a nixosSystem record. This is the part that actually constructs what our system will look like. Let's break it down.
First, it has "inherit system;". This tells Nix what kind of system we're building the configuration for.
Next, we have a list of modules, the first two being imports from nabam's nixos-rockchip flake. we use sdImageRockchip to inherit the boot configuration nabam has created, and we use dtOverlayPCIeFix because I felt like we should (it's valid for all rk3566 devices, although I don't know if it matters on PineTab 2 specifically). That module fixes some memory regions for PCIe devices.
Next, we have a custom module labeled "pinetab2 cachix". This sets up the system to be able to download binaries from a nix store that I maintain in the cachix nix repository service. This is important because PineTab 2 can't use standard kernels yet, which means if you don't have a binary to fetch you need to compile it yourself. This config here is also why nixos-rebuild needs to be run twice. The first time you run it, it installs this cachix configuration, and the second time you run it, it uses the cachix configuration. This is also why the nixos configuration uses an upstream kernel. It exists in NixOS's binary repository and doesn't need to be compiled to run the first nixos-rebuild. After the first rebuild finishes, we can use binaries from my cachix repository so the second nixos-rebuild will pull the custom kernel binary that I have already compiled and uploaded.
Finally, we have a much larger module. This is the same stuff you'd put in a configuration.nix file in a traditional NixOS setup, but we define a few extras.
First, we override zfs to think it can't build for our system. This is important because it quite literally can't build for this system currently and we don't want it to try.
Then we set our stateVersion. This tells Nix when you installed NixOS and shouldn't be changed even if upgrading to a new NixOS version.
Then we configure our user account using the variables we defined earlier.
Then we set the uBoot variable (this currently has no effect, since we aren't building a diskimage)
Then we set our kernel and boot arguments. This ensures we can use UART if we need to, and ensures we mount the right root partition.
Then we enable NetworkManager. Most desktop environments integrate with it.
Then we start some services:
- GNOME and GDM (the desktop & login screen)
- automatic-timezoned and geoclue2 (detect and set the right timezone)
- flatpak (if you want to install flatpaks)
- printing (if you want to print from your tablet)
- avahi (if you want easier network discovery stuff)
- pipewire (for all your sound server needs, like playing sound out of the speakers and headphone jack)
Then we have some more miscellaneous configuration:
- enable sound
- disable pulseaudio (we're using pipewire)
- enable rtkit (not sure what this does, actually)
Then we install some packages
- cachix (not actually needed, but it's there)
- firefox
- a bunch of gnome extensions
- htop
finally, we set some variables:
- MOZ_ENABLE_WAYLAND to make firefox run on wayland instead of xwayland
- the hostname for the system
- experimental-features for the Nix Config (this ensures we can use flakes in the future)
Hope this is useful to anyone thinking about NixOS on the PineTab 2 or just in general. I use it on almost all my systems at this point.
For this reason, I've built a more "general purpose" config that should help folks get started.
Firstly, my work is based on the wonder work from Nabam on github, and so the first step in getting NixOS working on your PineTab 2 is to download the PineTab 2 image from the releases page. This image boots to a console with a default user and no password. That's our starting point.
nixos-rockchip: https://github.com/nabam/nixos-rockchip
If you've played around at all with the PineTab 2, you'll know WiFi doesn't work yet. However you normally get internet on your tablet, you'll want to do that next. You can check whether the network device has been found with the `ip a` command.
After you have internet, download the PineTab 2 flake I've created to the tablet. It should be placed at `/etc/nixos/flake.nix`.
repo link: https://git.asonix.dog/asonix/pinetab2-nixos
raw file link: https://git.asonix.dog/asonix/pinetab2-n.../flake.nix
After you've done this, run the following commands:
Code:
$ sudo su
> cd
> nixos-rebuild switch
> nixos-rebuild switch # yes, do it twice
> reboot
After the tablet reboots, it should launch GNOME's login screen with a user called `pinetab2`. The default password for this account is `changeme`. You can log into the GNOME session and configure it to your liking.
Below is a More In Depth explanation of everything. It's optional reading
If you don't have experience with NixOS, you may not understand all the contents of the flake, and even if you do, you may not have used flakes before, or you may be confused about why you need to rebuild twice. Here's a more in-depth explanation:
the "inputs" section declares the configuration's dependencies. In this case, the dependencies are `nixpkgs` and `nabam/nixos-rockchip`. There's a bit of configuration to ensure that nixos-rockchip uses the same versions of nixpkgs that we do in our flake.
the "outputs" section declares what the flake should produce. We have a big "let ... in" block that defines a few variables, before finally constructing a couple nixos configurations at the bottom.
The first one is called "nixosConfigurations.${hostname}". This is the "final" configuration that we'll be loading. `hostname` is set as a variable in the "let .. in" block. The second one is called `nixosConfigurations.nixos` This is the "first" configuration that we'll be loading. In the installation instructions, I say to run `nixos-rebuild` twice. The first time will run the `nixos` configuration, since the image's default hostname is `nixos`. The second time it will run the `${hostname}` configuration, since setting the hostname to something else is part of the first configuration. I'll talk more about why it works this way in a bit. We can see that the configurations are slightly different. the ${hostname} configuration uses a kernel specific to the pinetab while the nixos configuration uses an upstream kernel.
Going back up to our "let .. in" block, we have a few variables up front: system, hostname, username, and initialPassword. These should all be pretty self-explanatory. "system" is the architecture & operating system that dictates which packages nixos should use. "hostname" is the name we're giving the pinetab. "username" is the username for the account we're creating. "initialPassword" is the password we give to that account.
Next, we have a `pkgs` declaration, which allows us to reference packages from nixos in the flake.
Then, we have a function called buildNixosConfiguration, which is a function that takes a record as an argument, and returns a nixosSystem record. This is the part that actually constructs what our system will look like. Let's break it down.
First, it has "inherit system;". This tells Nix what kind of system we're building the configuration for.
Next, we have a list of modules, the first two being imports from nabam's nixos-rockchip flake. we use sdImageRockchip to inherit the boot configuration nabam has created, and we use dtOverlayPCIeFix because I felt like we should (it's valid for all rk3566 devices, although I don't know if it matters on PineTab 2 specifically). That module fixes some memory regions for PCIe devices.
Next, we have a custom module labeled "pinetab2 cachix". This sets up the system to be able to download binaries from a nix store that I maintain in the cachix nix repository service. This is important because PineTab 2 can't use standard kernels yet, which means if you don't have a binary to fetch you need to compile it yourself. This config here is also why nixos-rebuild needs to be run twice. The first time you run it, it installs this cachix configuration, and the second time you run it, it uses the cachix configuration. This is also why the nixos configuration uses an upstream kernel. It exists in NixOS's binary repository and doesn't need to be compiled to run the first nixos-rebuild. After the first rebuild finishes, we can use binaries from my cachix repository so the second nixos-rebuild will pull the custom kernel binary that I have already compiled and uploaded.
Finally, we have a much larger module. This is the same stuff you'd put in a configuration.nix file in a traditional NixOS setup, but we define a few extras.
First, we override zfs to think it can't build for our system. This is important because it quite literally can't build for this system currently and we don't want it to try.
Then we set our stateVersion. This tells Nix when you installed NixOS and shouldn't be changed even if upgrading to a new NixOS version.
Then we configure our user account using the variables we defined earlier.
Then we set the uBoot variable (this currently has no effect, since we aren't building a diskimage)
Then we set our kernel and boot arguments. This ensures we can use UART if we need to, and ensures we mount the right root partition.
Then we enable NetworkManager. Most desktop environments integrate with it.
Then we start some services:
- GNOME and GDM (the desktop & login screen)
- automatic-timezoned and geoclue2 (detect and set the right timezone)
- flatpak (if you want to install flatpaks)
- printing (if you want to print from your tablet)
- avahi (if you want easier network discovery stuff)
- pipewire (for all your sound server needs, like playing sound out of the speakers and headphone jack)
Then we have some more miscellaneous configuration:
- enable sound
- disable pulseaudio (we're using pipewire)
- enable rtkit (not sure what this does, actually)
Then we install some packages
- cachix (not actually needed, but it's there)
- firefox
- a bunch of gnome extensions
- htop
finally, we set some variables:
- MOZ_ENABLE_WAYLAND to make firefox run on wayland instead of xwayland
- the hostname for the system
- experimental-features for the Nix Config (this ensures we can use flakes in the future)
Hope this is useful to anyone thinking about NixOS on the PineTab 2 or just in general. I use it on almost all my systems at this point.