From 9dec14bc80fb6ea89cdd3960e4553e3430a5e2ac Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 2 Nov 2024 18:42:16 +0100 Subject: [PATCH] prnt --- hardware/printer/common-share.nix | 56 ++++++++++++++++++++++++++ hardware/printer/hp-laserjet-p1005.nix | 4 ++ hosts/nixos/bjarte/configuration.nix | 4 +- profiles/printing.nix | 15 +++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 hardware/printer/common-share.nix create mode 100644 profiles/printing.nix diff --git a/hardware/printer/common-share.nix b/hardware/printer/common-share.nix new file mode 100644 index 0000000..fd569c6 --- /dev/null +++ b/hardware/printer/common-share.nix @@ -0,0 +1,56 @@ +{ lib, pkgs, ... }: +{ + + # airprint + # https://wiki.nixos.org/wiki/Printing#Printer_sharing + + services.avahi = { + enable = lib.mkDefault true; + nssmdns = true; + openFirewall = true; # opens port 5353 + publish.enable = true; + publish.userServices = true; + }; + services.printing = { + defaultShared = true; + browsing = true; + # allows anonymous access to printer + listenAddresses = [ "*:631" ]; + allowFrom = [ "all" ]; + openFirewall = true; + }; + + + # samba + # https://wiki.nixos.org/wiki/Samba#Printer_sharing + + /** / + services.samba = { + enable = lib.mkDefault true; + package = pkgs.sambaFull; # compiled with CUPS + + openFirewall = true; + settings = { + "global" = { + "load printers" = "yes"; + "printing" = "cups"; + "printcap name" = "cups"; + }; + "printers" = { + "comment" = "All Printers"; + "path" = "/var/spool/samba"; + "public" = "yes"; + "browseable" = "yes"; + # allow user 'guest account' to print. + "guest ok" = "yes"; + "writable" = "no"; + "printable" = "yes"; + "create mode" = 0700; + }; + }; + systemd.tmpfiles.rules = [ + "d /var/spool/samba 1777 root root -" + ]; + /**/ + +} diff --git a/hardware/printer/hp-laserjet-p1005.nix b/hardware/printer/hp-laserjet-p1005.nix index 3873e4c..22737ba 100644 --- a/hardware/printer/hp-laserjet-p1005.nix +++ b/hardware/printer/hp-laserjet-p1005.nix @@ -1,5 +1,9 @@ { lib, pkgs, ... }: { + imports = [ + ./common-share.nix + ]; + # https://nixos.wiki/wiki/Printing services.printing.enable = true; #services.printing.drivers = with pkgs; [ foo2zjs foomatic-filters cups-filters ]; diff --git a/hosts/nixos/bjarte/configuration.nix b/hosts/nixos/bjarte/configuration.nix index 4d59ee6..ce4371a 100644 --- a/hosts/nixos/bjarte/configuration.nix +++ b/hosts/nixos/bjarte/configuration.nix @@ -35,6 +35,8 @@ ../../../profiles/desktop/flatpak.nix ../../../profiles/desktop/waydroid.nix + ../../../profiles/printing.nix + ../../../profiles/known-hosts.nix ]; @@ -52,8 +54,6 @@ #networking.useDHCP = true; #TODO: avahi? resolved? https://git.pvv.ntnu.no/Drift/pvv-nixos-config/src/main/base.nix#L15-L18 - services.printing.enable = true; - # TODO: remove? Move? programs.dconf.enable = true; } diff --git a/profiles/printing.nix b/profiles/printing.nix new file mode 100644 index 0000000..5eb991f --- /dev/null +++ b/profiles/printing.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: +{ + + # https://wiki.nixos.org/wiki/Printing + + services.printing.enable = true; + + # Enable autodiscovery of network IPP printers + services.avahi = { + enable = true; + nssmdns4 = true; + openFirewall = true; # opens port 5353 + }; + +}