From 0fd5119b9d20d0320154e6278c8958f202973056 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 22 Sep 2021 21:11:22 +0200 Subject: [PATCH] pulsebert: copy from pipebert --- host-registry.nix | 1 + hosts/pipebert/default.nix | 213 +++++++++++++++++++++ hosts/pipebert/generate.sh | 9 + hosts/pipebert/hardware-configuration.nix | 37 ++++ hosts/pipebert/pipewire-pulse.conf.in.json | 16 ++ hosts/pipebert/pipewire-pulse.conf.json | 46 +++++ 6 files changed, 322 insertions(+) create mode 100644 hosts/pipebert/default.nix create mode 100755 hosts/pipebert/generate.sh create mode 100644 hosts/pipebert/hardware-configuration.nix create mode 100644 hosts/pipebert/pipewire-pulse.conf.in.json create mode 100644 hosts/pipebert/pipewire-pulse.conf.json diff --git a/host-registry.nix b/host-registry.nix index 2d417f5d..98f2d6bc 100644 --- a/host-registry.nix +++ b/host-registry.nix @@ -23,6 +23,7 @@ rec { builders = [ "ssh://client@172.22.99.110" ]; wol = true; }; + pipebert.ip4 = "172.22.99.207"; samba = { }; storage-ng.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMeg5ojU7U8+Lx824y+brazVJ007mEJDM7C7aUruOWGP"; diff --git a/hosts/pipebert/default.nix b/hosts/pipebert/default.nix new file mode 100644 index 00000000..c91c268c --- /dev/null +++ b/hosts/pipebert/default.nix @@ -0,0 +1,213 @@ +# 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, lib, pkgs, ... }: + +let + octoprintPort = 8080; +in { + imports = [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + + boot = { + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = false; + raspberryPi = { + enable = true; + version = 3; + uboot.enable = false; + }; + }; + #kernelPackages = pkgs.linuxPackages_rpi4; + kernelPackages = pkgs.linuxPackages_latest; + + tmpOnTmpfs = true; + }; + + c3d2 = { + isInHq = true; + mapHqHosts = true; + hq.interface = "eth0"; + }; + + nix = { + buildCores = 4; + maxJobs = 2; + }; + + networking = { + hostName = "pipebert"; # Define your hostname. + + # The global useDHCP flag is deprecated, therefore explicitly set to false here. + # Per-interface useDHCP will be mandatory in the future, so this generated config + # replicates the default behaviour. + useDHCP = false; + interfaces.eth0.useDHCP = true; + interfaces.wlan0.useDHCP = true; + firewall.enable = false; + }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + git + htop + libraspberrypi + mpd + mpv + ncmpcpp + ncpamixer + pulseaudio # required for pactl + vim + wget + ]; + + programs.tmux.enable = true; + + # Do not log to flash: + services.journald.extraConfig = '' + Storage=volatile + ''; + + # Enable the OpenSSH daemon. + services.openssh = { + enable = true; + permitRootLogin = "yes"; + }; + security.sudo = { + enable = true; + wheelNeedsPassword = false; + }; + + users.users.k-ot = { + isNormalUser = true; + extraGroups = [ "wheel" "audio" ]; + }; + + # Enable sound. + sound.enable = true; + hardware.bluetooth = { + enable = true; + settings = { + Policy.AutoEnable = true; + General = { + Enable = "Source,Sink,Media,Socket"; + #DiscoverableTimeout = 0; + #Discoverable = true; + }; + }; + }; + + services.pipewire = { + enable = true; + alsa.enable = true; + config.pipewire-pulse = lib.importJSON ./pipewire-pulse.conf.json; + pulse.enable = true; + }; + security.rtkit.enable = true; + + # tell Avahi to publish CUPS and PulseAudio + services.avahi = { + enable = true; + publish = { + enable = true; + addresses = true; + userServices = true; + }; + }; + + security.acme = { + acceptTerms = true; + email = "mail@c3d2.de"; + }; + + services.dhcpd4 = { + enable = true; + interfaces = [ config.c3d2.hq.interface ]; + authoritative = false; + # the leases are defined in the secrets module imported + # at the top-level of this flake + }; + + services.nginx = { + enable = true; + #recommendedGzipSettings = true; + recommendedProxySettings = true; + virtualHosts = { + "drkkr.hq.c3d2.de" = { + default = true; + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://127.0.0.1:${toString octoprintPort}"; + proxyWebsockets = true; + extraConfig = '' + proxy_set_header X-Scheme $scheme; + proxy_set_header Accept-Encoding identity; + client_max_body_size 2000M; + ''; + }; + locations."/cam/stream" = { + proxyPass = "http://localhost:3020/?action=stream"; + extraConfig = "proxy_pass_request_headers off;"; + }; + locations."/cam/capture" = { + proxyPass = "http://localhost:3020/?action=snapshot"; + extraConfig = "proxy_pass_request_headers off;"; + }; + }; + }; + }; + services.octoprint = rec { + enable = true; + port = octoprintPort; + extraConfig.webcam = { + snapshot = "http://localhost:3020?action=snapshot"; + stream = "https://drkkr.hq.c3d2.de/cam/stream"; + }; + # plugins = let + # python = pkgs.octoprint.python; + + # octoprint-filament-sensor-universal = python.pkgs.buildPythonPackage rec { + # pname = "OctoPrint-Filament-Sensor-Universal"; + # version = "1.0.0"; + + # src = pkgs.fetchFromGitHub { + # owner = "lopsided98"; + # repo = pname; + # rev = "8a72696867a9a008c5a79b49a9b029a4fc426720"; + # sha256 = "1a7lzmjbwx47qhrkjp3hggiwnx172x4axcz0labm9by17zxlsimr"; + # }; + + # propagatedBuildInputs = [ pkgs.octoprint python.pkgs.libgpiod ]; + # }; + # #in p: [ octoprint-filament-sensor-universal ]; + # in p: []; + }; + + # Allow access to printer serial port and GPIO + users.users.${config.services.octoprint.user}.extraGroups = [ "dialout" "gpio" ]; + + services.mjpg-streamer = { + enable = true; + inputPlugin = "input_uvc.so -d /dev/v4l/by-id/usb-046d_0817_4B7115A0-video-index0 -r 640x480 -f 30 -pl 50hz -ex auto"; + outputPlugin = "output_http.so -p 3020"; + }; + + # Allow gpio group to access GPIO devices + users.groups.gpio = { }; + services.udev.extraRules = '' + KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" + ''; + + # 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 = "21.05"; # Did you read the comment? +} diff --git a/hosts/pipebert/generate.sh b/hosts/pipebert/generate.sh new file mode 100755 index 00000000..4407ee35 --- /dev/null +++ b/hosts/pipebert/generate.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p jq + +# shellcheck shell=bash + +dir=$(dirname "$(readlink -f "$0")") +default_pipewire_pulse=$(nix-instantiate --eval -E '(import { }).pkgs.path')/nixos/modules/services/desktops/pipewire/pipewire-pulse.conf.json + +jq -s '.[0] * .[1] * .[2]' "$dir/pipewire-pulse.conf.in.json" "$default_pipewire_pulse" > "$dir/pipewire-pulse.conf.json" <(jq -cnS '{ "context.modules": [ inputs."context.modules" ] | add}' "$default_pipewire_pulse" "$dir/pipewire-pulse.conf.in.json") diff --git a/hosts/pipebert/hardware-configuration.nix b/hosts/pipebert/hardware-configuration.nix new file mode 100644 index 00000000..f6c0d84f --- /dev/null +++ b/hosts/pipebert/hardware-configuration.nix @@ -0,0 +1,37 @@ +# 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 = [ "usbhid" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + boot.kernelParams = [ "snd_bcm2835.enable_headphones=1" ]; + + fileSystems."/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-label/FIRMWARE"; + fsType = "vfat"; + }; + + swapDevices = [ ]; + + hardware.enableRedistributableFirmware = true; + #networking.wireless.enable = true; + boot.loader.raspberryPi.firmwareConfig = '' + gpu_mem=192 + dtparam=audio=on + ''; + + powerManagement.cpuFreqGovernor = lib.mkDefault "performance"; +} diff --git a/hosts/pipebert/pipewire-pulse.conf.in.json b/hosts/pipebert/pipewire-pulse.conf.in.json new file mode 100644 index 00000000..9ff61a85 --- /dev/null +++ b/hosts/pipebert/pipewire-pulse.conf.in.json @@ -0,0 +1,16 @@ +{ + "context.modules": [ + { + "name": "libpipewire-module-zeroconf-publish" + }, + { + "name": "libpipewire-module-protocol-pulse", + "args": { + "server.address": [ + "unix:native", + "tcp:4713" + ] + } + } + ] +} diff --git a/hosts/pipebert/pipewire-pulse.conf.json b/hosts/pipebert/pipewire-pulse.conf.json new file mode 100644 index 00000000..3e04a2c5 --- /dev/null +++ b/hosts/pipebert/pipewire-pulse.conf.json @@ -0,0 +1,46 @@ +{ + "context.modules": [ + { + "args": {}, + "flags": [ + "ifexists", + "nofail" + ], + "name": "libpipewire-module-rtkit" + }, + { + "name": "libpipewire-module-protocol-native" + }, + { + "name": "libpipewire-module-client-node" + }, + { + "name": "libpipewire-module-adapter" + }, + { + "name": "libpipewire-module-metadata" + }, + { + "args": { + "server.address": [ + "unix:native", + "tcp:4713" + ], + "vm.overrides": { + "pulse.min.quantum": "1024/48000" + } + }, + "name": "libpipewire-module-protocol-pulse" + }, + { + "name": "libpipewire-module-zeroconf-publish" + } + ], + "context.properties": {}, + "context.spa-libs": { + "audio.convert.*": "audioconvert/libspa-audioconvert", + "support.*": "support/libspa-support" + }, + "context.exec": [], + "stream.properties": {} +}