Skip to content

Instantly share code, notes, and snippets.

@schrmh
Last active December 28, 2023 17:34
Show Gist options
  • Save schrmh/01c0271bed160033489d7389f1101025 to your computer and use it in GitHub Desktop.
Save schrmh/01c0271bed160033489d7389f1101025 to your computer and use it in GitHub Desktop.
beryllium Mobile NixOS example setup
{ lib, config, pkgs ? (import ./pkgs.nix {}), ... }:
{
imports = [
(import /home/alice/Projects/mobile-nixos/lib/configuration.nix { device = "xiaomi-beryllium"; })
./packages.nix
];
nixpkgs.localSystem = { system = "aarch64-linux"; };
users.users.alice = {
isNormalUser = true;
home = "/home/alice";
extraGroups = [
"networkmanager"
"wheel"
];
openssh.authorizedKeys.keys = [ "ssh-rsa longlonglongstring== yourpc@hostname" ];
};
services.openssh = {
enable = true;
# require public key authentication for better security
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
settings.PermitRootLogin = "yes";
};
services.xserver = {
enable = true;
desktopManager.plasma5.mobile.enable = true;
displayManager.autoLogin.enable = true;
displayManager.autoLogin.user = "alice";
displayManager.defaultSession = "plasma-mobile";
displayManager.lightdm = {
enable = true;
# Workaround for autologin only working at first launch.
# A logout or session crashing will show the login screen otherwise.
extraSeatDefaults = ''
session-cleanup-script=${pkgs.procps}/bin/pkill -P1 -fx ${pkgs.lightdm}/sbin/lightdm
'';
};
libinput.enable = true;
};
# Networking, modem and misc.
networking.networkmanager.enable = true;
# Setup USB gadget networking in initrd...
mobile.boot.stage-1.networking.enable = lib.mkDefault true;
# Ensures any rndis config from stage-1 is not clobbered by NetworkManager
networking.networkmanager.unmanaged = [
"rndis0" "usb0" "*" "except:type:wwan" "except:type:gsm"
];
networking.wireless.enable = true;
networking.wireless.networks = {
"FRITZ!Box 7490" = { # SSID with spaces and/or special characters
psk = "yourwlanpassword";
};
};
# compatible NixOS release
system.stateVersion = "23.11";
}
{ device ? null
, pkgs ? (import ./pkgs.nix {})
}@args':
let args = args' // { inherit pkgs; }; in
import ~/Projects/mobile-nixos/lib/eval-with-configuration.nix (args // {
configuration = [ (import ./configuration.nix) ];
additionalHelpInstructions = ''
You can build the `-A outputs.default` attribute to build the default output
for your device.
$ nix-build examples/plasma-mobile --argstr device ${device} -A outputs.default
'';
})
{ config, lib, pkgs, ... }:
{
mobile.beautification = {
silentBoot = lib.mkDefault true;
splash = lib.mkDefault true;
};
environment.systemPackages = with pkgs; [
chatty # IM and SMS
epiphany # Web browser
gnome-console # Terminal
megapixels # Camera
htop
ncdu
nano
vim
firefox-wayland
mpv
vlc
android-tools
usbutils
git
gcc
waypipe
pavucontrol
minicom
atinout
libqmi
modemmanager
modem-manager-gui
gnome-2048
];
hardware.bluetooth.enable = true;
hardware.pulseaudio.enable = lib.mkDefault true; # mkDefault to help out users wanting pipewire
powerManagement.enable = true;
}

Foreword:
My NixOS experience is actually limited to this device. So this might not be this optimal and there are some parts of this that look a bit cringe to me and they might not be necessary but I left them here for now...

By the way: If you got a Pocophone F1 with EBBG display you will likely have to figure out a bit of stuff and then contribute to the Mobile NixOS repo. Most beryllium owners have a Tianma display.

Start on a aarch64 machine (e.g. SBC RPi 4):
Then e.g. this for phosh (hello actually has a few words on that iirc):

nix-build examples/phosh --argstr device xiaomi-beryllium -A outputs.default
fastboot flash boot result/boot.img
fastboot flash userdata result/system.img

I then took basically just cp -r'd the examples while keeping my modifications in the examples dir.
What I got is largely identical to what I attached (files from phone) but the first 5 lines differ.

On phone:

mkdir ~/Projects
cd Projects
git clone https://github.com/NixOS/mobile-nixos #get PR: git fetch origin pull/$ID/head:$BRANCHNAME
git clone https://github.com/NixOS/nixpkgs
mkdir pocophone
cp mobile-nixos/pkgs.nix pocophone/pkgs.nix
cd pocophone
nano default.nix
nano configuration.nix
nano packages.nix # split into extra file for list of apps
sudo -s
ln -s /home/alice/Projects/pocophone/configuration.nix /etc/nixos/configuration.nix
nix-channel --add https://nixos.org/channels/nixos-23.11 nixos
nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
nix-channel --update
export NIX_PATH="nixpkgs=/home/alice/Projects/nixpkgs:mobile-nixos=/home/alice/Projects/mobile-nixos:nixos-config=/etc/nixos/configuration.nix"
nixos-rebuild switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment