Mobile NixOS on Librem 5

I just stumbled across Mobile NixOS, the project that makes NixOS run on mobile devices.

Here’s a YouTube video that demoes a running NixOS on a mobile phone (I think it’s a OnePlus 6) and walks you through (re-)installing it from scratch.

If you don’t know NixOS, it’s a community-driven free/libre Linux distribution that is installed/managed/configured from source code (think “configuration management”).

The Mobile NixOS project maintains a device list to tell which devices can be installed right off their configuration maintained on GitHub. With NixOS, this usually refers to whether the device installs and generally works, not necessarily whether or how well phone calls, mobile broadband, etc. perform. I say this mainly to manage expectations, but the heavy lifting (aka hardware support) is usually done by other companies, communities or projects, so stay thrilled.

I wonder if anyone has ever tried the Librem 5 with Mobile NixOS. It’s not on their list yet. :star_struck:

4 Likes
4 Likes

I never understood the use case of Mobile NixOS. After all, a phone is just a smaller computer.

Never managed to make sound in phonecalls work, but last I tried was two years ago. I’m not doing much with my Librem 5 as it is a bit too slow. Maybe someday.

The relevant part of my configuration:

{
  boot = {
    initrd = {
      includeDefaultModules = false;
      kernelModules = [
        "bq25890_charger"
        "dwc3"
        "imx_dcss"
        "imx_sdma"
        "mtdblock"
        "ofpart"
        "phy_fsl_imx8mq_usb"
        "snvs_pwrkey"
        "spi_nor"
        "tps6598x"
        "xhci_hcd"
        "usbcore"
        "usb_storage"
        "uas"
        "xhci_plat_hcd"
      ];
      systemd.tpm2.enable = false;
    };
    kernelPackages =
      let
        kernel_pkg =
          { buildLinux, ... }@args:
          buildLinux (
            args
            // {
              defconfig = "librem5_defconfig";
              ignoreConfigErrors = true;
              version = "6.6.74-librem5";
              src = builtins.fetchGit {
                url = "https://source.puri.sm/Librem5/linux.git";
                ref = "latest";
                rev = "3449208c3c6bff93fe3b09862400e9e2b15fa607";
              };
            }
            // (args.argsOverride or { })
          );
        kernel = pkgs.callPackage kernel_pkg { };
      in
      pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor kernel);
    kernelPatches = [
      {
        name = "librem5-extraconfig";
        patch = null;
        extraConfig = ''
          EFI y
          EFIVAR_FS m
        '';
      }
    ];
  };

  fileSystems = {
    "/" = {
      label = "librem5";
      fsType = "ext4";
      options = [
        "data=journal"
        "discard"
        "journal_async_commit"
      ];
    };

    "/boot" = {
      label = "librem5";
      fsType = "ext4";
      options = [
        "data=journal"
        "discard"
        "journal_async_commit"
      ];
    };
  };

  hardware = {
    deviceTree = {
      enable = true;
      name = "freescale/imx8mq-librem5-r4.dtb";
    };
  };

  nixpkgs.hostPlatform = "aarch64-linux";
  powerManagement.cpuFreqGovernor = "schedutil";

  services = {
    xserver = {
      desktopManager = {
        phosh = {
          enable = true;
          group = "users";
          user = "<user>";
        };
      };
    };
  };
}
1 Like