Skip to content

Instantly share code, notes, and snippets.

@ProofOfPizza
Last active January 13, 2021 08:34
Show Gist options
  • Save ProofOfPizza/fcecc3a36206d76ef7e823a0863fb2b0 to your computer and use it in GitHub Desktop.
Save ProofOfPizza/fcecc3a36206d76ef7e823a0863fb2b0 to your computer and use it in GitHub Desktop.
config and install nixos

Installing Nixos on MBR (Legacy Boot) with luks encrypted disk and i3 WM

This is my guide that I synthesized from different sources. Mainly:

Installed it on /dev/sda. First, create an empty MBR partition table.

sudo fdisk /dev/sda
(fdisk) o

Create 2 main partitions (/dev/sda1 and /dev/sda2):

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048    526335    524288   256M 83 Linux      /boot
/dev/sda2          526336 765986815 765460480   365G 83 Linux      Encrypted with LUKS, 3 LVM partitions:
    swap  vg -wi-ao----   8.00g                                   swap
    root  vg -wi-ao----  80.00g                                   /
    blubber vg -wi-ao---- 277.00g

Create partitions:

(fdisk) n
(fdisk) p
(fdisk) 1
(fdisk) <Enter>
(fdisk) +256M
(fdisk) t
(fdisk) 83

(fdisk) n
(fdisk) p
(fdisk) 2
(fdisk) <Enter>
(fdisk) +365G
(fdisk) t
(fdisk) 83

(fdisk) w (Write Changes)

Format Partitions:

sudo mkfs.ext2 /dev/sda1

Setup encryption

# sudo cryptsetup -c aes-xts-plain64 -y --use-random luksFormat /dev/sda2
# sudo cryptsetup luksOpen /dev/sda2 luks

Create LVM Partitions This creates one partions for root, modify if /home or other partitions should be on separate partitions

# sudo pvcreate /dev/mapper/luks
# sudo vgcreate vg /dev/mapper/luks
# sudo lvcreate --size 8G vg --name swap
# sudo lvcreate --size 80G vg --name root
# sudo lvcreate -l +100%FREE vg --name blubber

Format LVM partitions

# sudo mkfs.ext4 /dev/mapper/vg-root
# sudo mkfs.ext4 /dev/mapper/vg-anbar
# sudo mkswap /dev/mapper/vg-swap

Mount the new system

# sudo mount /dev/mapper/vg-root /mnt
# sudo mkdir /mnt/boot
# sudo mount /dev/sda1 /mnt/boot
# sudo swapon /dev/mapper/vg-swap

install it .. changing config

sudo nixos-generate-config --root /mnt
sudo nixos-install

If install is successful, you’ll be prompted to set password for root user. Then reboot, and remove installation media.

Login to root, and add add user:

useradd -c 'Me' -m me
passwd me
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader.
# boot.loader.systemd-boot.enable = true;
# boot.loader.efi.canTouchEfiVariables = true;
nixpkgs.config.allowUnfree = true;
# Use the GRUB 2 boot loader.
# grub
boot.loader.grub = {
enable = true;
version = 2;
efiSupport = false;
enableCryptodisk = true;
device = "/dev/sda";
useOSProber=true;
};
# luks
boot.initrd.luks.devices = {
luksroot = {
device = "/dev/disk/by-uuid/7d69c075-67f9-4b87-adcc-cffa1ed416df";
preLVM = true;
allowDiscards = true;
};
};
# Set your time zone.
time.timeZone = "Europe/Amsterdam";
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
networking.useDHCP = false;
networking.interfaces.enp4s0f2.useDHCP = true;
networking.interfaces.wlp3s0.useDHCP = true;
environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw
services.xserver = {
enable = true;
desktopManager = {
xterm.enable = false;
};
displayManager = {
defaultSession = "none+i3";
};
windowManager.i3 = {
enable = true;
extraPackages = with pkgs; [
dmenu #application launcher most people use
i3status # gives you the default i3 status bar
i3lock #default i3 screen locker
i3blocks #if you are planning on using i3blocks over i3status
];
};
};
# Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;
system.stateVersion = "20.09"; # Did you read the comment?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment