New Printer Issues

Hi all

When I do a nixos-rebuild switch, I get the following error

restarting sysinit-reactivation.target
reloading the following units: dbus.service
restarting the following units: polkit.service
starting the following units: accounts-daemon.service
warning: the following units failed: ensure-printers.service
× ensure-printers.service - Ensure NixOS-configured CUPS printers
     Loaded: loaded (/etc/systemd/system/ensure-printers.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Sun 2025-04-20 17:51:34 BST; 269ms ago
 Invocation: 90a73494ef974254a673467e5a3bc3fd
    Process: 13082 ExecStart=/nix/store/ilhk3zg3jrg2q9nh6p33h74h4gsmzpzr-unit-script-ensure-printers-start/bin/ensure-printers-start (code=exited, status=1/FAILURE)
   Main PID: 13082 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
         IO: 0B read, 0B written
   Mem peak: 2.2M
        CPU: 12ms

Apr 20 17:51:30 nixos systemd[1]: Starting Ensure NixOS-configured CUPS printers...
Apr 20 17:51:34 nixos ensure-printers-start[13083]: lpadmin: Unable to connect to 192.168.1.21:631: Host is down
Apr 20 17:51:34 nixos systemd[1]: ensure-printers.service: Main process exited, code=exited, status=1/FAILURE
Apr 20 17:51:34 nixos systemd[1]: ensure-printers.service: Failed with result 'exit-code'.
Apr 20 17:51:34 nixos systemd[1]: Failed to start Ensure NixOS-configured CUPS printers.
warning: error(s) occurred while switching to the new configuration

I previously had issues with the printer but eventually got it working, I tried changing my config files to make them more modular but now have this error.

My configuration.nix looks like this

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
  imports =
    [<nixpkgs/nixos/modules/services/hardware/sane_extra_backends/brscan5.nix>


 # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./packages.nix
    ];

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

  networking.hostName = "nixos"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  time.timeZone = "Europe/London";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_GB.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "en_GB.UTF-8";
    LC_IDENTIFICATION = "en_GB.UTF-8";
    LC_MEASUREMENT = "en_GB.UTF-8";
    LC_MONETARY = "en_GB.UTF-8";
    LC_NAME = "en_GB.UTF-8";
    LC_NUMERIC = "en_GB.UTF-8";
    LC_PAPER = "en_GB.UTF-8";
    LC_TELEPHONE = "en_GB.UTF-8";
    LC_TIME = "en_GB.UTF-8";
  };

  # Enable the X11 windowing system.
  # You can disable this if you're only using the Wayland session.
  services.xserver.enable = true;

  # Enable the KDE Plasma Desktop Environment.
  services.displayManager.sddm.enable = true;
  services.desktopManager.plasma6.enable = true;

  # Configure keymap in X11
  services.xserver.xkb = {
    layout = "gb";
    variant = "";
  };

  # Configure console keymap
  console.keyMap = "uk";

  # Enable CUPS to print documents.
   services.printing.enable = true;

services.avahi = {
  enable = true;
  nssmdns4 = true;
  openFirewall = true;
};
services.printing = {
  listenAddresses = [ "*:631" ];
  allowFrom = [ "all" ];
  browsing = true;
  defaultShared = true;
  openFirewall = true;
};


  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.martyn = {
    isNormalUser = true;
    description = "SquarePeg";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      kdePackages.kate
    #  thunderbird
    ];
  };

  # Enable automatic login for the user.
  services.xserver.displayManager.autoLogin.enable = true;
  services.xserver.displayManager.autoLogin.user = "squarepeg";

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

# Enable bluray/dvd
boot.kernelModules = [ "sg" ];

# Enable fonts
fonts.packages = with pkgs; [ nerdfonts ];

# Enable Steam
programs.steam = {
 enable = true;
remotePlay.openFirewall = true;
dedicatedServer.openFirewall = true;
localNetworkGameTransfers.openFirewall = true;
};

# Steam cursor fix
programs.steam.package = pkgs.steam.override {
extraPkgs = p: [
p.kdePackages.breeze
];
};



  # List packages installed in system profile. To search, run:
  # $ nix search wget

environment.systemPackages = let
    libbluray = pkgs.libbluray.override {
      withAACS = true;
      withBDplus = true;
    };
    myVlc = pkgs.vlc.override { inherit libbluray; }; # renamed this to avoid potential shadowing by `with pkgs;` 
  in [
    myVlc
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.11"; # Did you read the comment?

}

My hardware-configuration.nix is

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sr_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/27c2f63e-91e9-405b-ac75-d386683bae75";
      fsType = "btrfs";
      options = [ "subvol=@" ];
    };

  fileSystems."/DATA" =
    { device = "/dev/disk/by-uuid/c5f12c62-1e4c-4c34-b949-1c9f47857702";
      fsType = "ext4";
    };

  fileSystems."/STEAM" =
    { device = "/dev/disk/by-uuid/830814ac-e33f-443f-9b62-7795c36db8db";
      fsType = "ext4";
    };

  fileSystems."/STEAM-HDD" =
    { device = "/dev/disk/by-uuid/76230a19-9d42-42ab-bf54-ebbb3ecca662";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/FC00-6584";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/456369f9-e605-4f4d-9097-b70b5cfaf17d"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp38s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

# Enable Printer
hardware.printers = {
  ensureDefaultPrinter = "Brother";
  ensurePrinters = [{
    name = "Brother";
    location = "office";
    model = "everywhere";
ppdOptions = {
      pageSize = "A4";
    };
    description = "Brother MFC-J4340DW";
    deviceUri = "ipp://192.168.1.21/ipp";
  }];
};

# Enable Scanner
hardware = {
sane = {
enable = true;
brscan5 = {
enable = true;
netDevices = {
home = { model = "MFC-J4340DW"; ip = "192.168.1.21"; };
};
};
};
};

}

and finally I have some packages installed via a different config file (packages.nix):

{ pkgs, ... }:
{
  environment.systemPackages = with pkgs; [ 
gitFull
kdePackages.yakuake
librewolf
kdePackages.kpat
strawberry-qt6
kdePackages.k3b
kdePackages.sddm-kcm
backintime
protonup-qt
makemkv
handbrake
mpv
calibre
fuse-emulator
zapzap
nfs-utils
yt-dlp
duf
mediaelch-qt6
picard
kdePackages.kdenlive
lutris
gramps
eza
aria2
veracrypt
gamemode
digikam
get_iplayer
kdePackages.kdeconnect-kde

];
}

Can anyone help?

Appears to me as if it wants to start a script that contacts the printer which fails, if you read the log message lpadmin: Unable to connect to 192.168.1.21:631: Host is down.

Dumb question, is the printer on? Even if it isn’t, while the “Warning” might be annoying, it won’t stop the switch from happening and it shouldn’t stop you from printing if it worked once.

Well I’ll be damned. I feel so stupid now, someone unplugged the printer to use the socket for something. I’m so sorry to waste your time, it’s working perfectly and the scanner is too.

Thank you and again, apologies