Table of Contents

1. PC

Boot livecd, install git tmux, enter unstable shell.

nix-env -iA nixos.git
nix-env -iA nixos.tmux
tmux
nix-shell -p nixUnstable

after, clone the repo

git clone https://gitlab.com/haveagoodtime/flakes

1.1. Preview

pc.png

1.2. Build my system

nix build ./#nixosConfigurations.pc.config.system.build.toplevel --experimental-features 'nix-command flakes'

1.3. Disk Partition

Device Size Type
/dev/nvme0n1p1 200M EFI System
/dev/nvme0n1p2 ALL OTHER DISK Solaris /usr & Apple ZFS
/dev/sda ALL DISK Solaris /usr & Apple ZFS

1.3.1. Create zpool:

zpool create -f -O encryption=on -O keyformat=passphrase -o ashift=12 -o cachefile= -O compression=zstd -O acltype=posixacl -O atime=off -O xattr=sa -m none -O mountpoint=none tank /dev/disk/by-id/nvme-PLEXTOR_PX-256M9PeG_P02933100926-part2 /dev/disk/by-id/ata-PLEXTOR_PX-512M8VC_P02011403287

1.3.2. Create Dataset:

zfs create -o mountpoint=legacy tank/nix
zfs create -o mountpoint=legacy tank/home

1.3.3. Create Swap

sudo zfs create -V 16G tank/swap

1.3.4. Mount:

mount -t tmpfs none /mnt
mkdir -p /mnt/{boot,nix,home,var/log}
mount -t zfs tank/nix /mnt/nix
mount -t zfs tank/home /mnt/home
mkdir -p /mnt/nix/persist/{etc/ssh,var/log,var/lib/libvirt}
mount -o bind /mnt/nix/persist/var/log /mnt/var/log
mkfs.fat -F32 /dev/nvme0n1p1 
mount /dev/nvme0n1p1 /mnt/boot

1.4. Install System

nixos-install --no-root-passwd --root /mnt --system ./result

1.5. Umount

umount /mnt/*
umount /mnt
zpool export tank
reboot

1.6. Post Install

sudo nixos-rebuild switch --flake ./flakes#pc

2. Nas

2.1. Build my system

nix build ./#nixosConfigurations.nas.config.system.build.toplevel --experimental-features 'nix-command flakes'
# --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store https://mirror.sjtu.edu.cn/nix-channels/store https://mirrors.ustc.edu.cn/nix-channels/store https://cache.nixos.org/"

2.2. Disk Partition

Device Size Type
/dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part1 512M EFI System
/dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part2 ALL OTHER DISK Linux Filesystem

2.2.1. Create filesystem:

mkfs.fat -F32 /dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part1
cryptsetup luksFormat /dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part2
cryptsetup open /dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part2 nix
mkfs.btrfs /dev/mapper/nix

2.2.2. Create Btrfs Subvolume:

mount /dev/mapper/nix /mnt
btrfs subvolume create /mnt/nix
btrfs subvolume create /mnt/home
umount /mnt

2.2.3. Mount:

mount -t tmpfs none /mnt
mkdir -p /mnt/{boot,nix,home}
mount /dev/disk/by-id/ata-Netac_SSD_240GB_A0022282630000000466-part1 /mnt/boot
mount -o subvol=nix,compress-force=zstd,noatime /dev/mapper/nix /mnt/nix
mount -o subvol=home,compress-force=zstd,noatime /dev/mapper/nix /mnt/home
mkdir -p /mnt/nix/persist/{etc/ssh,var/log}
mkdir -p /mnt/var/log
mount -o bind /mnt/nix/persist/var/log /mnt/var/log

2.3. Install System

nixos-install --no-root-passwd --root /mnt --system ./result

2.4. Umount

umount /mnt/boot 
umount /mnt/home 
umount /mnt/nix 
umount /mnt/var/log 
umount /mnt
cryptsetup luksClose nix

Reboot!

2.5. Post Install

sudo nixos-rebuild switch --flake ./#nas --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store https://mirror.sjtu.edu.cn/nix-channels/store https://mirrors.ustc.edu.cn/nix-channels/store https://cache.nixos.org/" -L -v

3. Darwin

3.1. Preview

mac.png

3.2. Disable SIP

csrutil disable --with kext --with dtrace --with basesystem

3.3. enable arm64e

sudo nvram boot-args=-arm64e_preview_abi

3.4. Install NIX

Stable

curl -L https://nixos.org/nix/install | sh

Unstable

NIX-UNSTABLE-INSTALL

3.5. Download My Flakes

3.6. Build My system

nix build --extra-experimental-features "nix-command flakes" ./#darwinConfigurations.m1.system

3.7. Move old files

sudo mv /etc/zshrc /etc/zshrc.backup
sudo mv /etc/zprofile /etc/zprofile.backup
sudo rm -rf /etc/nix/nix.conf
sudo rm -rf /Users/me/.nix-defexpr/channels

3.8. Softlink /run

echo 'run\tprivate/var/run' | sudo tee -a /etc/synthetic.conf
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t

3.9. Install my system

./result/sw/bin/darwin-rebuild switch --flake .#m1

3.10. Post Install

Just need run:

darwin-rebuild switch --flake .#m1 -L -v

4. Tips

4.1. Create ~/.smb-secrets

username=
password=

4.2. Create Windows VM

sudo virt-install --virt-type=kvm \
--name=windows11 \
--memory=8196 \
--vcpus=6 \
--boot uefi \
--machine q35 \
--cpu=host-passthrough \
--cdrom=/home/me/Win11_English_x64.iso \
--os-variant win10 \
--network bridge=br0,model=e1000

4.3. Create ~/.gnupg/gpg-agent.conf

pinentry-program /run/current-system/sw/bin/pinentry

4.4. Gpg: selecting card failed (only macOS)

echo "disable-ccid" >> ~/.gnupg/scdaemon.conf
pkill gpg-agent; gpg-agent --homedir $HOME/.gnupg --daemon

4.5. Fix qutebrowser can't open (only macOS)

xattr -rd com.apple.quarantine /Applications/qutebrowser.app

4.6. Start a nixos vm

qemu-img create -f qcow2 nixos.img 200G

qemu-system-aarch64 \
    -monitor stdio \
    -M virt,highmem=off \
    -accel hvf \
    -cpu cortex-a72 \
    -smp 4 \
    -m 4096 \
    -bios /nix/store/f6vj8a0cvr4j2fdypzzyzp5fxmkkjvby-qemu-6.1.0/share/qemu/edk2-aarch64-code.fd \
    -device virtio-gpu-pci \
    -device qemu-xhci \
    -device usb-kbd \
    -device usb-tablet \
    -device intel-hda \
    -device hda-duplex \
    -netdev user,id=vmnic,hostname=nixos,hostfwd=tcp:127.0.0.1:22222-:22,hostfwd=tcp:127.0.0.1:22223-:3389 \
    -device virtio-net,netdev=vmnic \
    -drive file=nixos.img,if=virtio,cache=writethrough \
    "$@"

Author: NULL

Created: 2022-01-04 Tue 12:57

Validate