Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active January 20, 2024 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/d6dc6ad9acf6eeed77b6c33f2b8428ae to your computer and use it in GitHub Desktop.
Save ryuheechul/d6dc6ad9acf6eeed77b6c33f2b8428ae to your computer and use it in GitHub Desktop.
NixOS on Microsoft Surface Pro 8

NixOS on Microsoft Surface Pro 8

What Is This Note About

This is mostly a short version of information dump and sharing my experience regarding installing (and using) NixOS on Microsoft Surface Pro 8 device.

TL;DR:

Where I'm Coming From

  • no real experience of using Linux as a host OS prior to this attempt
    • I mean I have used linux as virtual machines for software deployment purposes
    • used various virtual machine tools to try out some distros in the past
    • installed Fedora on a Macbook Air (dual booting) once briefly (somewhere around 2015?) but didn't stick with it
  • macOS has been the main OS since Snow Leopard
    • and stopped using Windows
    • this is also when I started working as a software engineer
  • prior to Snow Leopard, used various versions of Windows as a normal user
  • discovered nix (the package manager) since 2021
    • and that became a big part of my dotfiles
      • at the time of writing it's 38.5%!!
    • thanks to tinkering with WSL my dotfiles became cross platform
      • mostly between aarch64/macOS and x86_64/linux but also arm64/linux as guest on top of macOS
      • NixOS-WSL allowed me to have an experience of some version of NixOS
        • this even worked running Alacritty (GUI via Wayland) directly from NixOS seamlessly on Windows 11 via WSLg
  • mainly the not so great performance of Windows 11 + Surface Pro 8 motivated me a lot on trying out on linux
    • despite lack of experience on the subject matter, this page encouraged me!
    • (are you still here? continue at 1-main.md)

What's Next for Me

(TBC)

Disclaimer

I'm not endorsing this activity and I'm only sharing information that is helpful in case you want to try something similar to what I did.

Especially if you are not confident nor familiar with handling the configuration of NixOS at all, why don't you play with it safely with virtual computer first?

What's Not Working or Not Great

let's list what's not great first so that it's out of the way

All these cons weren't bad enough for me to stop using NixOS (and I can always fallback to Windows 11 as needed). Well, now you know.

Prerequisites

Here We Go - Time to Install It!

  1. Proceed until 5. Install your distribution via a bootable USB. from https://github.com/linux-surface/linux-surface/wiki/Installation-and-Setup.
  • my prerequisites will overlap with some of them
  1. Continue with Installation app after booting with the image
  • Installation might not start if power and WiFi is not connected
  • and even after that’s resolved it might not reflect right away
  • in that case simply close the window and open the installer again
  • after installation is done, it will boot to NixOS from the disk
  1. Configure NixOS after installation
  • the bare installation that you just did should work pretty well (screen (no touchscreen), keyboard, touchpad, Wi-Fi, etc) - enough to continue
  • which makes it possible to configure further to enable more capabilities
  • if you are not familiar with how to configure nixos via configuration files, you should practice this activity with a VM
    • for the rest, I will assume that you are somewhat familiar with these process
  • you will probably start from here
    • or you can try https://github.com/ryuheechul/dotfiles#nixos if you just want to try something quick before you build your own configuration
      • (or maybe at least look at https://github.com/ryuheechul/dotfiles/tree/master/nix/nixos if you need some idea about what can be done and what is needed)
      • make sure to cd dotfiles && cp mix-and-match-template.nix mix-and-match.nix (and leave only the one you need - at least recipes/surface-pro-intel.nix)
    • importing nixos-hardware (recipes/surface-pro-intel.nix) will requires building the custom kernel which takes time and uses CPU intensively during the compilation
      • aka it will stay hot and noisy for a while
      • you might want to limit cores to avoid high temperature and noise if you are ok with longer time building kernel
      • since it takes time and resource, make sure to have enough battery left to go on in case the power is not connected

Shrink Partition for Windows 11

In order to dual boot NixOS needs to take it own partition therefore, Windows 11 needs to give away some space to it.

Why Only So Little Is Available to Shrink?

You probably encounter a situation that you can't shrink much, in that case any of these might be helpful to have more space available to shrink:

Adjusting Partition

aka giving more space to NixOS from Windows 11

After I became confident that I rather continue using NixOS daily than Windows 11, I did shrink the partition on the disk for Windows 11 even more but how can I grow the partition of NixOS?

Now you need GParted! (unless you know a better way to do it).

First let me list what's either impossible or not great:

  • Windows Disk Manager that we used to shrink the partition of Windows
    • I couldn't find a way to merge the two partitions (unallocated one on the left and existing NixOS one on the right)
    • that's why we need GParted!
  • GParted running on NixOS
    • you can run GParted on NixOS but how can you manipulate the partition when it's mounted on very system that is running everything?
      • it's like a doctor can't operate on their own body, you need another surgeon to do it for you!
      • I mean... let me know if you know this way is possible
  • GParted live disk (USB/CD)
    • it's like similar to prepare an NixOS installation medium and run it but the content is GParted
    • so technically you can do it - https://gparted.org/livecd.php
    • but you will encounter that your keyboard and touchpad will not work
      • if you have usb keyboard and mouse, that probably would work
        • but even so, the UX seems not so great

If you still have the USB stick with NixOS install image, it actually comes with GParted!

actually since I wasn't using the swap partition, it was realatively straight forward but if you were using swap partition, I assume it's not this simple

  1. prepare the image on the stick if you don't have already
  2. boot with the stick
  3. close the installation app
  4. open GParted (click activity on the left top corner to find one)
  5. select Resize/Move - https://gparted.org/display-doc.php%3Fname%3Dmoving-space-between-partitions
  6. apply (GParted doesn't do anything until you actually apply) - and since it's a risky operation make sure that your device doesn't turn off during the operation
  7. turn off the computer (find the power option from the right top corner and shutdown) and remove the USB stick
  8. pray for booting - (but seriously) you better be ready for the case that it doesn't boot anymore after Resize/Move

Dealing with Freezing Due to OOM

It turns out unlike the usual experience with using macOS or Windows 10/11, which are configured to prevent freezing the desktop session due to OOM, it can be left up to users to configure stuff on linux. You may find this link useful to deal with the freezing if you are experiencing that, https://github.com/ryuheechul/dotfiles/blob/master/nix/nixos/recipes/oom.nix.

@ryuheechul
Copy link
Author

https://borretti.me/article/nixos-for-the-impatient for people who are relatively new to NixOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment