From addb1d9fba052377f001fd79f4bbbc7d454cba6e Mon Sep 17 00:00:00 2001 From: Berk Arslan Date: Wed, 11 Sep 2024 15:16:38 +0300 Subject: [PATCH] Add printing service in zathura-vm, chromium-vm and bussiness-vm CUPS is enabled in zathura-vm, chromium-vm and bussines-vm CUPS overlay is applied due to printer webpage bug. Avahi service reflection is added in net-vm. CUPS web page is added into default chromium bookmarks. Signed-off-by: Berk Arslan --- modules/common/services/default.nix | 1 + modules/common/services/printer.nix | 65 +++++++++++++++++++ .../microvm/virtualization/microvm/netvm.nix | 5 ++ modules/reference/appvms/business.nix | 6 ++ modules/reference/appvms/chromium.nix | 6 ++ modules/reference/appvms/zathura.nix | 5 ++ overlays/custom-packages/cups/default.nix | 14 ++++ overlays/custom-packages/default.nix | 1 + 8 files changed, 103 insertions(+) create mode 100644 modules/common/services/printer.nix create mode 100644 overlays/custom-packages/cups/default.nix diff --git a/modules/common/services/default.nix b/modules/common/services/default.nix index e099e98dff..abbd1aee53 100644 --- a/modules/common/services/default.nix +++ b/modules/common/services/default.nix @@ -11,5 +11,6 @@ ./namespaces.nix ./yubikey.nix ./bluetooth.nix + ./printer.nix ]; } diff --git a/modules/common/services/printer.nix b/modules/common/services/printer.nix new file mode 100644 index 0000000000..37c84f08b0 --- /dev/null +++ b/modules/common/services/printer.nix @@ -0,0 +1,65 @@ +# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors +# SPDX-License-Identifier: Apache-2.0 +{ config, lib, ... }: +let + cfg = config.ghaf.services.printer; + inherit (lib) mkIf mkEnableOption mkOption types optionalAttrs hasAttr; +in +{ + options.ghaf.services.printer = { + enable = mkEnableOption "Printer configuration for app-vms"; + name = mkOption { + type = types.string; + description = "App-vm name for storage-vm"; + }; + }; + config = mkIf cfg.enable { + + services.printing.enable = true; + services.avahi = { + enable = true; + nssmdns4 = true; + reflector = true; + }; + environment.etc."chromium/bookmarks.html".text = + '' + + + + Bookmarks +

Bookmarks

+

+

Bookmarks bar

+

+ '' + + "

Printing" + + '' +

+

+ ''; + programs.chromium.initialPrefs = { + "import_bookmarks" = false; + "distribution" = { + "import_bookmarks" = false; + "import_bookmarks_from_file" = "/etc/chromium/bookmarks.html"; + "bookmark_bar" = { + "show_on_all_tabs" = true; + }; + }; + }; + ghaf = optionalAttrs (hasAttr "storagevm" config.ghaf) { + storagevm = { + enable = true; + name = cfg.name; + directories = [ "/etc/cups/" ]; + }; + }; + }; +} diff --git a/modules/microvm/virtualization/microvm/netvm.nix b/modules/microvm/virtualization/microvm/netvm.nix index b22ace7009..9c88f970fc 100644 --- a/modules/microvm/virtualization/microvm/netvm.nix +++ b/modules/microvm/virtualization/microvm/netvm.nix @@ -85,6 +85,11 @@ let firewall.allowedTCPPorts = [ 53 ]; firewall.allowedUDPPorts = [ 53 ]; }; + services.avahi = { + enable = true; + nssmdns4 = true; + reflector = true; + }; services.openssh = config.ghaf.security.sshKeys.sshAuthorizedKeysCommand; diff --git a/modules/reference/appvms/business.nix b/modules/reference/appvms/business.nix index 9138ad99df..b5a267be2f 100644 --- a/modules/reference/appvms/business.nix +++ b/modules/reference/appvms/business.nix @@ -96,6 +96,12 @@ in # Set default PDF XDG handler xdg.mime.defaultApplications."application/pdf" = "ghaf-pdf.desktop"; + # Enable printer service + ghaf.services.printer = { + enable = true; + name = "${name}"; + }; + # TODO: Add a way to configure the gpclient # also check the openconnect cli options https://discourse.nixos.org/t/globalprotect-vpn/24014/5 services.globalprotect = { diff --git a/modules/reference/appvms/chromium.nix b/modules/reference/appvms/chromium.nix index 48ec7444e3..717735a968 100644 --- a/modules/reference/appvms/chromium.nix +++ b/modules/reference/appvms/chromium.nix @@ -86,6 +86,12 @@ in # Set default PDF XDG handler xdg.mime.defaultApplications."application/pdf" = "ghaf-pdf.desktop"; + + # Enable printer service + ghaf.services.printer = { + enable = true; + name = "${name}"; + }; } ]; borderColor = "#630505"; diff --git a/modules/reference/appvms/zathura.nix b/modules/reference/appvms/zathura.nix index d8f7a7d522..75c3ca7b1f 100644 --- a/modules/reference/appvms/zathura.nix +++ b/modules/reference/appvms/zathura.nix @@ -23,6 +23,11 @@ name = lib.mkForce "zathura-vm"; applications = lib.mkForce ''{"zathura": "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/zathura"}''; }; + # Enable printer service + ghaf.services.printer = { + enable = true; + name = "zathura"; + }; } ]; borderColor = "#122263"; diff --git a/overlays/custom-packages/cups/default.nix b/overlays/custom-packages/cups/default.nix new file mode 100644 index 0000000000..497064f468 --- /dev/null +++ b/overlays/custom-packages/cups/default.nix @@ -0,0 +1,14 @@ +# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors +# SPDX-License-Identifier: Apache-2.0 +{ final, prev }: +prev.cups.overrideAttrs ( + _final: _prev: { + # Due to the incorrect printer URI bug: https://github.com/OpenPrinting/cups/issues/998 + src = final.fetchFromGitHub { + owner = "OpenPrinting"; + repo = "cups"; + rev = "313c388dbc023bbcb75d1efed800d0cfc992a6cc"; + hash = "sha256-weu12hlrYUYY90pe0dJ6CiLtm8ynrLA9nT4j7iRwA+Q="; + }; + } +) diff --git a/overlays/custom-packages/default.nix b/overlays/custom-packages/default.nix index c2d90be845..919d96609d 100644 --- a/overlays/custom-packages/default.nix +++ b/overlays/custom-packages/default.nix @@ -21,4 +21,5 @@ gtklock = import ./gtklock { inherit prev; }; hardware-scan = final.callPackage ../../packages/hardware-scan { }; pulseaudio-ghaf = import ./pulseaudio { inherit prev; }; + cups = import ./cups { inherit final prev; }; })