Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save newtolinux23/a058571bec6292da475e4d23644df0fe to your computer and use it in GitHub Desktop.

Select an option

Save newtolinux23/a058571bec6292da475e4d23644df0fe to your computer and use it in GitHub Desktop.
This document provides a comprehensive guide to the issues faced during the configuration and maintenance of a NixOS system, the solutions implemented to resolve these issues, and a set of commands for regular maintenance.

NixOS Troubleshooting and Maintenance Guide

https://user-images.githubusercontent.com/45159366/128645106-874b3883-1d6f-46b8-86f4-2cefd54d4117.png

Table of Contents

Introduction

This document provides a comprehensive guide to the issues faced during the configuration and maintenance of a NixOS system, the solutions implemented to resolve these issues, and a set of commands for regular maintenance.

Issues and Solutions

Home Manager Configuration Issues

Problem

During the setup of Home Manager, several errors were encountered, including missing packages and syntax errors in the configuration files.

Solution

Updated the home.nix file to ensure proper syntax and included all necessary packages. Removed unnecessary or conflicting packages such as Python-related packages.

Corrected home.nix Configuration

{ config, pkgs, ... }:

{
  home.username = "rob";
  home.homeDirectory = "/home/rob";
  home.stateVersion = "24.05";

  home.packages = [
    pkgs.hugo
    pkgs.wget
    pkgs.git
    pkgs.docker
    pkgs.docker-compose
    pkgs.ispell
    pkgs.nixpkgs-fmt
  ];

  home.file = { };

  home.sessionVariables = {
    PATH = "${config.home.homeDirectory}/.config/emacs/bin:${pkgs.coreutils}/bin:${pkgs.docker}/bin:${pkgs.git}/bin:${pkgs.wget}/bin:${pkgs.ispell}/bin:${pkgs.nixpkgs-fmt}/bin";
  };

  programs.bash = {
    enable = true;
    initExtra = ''
      export PATH="$HOME/.config/emacs/bin:$PATH"
    '';
    shellAliases = {
      ll = "ls -la";
      gs = "git status";
      up = "sudo nixos-rebuild switch --upgrade";
    };
  };

  programs.home-manager.enable = true;
}

System Configuration Issues

Problem

Errors encountered due to invalid options like system.autoUpgrade.numberOfGenerations. Additionally, issues with ClamAV package causing build failures.

Solution

Removed invalid options and ClamAV package from the configuration. Ensured proper inclusion of necessary packages and correct syntax in configuration.nix.

Corrected configuration.nix

{ config, pkgs, lib, ... }:
let
  secrets = import ./secrets.nix;
in

{
  imports = [
    ./hardware-configuration.nix
  ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  networking.networkmanager.enable = true;
  systemd.services."NetworkManager-wait-online".enable = false;

  time.timeZone = "America/Chicago";
  i18n.defaultLocale = "en_US.UTF-8";

  boot.kernelParams = [
    "intel_iommu=on"
    "iommu=pt"
  ];

  services.timesyncd.enable = true;

  powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand";

  services.xserver.enable = true;
  services.xserver.displayManager.gdm.enable = lib.mkForce true;
  services.xserver.desktopManager.gnome.enable = true;

  services.tlp.enable = true;
  powerManagement.powertop.enable = true;
  services.power-profiles-daemon.enable = false;

  services.flatpak.enable = true;

  users.mutableUsers = false;
  users.users = {
    root = {
      password = secrets.passdw;
    };
    rob = {
      isNormalUser = true;
      description = "Rob Alicea";
      extraGroups = [ "wheel" "networkmanager" "docker" "kvm" "libvirtd" ];
      password = secrets.passd;
      home = "/home/rob";
    };
  };

  environment.systemPackages = with pkgs; [
    wget vim git ripgrep fd shellcheck discount cmake gnumake pipenv cabextract flatpak ffmpeg tlp dconf gnome3.gnome-shell gnomeExtensions.pop-shell nixpkgs-fmt emacs qemu_kvm virt-manager virt-viewer gitAndTools.git-extras gnomeExtensions.user-themes gnome-themes-extra arc-theme papirus-icon-theme fastfetch gnome-tweaks
  ];

  boot.kernelModules = [ "binder_linux" "ashmem_linux" ];

  fonts.packages = with pkgs; [
    fira-code
    (pkgs.fetchurl {
      url = "https://downloads.sourceforge.net/project/corefonts/the%20fonts/final/arial32.exe";
      sha256 = secrets.sha256Hash;
    })
  ];

  nix.gc.automatic = true;
  nix.gc.dates = "weekly";
  nix.gc.options = "--delete-older-than 10d";

  networking.wg-quick.interfaces = {
    wg0 = {
      address = [ "10.72.1.2/24" ];
      listenPort = 51820;
      privateKey = secrets.wireguardPrivateKey;
      dns = [ "10.72.1.1" ];
      peers = [{
        publicKey = "HYrJHiCFn5+dzDzr1RSHWHsbc0Cv8RhRaABNDl5Xd0A=";
        allowedIPs = [ "0.0.0.0/0, ::/0" ];
        endpoint = "${secrets.endpoint}:51820";
        persistentKeepalive = 25;
      }];
    };
  };

  virtualisation.podman.enable = true;
  virtualisation.waydroid.enable = true;
  virtualisation.docker.enable = true;
  virtualisation.docker.rootless = {
    enable = true;
    setSocketVariable = true;
  };

  virtualisation.libvirtd = {
    enable = true;
    qemu.package = pkgs.qemu_kvm;
  };

  networking.firewall = {
    enable = true;
    allowedTCPPorts = [ 22 80 443 8443 ];
    allowedUDPPorts = [ 123 ];
    interfaces = {
      "eth0" = { allowedTCPPorts = [ 8080 ]; };
    };
  };

  services.resolved.enable = true;

  environment.etc."NetworkManager/NetworkManager.conf".text = lib.mkForce ''
    [main]
    dns=systemd-resolved
  '';

  systemd.services.systemd-oomd.enable = false;
  systemd.sockets.systemd-oomd.enable = false;

  system.stateVersion = "24.05";
}

Conclusion

After resolving the issues with Home Manager and system configurations, the system is now stable and functioning as expected. The following maintenance commands are essential for keeping the system updated and optimized.

Maintenance Commands

Regular Updates

Keep your system updated with the latest packages and configurations.

sudo nixos-rebuild switch --upgrade --flake .#rob-nixos
home-manager switch --flake .

Garbage Collection

Clean up old generations and unused packages to free up disk space.

sudo nix-collect-garbage -d

Optimize Nix Store

Optimize the Nix store to improve performance.

sudo nix store optimise

Monitor System

Use journalctl and other tools to monitor system health.

journalctl -xe

Manage Generations

List and delete old generations to keep your system clean.

nix-env --list-generations
nix-env --delete-generations old

Additional Tips

  • Use Git for version control of your Nix and Home Manager configurations.
  • Document custom configurations and important commands for future reference.

If you encounter any issues or need further assistance, feel free to ask for help.

@adamdicarlo0
Copy link

You don't need to manually set PATH like that... Home Manager builds a big ol' set of symlinks for all the packages installed via home.packages and adds it to your path for you. (Same thing happens for environment.systemPackages, but it's the set of symlinks is located in a system-wide place.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment