From bc60f155aa973af80fe0d72a93ff725c16ea30ea Mon Sep 17 00:00:00 2001 From: Jacob Bachmann Date: Tue, 16 Apr 2024 20:37:08 +0200 Subject: [PATCH] feat: a lot of stuff --- hosts/IROH/default.nix | 3 + hosts/T430/default.nix | 3 + hosts/W530/default.nix | 3 + modules/audio.nix | 9 +- modules/default.nix | 12 +- modules/keyd.nix | 7 +- modules/nix.nix | 32 +++--- modules/ollama.nix | 6 + modules/packages.nix | 1 + modules/ratbag.nix | 3 + modules/rr.nix | 1 - modules/tts.nix | 17 +++ modules/unfree.nix | 3 - modules/virtualisation.nix | 9 ++ overlays/pppdf/default.nix | 26 +++++ overlays/pppdf/pppdf.py | 107 ++++++++++++++++++ users/gandalf/modules/audio.nix | 21 ++++ users/gandalf/modules/default.nix | 1 + .../gandalf/modules/gui/programs/default.nix | 6 + 19 files changed, 250 insertions(+), 20 deletions(-) create mode 100644 modules/ollama.nix create mode 100644 modules/ratbag.nix create mode 100644 modules/tts.nix delete mode 100644 modules/unfree.nix create mode 100644 overlays/pppdf/default.nix create mode 100644 overlays/pppdf/pppdf.py create mode 100644 users/gandalf/modules/audio.nix diff --git a/hosts/IROH/default.nix b/hosts/IROH/default.nix index baf1293..7275b21 100755 --- a/hosts/IROH/default.nix +++ b/hosts/IROH/default.nix @@ -20,6 +20,9 @@ devenv.enable = true; virtualisation.enable = true; games.enable = true; + ratbag.enable = true; + + ai.enable = true; }; diff --git a/hosts/T430/default.nix b/hosts/T430/default.nix index eb99c0f..055621a 100755 --- a/hosts/T430/default.nix +++ b/hosts/T430/default.nix @@ -21,6 +21,9 @@ devenv.enable = true; virtualisation.enable = true; games.enable = true; + ratbag.enable = true; + + ai.enable = false; }; diff --git a/hosts/W530/default.nix b/hosts/W530/default.nix index 0226203..f166ff3 100644 --- a/hosts/W530/default.nix +++ b/hosts/W530/default.nix @@ -20,6 +20,9 @@ devenv.enable = true; virtualisation.enable = true; games.enable = true; + ratbag.enable = true; + + ai.enable = false; }; diff --git a/modules/audio.nix b/modules/audio.nix index e48ae11..fd67443 100644 --- a/modules/audio.nix +++ b/modules/audio.nix @@ -1,4 +1,4 @@ -{ config, lib, ... }: lib.mkIf config.bchmnn.audio.enable { +{ pkgs, config, lib, ... }: lib.mkIf config.bchmnn.audio.enable { # Enable pipewire - audio services.pipewire = { enable = true; @@ -7,5 +7,12 @@ alsa.support32Bit = true; jack.enable = true; pulse.enable = true; + wireplumber.enable = true; }; + + environment.systemPackages = with pkgs; [ + alsa-utils + pulseaudio + ]; + } diff --git a/modules/default.nix b/modules/default.nix index ca4be9c..4626b8e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -50,6 +50,14 @@ enable = mkEnableOption "games"; }; + ai = { + enable = mkEnableOption "ai"; + }; + + ratbag = { + enable = mkEnableOption "ratbag"; + }; + }; imports = [ @@ -69,19 +77,21 @@ ./nix-ld.nix ./nix.nix ./nvidia.nix + ./ollama.nix ./opengl.nix ./openssh.nix ./openvpn.nix ./power.nix ./packages.nix ./printing.nix + ./ratbag.nix ./rr.nix ./security.nix ./shell.nix ./steam.nix ./syncthing.nix + ./tts.nix ./udisks2.nix - ./unfree.nix ./virtualisation.nix ./xdg-portal.nix ]; diff --git a/modules/keyd.nix b/modules/keyd.nix index 71185bd..f3b36c0 100644 --- a/modules/keyd.nix +++ b/modules/keyd.nix @@ -34,7 +34,12 @@ in services.keyd = { enable = true; keyboards.default = { - ids = [ "*" "-04fe:0020" ]; + ids = [ + "*" + "-04fe:0020" # HHKB + "-046d:102a" # Logitech G700s + "-046d:c07c" # Logitech G700s Rechargeable Gaming Mouse + ]; settings = { main = { leftalt = "layer(meta)"; diff --git a/modules/nix.nix b/modules/nix.nix index 194d1a3..c551420 100644 --- a/modules/nix.nix +++ b/modules/nix.nix @@ -8,19 +8,25 @@ }; }; - nixpkgs.overlays = [ - (self: super: { - bun-baseline = (super.callPackage ../overlays/bun-baseline.nix { }); - mfcl3750cdwlpr = (super.callPackage ../overlays/mfcl3750cdw.nix { }).driver; - mfcl3750cdwcupswrapper = (super.callPackage ../overlays/mfcl3750cdw.nix { }).cupswrapper; - }) - ]; - - # allow EOL version electron for obsidian - # TODO: remove - nixpkgs.config.permittedInsecurePackages = [ - "electron-25.9.0" - ]; + nixpkgs = { + overlays = [ + (self: super: { + bun-baseline = (super.callPackage ../overlays/bun-baseline.nix { }); + mfcl3750cdwlpr = (super.callPackage ../overlays/mfcl3750cdw.nix { }).driver; + mfcl3750cdwcupswrapper = (super.callPackage ../overlays/mfcl3750cdw.nix { }).cupswrapper; + pppdf = (super.python3Packages.callPackage ../overlays/pppdf { }); + }) + ]; + config = { + allowUnfree = true; + allowUnfreePredicate = (_: true); + # allow EOL version electron for obsidian + # TODO: remove + permittedInsecurePackages = [ + "electron-25.9.0" + ]; + }; + }; system.stateVersion = "23.05"; } diff --git a/modules/ollama.nix b/modules/ollama.nix new file mode 100644 index 0000000..85c76ed --- /dev/null +++ b/modules/ollama.nix @@ -0,0 +1,6 @@ +{ lib, config, ... }: lib.mkIf config.bchmnn.ai.enable { + services.ollama = { + enable = true; + acceleration = if config.bchmnn.nvidia.enable then "cuda" else null; + }; +} diff --git a/modules/packages.nix b/modules/packages.nix index 8bae43f..e8169bc 100644 --- a/modules/packages.nix +++ b/modules/packages.nix @@ -2,6 +2,7 @@ environment.systemPackages = with pkgs; with config.bchmnn; [ pciutils # a collection of programs for inspecting and manipulating configuration of pci devices usbutils # tools for working with usb devices, such as lsusb + lshw # provide detailed information on the hardware configuration of the machine git # distributed version control system gnumake # a tool to control the generation of non-source files from sources mercurial # a fast, lightweight scm system for very large distributed projects diff --git a/modules/ratbag.nix b/modules/ratbag.nix new file mode 100644 index 0000000..b47f7e9 --- /dev/null +++ b/modules/ratbag.nix @@ -0,0 +1,3 @@ +{ + services.ratbagd.enable = true; +} diff --git a/modules/rr.nix b/modules/rr.nix index 6266759..28f0301 100644 --- a/modules/rr.nix +++ b/modules/rr.nix @@ -6,7 +6,6 @@ virtualisation = { oci-containers = { - backend = "podman"; containers = { flare-solvarr = { image = "ghcr.io/flaresolverr/flaresolverr:latest"; diff --git a/modules/tts.nix b/modules/tts.nix new file mode 100644 index 0000000..4d8194d --- /dev/null +++ b/modules/tts.nix @@ -0,0 +1,17 @@ +{ lib, config, ... }: lib.mkIf config.bchmnn.ai.enable { + + virtualisation = { + oci-containers = { + containers = { + coqui-ai-tts = { + image = "ghcr.io/coqui-ai/tts:latest"; + autoStart = true; + ports = ["127.0.0.1:5002:5002"]; + entrypoint = "/bin/bash"; + cmd = []; + }; + }; + }; + }; + +} diff --git a/modules/unfree.nix b/modules/unfree.nix deleted file mode 100644 index e83f701..0000000 --- a/modules/unfree.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ ... }: { - nixpkgs.config.allowUnfree = true; -} diff --git a/modules/virtualisation.nix b/modules/virtualisation.nix index bb87cd7..4317d29 100644 --- a/modules/virtualisation.nix +++ b/modules/virtualisation.nix @@ -10,11 +10,20 @@ # required for containers under podman-compose to be able to talk to each other. defaultNetwork.settings.dns_enabled = true; }; + oci-containers = { + backend = "podman"; + }; + containers = { + enable = true; + cdi.dynamic.nvidia.enable = config.bchmnn.nvidia.enable; + }; }; + programs = { dconf.enable = true; virt-manager.enable = true; }; + environment.systemPackages = with pkgs; [ virtiofsd ]; } diff --git a/overlays/pppdf/default.nix b/overlays/pppdf/default.nix new file mode 100644 index 0000000..293143e --- /dev/null +++ b/overlays/pppdf/default.nix @@ -0,0 +1,26 @@ +{ pkgs, lib, buildPythonApplication, python3Packages }: +buildPythonApplication { + pname = "pppdf"; + version = "1.0.0"; + src = ./pppdf.py; + + nativeBuildInputs = [ + pkgs.wrapGAppsHook + pkgs.gobject-introspection + ]; + + propagatedBuildInputs = with python3Packages; [ pkgs.gtk3 pygobject3 notify2 pikepdf ]; + + dontUnpack = true; + format = "other"; + + installPhase = '' + install -D $src $out/bin/pppdf + ''; + + meta = with lib; { + description = "PDF Postprocessor"; + license = licenses.mit; + }; + +} diff --git a/overlays/pppdf/pppdf.py b/overlays/pppdf/pppdf.py new file mode 100644 index 0000000..e967fdb --- /dev/null +++ b/overlays/pppdf/pppdf.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python + +import sys +import math +import os + +try: + import notify2 +except: + print('Missing library: notify2') + exit(1) + +notify2.init('pppdf') +# notify2.Notification('pppdf', f'Working dir: {os.getcwd()}').show() + +try: + import pikepdf +except: + notify2.Notification('pppdf', 'Missing library: pikepdf').show() + print('Missing library: pikepdf') + exit(1) + +try: + import gi + gi.require_version("Gtk", "3.0") + from gi.repository import Gtk +except: + notify2.Notification('pppdf', 'Missing library: gi').show() + print('Missing library: gi') + exit(1) + +if len(sys.argv) != 5: + notify2.Notification('pppdf', 'Error: invalid arguments.').show() + print('Error: invalid arguments.') + print(f'Usage: {sys.argv[0]} ') + exit(1) + +mime = sys.argv[1] +keep = sys.argv[2] +source = sys.argv[3] +mode = sys.argv[4] + +if mime != 'application/pdf': + notify2.Notification('pppdf', 'Error: Only support for pdf.').show() + print('Error: Only support for pdf.') + exit(1) + + +def pppdf_zip(): + try: + with pikepdf.open(source) as pdf: + + target = pikepdf.Pdf.new() + + n = len(pdf.pages) + if mode == "zip": + pattern = [i // 2 if i % 2 == 0 else math.ceil(n / 2) + i // 2 for i in range(n)] + else: + pattern = [i // 2 if i % 2 == 0 else n - (i // 2) - 1 for i in range(n)] + print(pattern) + for i in pattern: + target.pages.append(pdf.pages[i]) + + if keep != "false": + pdf.save(source + ".orig") + target.save(source) + notify2.Notification('pppdf', f'Success: {source}').show() + except Exception as error: + notify2.Notification('pppdf', f'Error: {error}').show() + + + +class Dialog(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self, title="pppdf") + + self.set_border_width(6) + label = Gtk.Label(label=f"Do you want to zip {source}?") + + btn_cancel = Gtk.Button(label="Cancel") + btn_ok = Gtk.Button(label="Ok") + btn_cancel.connect("clicked", self.on_btn_cancel_clicked) + btn_ok.connect("clicked", self.on_btn_ok_clicked) + + buttons = Gtk.Box(spacing=6) + buttons.pack_start(btn_cancel, True, True, 0) + buttons.pack_start(btn_ok, True, True, 0) + + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) + + vbox.pack_start(label, True, True, 0) + vbox.pack_start(buttons, True, True, 0) + + self.add(vbox) + + def on_btn_cancel_clicked(self, widget): + Gtk.main_quit() + + def on_btn_ok_clicked(self, widget): + pppdf_zip() + Gtk.main_quit() + +win = Dialog() +win.connect("destroy", Gtk.main_quit) +win.show_all() +Gtk.main() + diff --git a/users/gandalf/modules/audio.nix b/users/gandalf/modules/audio.nix new file mode 100644 index 0000000..c3d1c10 --- /dev/null +++ b/users/gandalf/modules/audio.nix @@ -0,0 +1,21 @@ +{ + xdg.configFile."wireplumber/wireplumber.conf.d/51-scarlett-samplerate.conf" = { + text = '' + monitor.alsa.rules = [ + { + matches = [ + { + node.nick = "Scarlett 2i2 USB" + } + ] + actions = { + update-props = { + audio.rate = 44100 + api.acp.probe-rate = 44100 + } + } + } + ] + ''; + }; +} diff --git a/users/gandalf/modules/default.nix b/users/gandalf/modules/default.nix index d804c12..20c371e 100644 --- a/users/gandalf/modules/default.nix +++ b/users/gandalf/modules/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./audio.nix ./dconf.nix ./fzf.nix ./gui diff --git a/users/gandalf/modules/gui/programs/default.nix b/users/gandalf/modules/gui/programs/default.nix index 22e40ca..8c65b62 100644 --- a/users/gandalf/modules/gui/programs/default.nix +++ b/users/gandalf/modules/gui/programs/default.nix @@ -25,6 +25,7 @@ gnome.nautilus # the file manager for gnome gnome.simple-scan # simple scanning utility + pppdf feh # a light-weight image viewer vlc # cross-platform media player and streaming server zathura # a highly customizable and functional pdf viewer @@ -41,9 +42,14 @@ ] ++ lib.optionals nixosConfig.bchmnn.printing.enable [ system-config-printer # graphical user interface for cups administration + ] ++ lib.optionals nixosConfig.bchmnn.games.enable [ openjdk17 # the open-source java development kit prismlauncher # a free, open source launcher for minecraft + + ] ++ lib.optionals nixosConfig.bchmnn.ratbag.enable [ + piper # gtk frontend for ratbagd mouse config daemon + ]; }