Howto nixos

From Vidalinux Wiki
Jump to navigation Jump to search

configure enviroment

download nixos installation iso:

https://channels.nixos.org/nixos-23.05/latest-nixos-minimal-x86_64-linux.iso

create usb to install on physical desktop:

yay -S ventoy-bin

or install nixos on virtual machine:

qemu-img create -f qcow2 /var/lib/libvirt/images/nixos_disk1_100G.qcow2 100G

boot with nixos iso and create partitions:

parted /dev/vda -- mklabel gpt
parted /dev/sda -- mkpart ESP fat32 1 1GB
parted /dev/sda -- mkpart primary linux-swap 1GB 8GB
parted /dev/sda -- mkpart primary ext4 8GB 100%

format partitions:

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

installing os

mount root partition on /mnt:

mount /dev/vda3 /mnt

make boot directory and mount boot partition:

mkdir /mnt/boot
mount /dev/vda1 /mnt/boot

mount swap partition:

swapon /dev/vda2

generate nixos configuration file:

nixos-generate-config --root /mnt

edit configuration file /mnt/etc/nixos/configuration.nix:

{ config, pkgs, ... }:
{
  imports =
      ./hardware-configuration.nix
    ];
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  time.timeZone = "America/Puerto_Rico";
  i18n.defaultLocale = "en_US.UTF-8";
  services.xserver.enable = true;
  services.xserver.layout = "us";
  sound.enable = true;
  hardware.pulseaudio.enable = true;
  users.users.linux = {
     isNormalUser = true;
     extraGroups = [ "wheel" "networkmanager" "virt-manager" "scanner" "lp" ];
     packages = with pkgs; [
      firefox
      tree
     ];
   };
  services.openssh.enable = true;
} 

configure static ip networking:

networking.networkmanager.enable = true;
networking.interfaces.eth0.ipv4.addresses = [ {
 address = "192.168.75.44";
 prefixLength = 24;
} ];

networking.defaultGateway = "192.168.75.1";
networking.nameservers = [ "4.2.2.1" "4.2.2.2" ];

bridge network interface:

 networking.useDHCP = false;
 networking.bridges = {
   "br0" = {
     interfaces = [ "enp1s0" ];
   };
 };
 networking.interfaces.br0.ipv4.addresses = [ {
   address = "192.168.75.44";
   prefixLength = 24;
 } ];
 networking.defaultGateway = "192.168.75.1";
 networking.nameservers = ["4.2.2.1" "4.2.2.2"];

hostname and /etc/hosts:

networking.hostName = "nixos";
networking.extraHosts = 
   127.0.0.1     localhost
   192.168.75.44 nixos
 ;

enable ip forwarding:

 boot.kernel.sysctl."net.ipv4.ip_forward" = 1;

allow nonfree apps:

nixpkgs.config.allowUnfree = true;

configure desktop gnome:

services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
programs.dconf.enable = true;
services.udev.packages = with pkgs; [ gnome.gnome-settings-daemon ]; 

environment.gnome.excludePackages = (with pkgs; [
  gnome-photos
  gnome-tour
]) ++ (with pkgs.gnome; [
  gnome-terminal
  gedit # text editor
  evince # document viewer
  gnome-characters
]);

enable virtualization:

virtualisation.libvirtd.enable = true;

enable flatpak:

services.flatpak.enable = true;
xdg.portal.enable = true;

enable cups server for printers:

services.printing.enable = true;

enable scanner:

hardware.sane.enable = true;

enable podman containers:

 virtualisation = {
  podman.enable = true;
  oci-containers.backend = "podman";
};

then when system boot configure flatpak repo:

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

system packages:

environment.systemPackages = with pkgs; [
   wget vim nano zsh file lsof virt-manager
];

intel drivers:

services.xserver.videoDrivers = [ "modesetting" ];

if you experience screen tearing no matter what, this configuration was reported to resolve the issue:

services.xserver.videoDrivers = [ "intel" ];
services.xserver.deviceSection = ''
   Option "DRI" "2"
   Option "TearFree" "true"
 '';

nvidia gpu drivers:

services.xserver.videoDrivers = [ "nvidia" ];
boot.blacklistedKernelModules = [ "nouveau" ];

or nvidia gpu legacy drivers:

services.xserver.videoDrivers = [ "nvidiaLegacy390" ];
services.xserver.videoDrivers = [ "nvidiaLegacy340" ];
services.xserver.videoDrivers = [ "nvidiaLegacy304" ];

amd gpu drivers:

services.xserver.videoDrivers = [ "amdgpu-pro" ];

for laptop touchpads:

services.xserver.libinput.enable = true;

load kernel modules:

boot.kernelModules = [ "fuse" "kvm-intel" "coretemp" ];

load kernel modules on initrd:

boot.initrd.kernelModules = [ "cifs" ];

run the installer:

nixos-install

reboot the system:

reboot

os configuration

add unstable channel:

nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
nix-channel --update

run command without installing the package in your current session:

nix-shell -p git

verify current os configuration:

nix-shell -p nix-info --run "nix-info -m"

list current os generations:

nix-env --list-generations

command output:

  1   2023-06-26 11:42:47   
  2   2023-06-26 11:52:57   
  3   2023-06-26 11:53:04   
  4   2023-06-26 11:53:10   
  5   2023-06-26 11:53:21   
  6   2023-06-26 11:56:23   
  7   2023-06-26 11:56:47   
  8   2023-06-26 12:11:51   
  9   2023-06-26 12:11:59   (current)

delete os generations:

nix-env --delete-generations 1 2 3 4 5

references