nix-config
nix-config copied to clipboard
My NixOS and Nix configuration
#+TITLE: Otavio Salvador's Nix Configuration
- Table of Contents :PROPERTIES: :TOC: :include all :ignore (this) :END: :CONTENTS:
- [[#installing-nixos-on-a-newexisting-device][Installing NixOS on a new/existing device]]
- [[#generating-the-nixos-installer-with-ssh-and-networkmanager-support][Generating the NixOS Installer with SSH and NetworkManager support]]
- [[#doing-the-partitioning-of-disk][Doing the partitioning of disk]]
- [[#generate-the-configurationnix---optional][Generate the configuration.nix - optional]]
- [[#install-the-device-using-the-desired-configuration][Install the device using the desired configuration]]
- [[#installation-inside-an-existing-linux-system][Installation inside an existing Linux system]] :END: :CUSTOM_ID: configuration-repository :END:
- Installing NixOS on a new/existing device
** Generating the NixOS Installer with SSH and NetworkManager support
To generate the installer you can run:
#+begin_src sh
nix build .#mkInstallerIso
#+end_src
** Doing the partitioning of disk
The installer allow SSH connection and has the authorized keys based on ~otavio~ user. Currently, I've been using following steps to format the disk:
#+begin_src sh
device=/dev/xxx deviceNixOSPart=${device}1 deviceEFIPart=${device}2
parted ${device} -- mklabel gpt parted ${device} -- mkpart primary 512MiB 100% parted ${device} -- mkpart ESP fat32 1MiB 512MiB parted ${device} -- set 2 esp on
mkdosfs -F32 ${deviceEFIPart} -n EFI
mkfs.btrfs ${deviceNixOSPart} mount -t btrfs ${deviceNixOSPart} /mnt
btrfs subvolume create /mnt/nixos btrfs subvolume create /mnt/home btrfs subvolume snapshot -r /mnt/nixos /mnt/nixos-blank
umount /mnt mount -o subvol=nixos,compress=zstd,discard,noatime,autodefrag ${deviceNixOSPart} /mnt
mkdir /mnt/home mount -o subvol=home,compress=zstd,discard,noatime,autodefrag ${deviceNixOSPart} /mnt/home
mkdir /mnt/efi mount ${deviceEFIPart} /mnt/efi
#+end_src
** Generate the =configuration.nix= - optional
Once the partitioning is done, we may generate the =hardware-configuration.nix= if it is a new device. We than copy it to our machine definition.
#+begin_src sh
nixos-generate-config --root /mnt/
#+end_src
** Install the device using the desired configuration
The installation of the machine can be done using the machine's flake. For it use:
#+begin_src text
nixos-install --flake https://github.com/otavio/nix-config#
#+end_src
- Installation inside an existing Linux system
For Debian-based systems we need to have =curl=, =rsync=, =zsh=, =xz-utils= and =git-core= before proceeding. Use:
#+begin_src sh sudo apt install -y curl rsync zsh xz-utils git-core #+end_src
The user must use =zsh= as shell so do it using:
#+begin_src sh sudo usermod -s /bin/zsh otavio #+end_src
Install the daemon inside the existing operating system with:
#+begin_src sh curl -L https://nixos.org/nix/install | sh -s -- --daemon
Enable Nix Flakes support
mkdir -p ~/.config/nix echo 'experimental-features = nix-command flakes' > ~/.config/nix/nix.conf #+end_src
Finally, clone this repository as:
#+begin_src sh mkdir -p ~/src git clone https://github.com/otavio/nix-config.git ~/src/nix-config #+end_src
Add the required channels to the environment, using:
#+begin_src sh home-manager switch --flake .#otavio #+end_src