Skip to content

Instantly share code, notes, and snippets.

@newtolinux23
Created July 5, 2024 04:53
Show Gist options
  • Select an option

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

Select an option

Save newtolinux23/e646b7f1deb5957c42614dee743cee3c to your computer and use it in GitHub Desktop.
Adding Nix Flakes, issues with Nixos-rebuild switch –upgrade NetworkManager-wait-online.service failure
Title Author Date Tags Reading Time
Fixing NetworkManager-wait-online Issue and Incorporating Nix Flakes
Rob Alicea
2024-07-04
Nix-flakes
Linux
NixOS
3 min

Table of Contents

Issue Description

I encountered an issue where the NetworkManager-wait-online.service was causing delays and failures during the system boot process. The goal was to disable this service to improve the boot time and overall system performance.

Fixing the Issue

To resolve the issue, I needed to disable the NetworkManager-wait-online service in our NixOS configuration.

Disabling NetworkManager-wait-online

I modified the configuration.nix file to explicitly disable the NetworkManager-wait-online service using the systemd.services option.

{ 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;
  networking.nameservers = [ "127.0.0.1" ];

  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 = true;
  services.xserver.desktopManager.gnome.enable = true;

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

  services.flatpak.enable = true;

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

  environment.systemPackages = with pkgs; [
    wget git emacs ripgrep fd shellcheck discount cmake gnumake python310
    python310Packages.isort python310Packages.nose python310Packages.pytest
    python310Packages.pip python310Packages.setuptools python310Packages.pip
    pipenv cabextract podman podman-compose distrobox floorp docker-compose
    flatpak hugo ffmpeg tlp gnome3.gnome-tweaks dconf gnome3.gnome-shell
    gnomeExtensions.pop-shell
  ];

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

  fonts.enableDefaultPackages = true;
  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 30d";

  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" ];
        endpoint = "${secrets.endpoint}:51820";
        persistentKeepalive = 25;
      }];
    };
  };

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

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

  services.resolved.enable = true;

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

  system.stateVersion = "24.05";
}

Rebuilding the System

After modifying the configuration, we rebuilt the system to apply the changes.

sudo nixos-rebuild switch --flake .#rob-nixos --show-trace

Incorporating Nix Flakes

To take advantage of the benefits provided by Nix flakes, we incorporated flakes into our NixOS configuration.

Flake Configuration

We created a flake.nix file to define our flake, specifying the inputs and outputs for our NixOS configuration.

{
  description = "NixOS configuration for Rob's system";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }: {
    nixosConfigurations = {
      rob-nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
        ];
      };
    };
  };
}

Updating and Rebuilding

To update and rebuild the system using flakes, we followed these steps:

  1. Update the flake:
    sudo nix flake update
        
  2. Rebuild the system:
    sudo nixos-rebuild switch --flake .#rob-nixos --show-trace
        
  3. Upgrade the system:
    sudo nixos-rebuild switch --flake .#rob-nixos --upgrade
        

By following these steps, I successfully incorporated Nix flakes into our NixOS configuration, enabling us to manage and update our system more efficiently.

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