Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created January 3, 2023 23:58
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 JosePedroDias/0df74ae198b9303382b2a560ecc0a6f4 to your computer and use it in GitHub Desktop.
Save JosePedroDias/0df74ae198b9303382b2a560ecc0a6f4 to your computer and use it in GitHub Desktop.
run nixos on M1 with UTM
{ config, pkgs, ... }:
{
imports =
[
./hardware-configuration.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
time.timeZone = "Europe/Lisbon";
# i18n.defaultLocale = "en_US.UTF-8";
# console = {
# font = "Lat2-Terminus16";
# keyMap = "us";
# useXkbConfig = true; # use xkbOptions in tty.
# };
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.zp = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
packages = with pkgs; [
];
};
# List packages installed in system profile
environment.systemPackages = with pkgs; [
helix
git
tmux
wget
];
services.openssh.enable = true;
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# networking.firewall.enable = false;
# Copy the NixOS configuration file and link it from the resulting system
# (/run/current-system/configuration.nix). This is useful in case you
# accidentally delete configuration.nix.
system.copySystemConfiguration = true;
system.stateVersion = "22.11"; # Did you read the comment?
}
  1. get UTM
  2. get the latest minimal iso for 64bit arm
  3. add > emulate > linux > choose boot iso with browse button > 4 GB mem > storage 64 GB
sudo sh

parted /dev/vda -- mklabel gpt
parted /dev/vda -- mkpart primary 512MiB -4GiB
parted /dev/vda -- mkpart primary linux-swap -4GiB 100%
parted /dev/vda -- mkpart ESP fat32 1MiB 512MiB
parted /dev/vda -- set 3 esp on

#to check it worked:
parted
select /dev/vda
print

cfdisk
#    /dev/vda1 (linux fs)
#    /dev/vda2 (swap)
#    /dev/vda3 (boot @ efi system)

mkfs.ext4 -L nixos      /dev/vda1
mkswap    -L swap       /dev/vda2
mkfs.fat  -F 32 -n boot /dev/vda3

mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot

swapon /dev/disk/by-label/swap

nixos-generate-config --root /mnt
nano /mnt/etc/nixos/configuration.nix

nixos-install
#or
nixos-install --no-root-passwd

reboot

useradd -c 'ze pedro' -m zp
passwd zp

# Available software:
nix search something

# test software
nix-shell -p git

# install something
nix-env --install git

# when we edit /etc/nixos/configuration.nix
nixos-rebuild switch (--rollback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment