NixOS on PineTab 2
#1
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:
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.
  Reply
#2
[quote pid="118220" dateline="1687485923"]
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.
---------
1) Do you actually use it on the PineTab2 yourself?
2) if so: does the Wifi work out of the box or not?
3) How does one get rid of the whole thing afterwards if one doesn't like the NixOS?
Thank you for answering these questions. Might be helpful to post some screenshots too, though.
[/quote]
  Reply
#3
Thanks for this! It works great when running from an SD card. I have a question. I have been running it for weeks, and I am happy with it so now I would like to put it on the internal storage, but I cannot find any directions to do that. Do you have any suggestions? I am not sure what mmcblk1boot0 & mmcblk1boot1 are for.

Thanks!
  Reply
#4
(11-10-2023, 05:40 PM)duckunix Wrote: Thanks for this!  It works great when running from an SD card. I have a question.  I have been running it for weeks, and I am  happy with it so now I would like to put it on the internal storage, but I cannot find any directions to do that.  Do you have any suggestions?  I am not sure what mmcblk1boot0 & mmcblk1boot1 are for.

Thanks!

So, I just recently had to reinstall the OS since I broke it. I used the command below to reinstall the stock Danctnix Arch Linux:

Code:
sudo dd if=/dev/mmcblk1 of=mmcblk0

I'm not sure what the boot partitions either, but the command didn't seem to mess them up for my Danctnix install. Also, it took FOREVER. Also, make sure the drives are correct by running the following command:

Code:
sudo fdisk -l

**edit: this actually didn't work as I expected it to. I think need to convert the image to an .img file and THEN use dd to image the EMMC.**
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PineTab 2 login screen rotation fix chzbacon 11 7,210 03-17-2024, 04:53 PM
Last Post: mtomaschett
  Working OS on pinetab RISC-V? user641 3 2,166 12-13-2023, 08:11 AM
Last Post: tophneal
  Pinetab 2 as Pinebook Pro replacement Corkonian 4 3,510 08-15-2023, 11:22 AM
Last Post: CadenAnderson
  Software for PineTab-V msm 12 7,137 08-05-2023, 05:08 PM
Last Post: bingch
  Arch Linux ARM on PineTab 1 Danct12 25 34,473 06-10-2023, 05:33 PM
Last Post: fxc
  PineTab 2 Login Failure cptijerina 0 964 06-07-2023, 07:16 PM
Last Post: cptijerina
  PineTab Mobian bcnaz 150 173,055 04-26-2022, 11:58 AM
Last Post: thomzane
  Xmonad on PineTab Telefza 0 2,053 06-24-2021, 04:04 AM
Last Post: Telefza
  PineTab Mobian Upgrade issue - Pin no longer works thomzane 3 4,800 04-30-2021, 06:52 AM
Last Post: thomzane
  Video Tutorial: SDR/GQRX- Listening In To Voice On Pinetab (Internal SDR) RTP 1 3,013 03-08-2021, 09:33 AM
Last Post: barray

Forum Jump:


Users browsing this thread: 1 Guest(s)