From 14428dabcdd4df37687c4bd9584d856d6fa5b187 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 14 Oct 2021 16:11:56 +0200 Subject: [PATCH] radiobert: split into multiple files --- hosts/radiobert/base.nix | 114 +++++++++++++++++++++ hosts/radiobert/default.nix | 186 +---------------------------------- hosts/radiobert/dump1090.nix | 51 ++++++++++ hosts/radiobert/soapysdr.nix | 24 +++++ 4 files changed, 193 insertions(+), 182 deletions(-) create mode 100644 hosts/radiobert/base.nix create mode 100644 hosts/radiobert/dump1090.nix create mode 100644 hosts/radiobert/soapysdr.nix diff --git a/hosts/radiobert/base.nix b/hosts/radiobert/base.nix new file mode 100644 index 00000000..caf01133 --- /dev/null +++ b/hosts/radiobert/base.nix @@ -0,0 +1,114 @@ +{ hostRegistry, config, lib, pkgs, ... }: + +{ + boot.initrd.availableKernelModules = [ "usbhid" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + + fileSystems."/boot/firmware" = { + device = "/dev/disk/by-label/FIRMWARE"; + fsType = "vfat"; + }; + + swapDevices = [ ]; + + hardware.enableRedistributableFirmware = true; + #networking.wireless.enable = true; + hardware.deviceTree.enable = false; + powerManagement.cpuFreqGovernor = lib.mkDefault "performance"; + + boot = { + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = lib.mkDefault true; + raspberryPi = { + enable = true; + version = 4; + uboot.enable = true; + firmwareConfig = '' + gpu_mem=192 + dtparam=audio=on + ''; + }; + }; + kernelPackages = pkgs.linuxPackages_latest; + # Don't build ZFS for aarch64 (broken?) + supportedFilesystems = lib.mkForce [ "vfat" "ext4" ]; + + tmpOnTmpfs = true; + }; + sdImage = { + compressImage = false; + imageBaseName = config.networking.hostName; + firmwareSize = 512; + }; + + c3d2 = { + isInHq = false; + hq.statistics.enable = true; + pi-sensors = [ { + type = "dht22"; + pin = 17; + location = "Schrank"; + } { + type = "dht22"; + pin = 23; + location = "Aussen"; + } ]; + }; + + nix = { + buildCores = 4; + maxJobs = 2; + }; + + networking = { + hostName = "radiobert"; # Define your hostname. + useDHCP = false; + interfaces.eth0.ipv4.addresses = [{ + address = hostRegistry.hosts.${config.networking.hostName}.ip4; + prefixLength = 26; + }]; + defaultGateway = "172.20.73.1"; + firewall.enable = false; + nameservers = [ "172.20.73.8" "9.9.9.9" ]; + }; + + environment.systemPackages = with pkgs; [ + libraspberrypi + raspberrypi-eeprom + vim + wget + ]; + + programs.tmux.enable = true; + + # Do not log to flash: + services.journald.extraConfig = '' + Storage=volatile + ''; + + # Enable the OpenSSH daemon. + services.openssh = { + enable = true; + }; + + # Allow access to USB + services.udev.extraRules = '' + SUBSYSTEM=="usb", MODE:="0666" + ''; + + # 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/radiobert/default.nix b/hosts/radiobert/default.nix index 20406f60..af6626e3 100644 --- a/hosts/radiobert/default.nix +++ b/hosts/radiobert/default.nix @@ -1,185 +1,7 @@ -{ hostRegistry, config, lib, pkgs, modulesPath, ... }: - -let - # soapysdr = with pkgs; soapysdr.override { - # extraPackages = [ - # soapyhackrf - # ]; - # }; - soapysdr = pkgs.soapysdr-with-plugins; -in { - boot.initrd.availableKernelModules = [ "usbhid" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ ]; - boot.extraModulePackages = [ ]; - boot.blacklistedKernelModules = [ - # no watching TV intended - "dvb_usb_rtl28xxu" + imports = [ + ./base.nix + ./soapysdr.nix + ./dump1090.nix ]; - - fileSystems."/" = { - device = "/dev/disk/by-label/NIXOS_SD"; - fsType = "ext4"; - }; - - fileSystems."/boot/firmware" = { - device = "/dev/disk/by-label/FIRMWARE"; - fsType = "vfat"; - }; - - swapDevices = [ ]; - - hardware.enableRedistributableFirmware = true; - #networking.wireless.enable = true; - hardware.deviceTree.enable = false; - powerManagement.cpuFreqGovernor = lib.mkDefault "performance"; - - boot = { - loader = { - grub.enable = false; - generic-extlinux-compatible.enable = lib.mkDefault true; - raspberryPi = { - enable = true; - version = 4; - uboot.enable = true; - firmwareConfig = '' - gpu_mem=192 - dtparam=audio=on - ''; - }; - }; - kernelPackages = pkgs.linuxPackages_latest; - # Don't build ZFS for aarch64 (broken?) - supportedFilesystems = lib.mkForce [ "vfat" "ext4" ]; - - tmpOnTmpfs = true; - }; - sdImage = { - compressImage = false; - imageBaseName = config.networking.hostName; - firmwareSize = 512; - }; - - c3d2 = { - isInHq = false; - hq.statistics.enable = true; - pi-sensors = [ { - type = "dht22"; - pin = 17; - location = "Schrank"; - } { - type = "dht22"; - pin = 23; - location = "Aussen"; - } ]; - }; - - nix = { - buildCores = 4; - maxJobs = 2; - }; - - networking = { - hostName = "radiobert"; # Define your hostname. - useDHCP = false; - interfaces.eth0.ipv4.addresses = [{ - address = hostRegistry.hosts.${config.networking.hostName}.ip4; - prefixLength = 26; - }]; - defaultGateway = "172.20.73.1"; - firewall.enable = false; - nameservers = [ "172.20.73.8" "9.9.9.9" ]; - }; - - users.users.soapysdr = { - isSystemUser = true; - group = "soapysdr"; - }; - users.groups.soapysdr = {}; - systemd.services.soapysdr-server = { - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStart = "${soapysdr}/bin/SoapySDRServer --bind"; - User = "soapysdr"; - Group = "soapysdr"; - ProtectSystem = "full"; - ProtectHome = true; - }; - }; - - users.users.dump1090 = { - isSystemUser = true; - group = "dump10190"; - }; - users.groups.dump1090 = {}; - systemd.tmpfiles.rules = [ - "d /tmp/dump1090 0755 dump1090 dump1090 -" - ]; - systemd.services.dump1090 = { - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStart = "${pkgs.dump1090_sdrplus}/bin/dump1090 --aggressive --net"; - User = "dump1090"; - Group = "dump1090"; - ProtectSystem = "full"; - ProtectHome = true; - WorkingDirectory = "/tmp/dump1090"; - WritablePaths = "/tmp/dump1090"; - }; - }; - - - # TODO: `services.collectd.plugins.exec` is already defined by pi-sensors - # (https://github.com/NixOS/nixpkgs/pull/141551) - services.collectd.extraConfig = - let - distanceRb = pkgs.fetchurl { - url = "https://github.com/djberg96/gis-distance/raw/main/lib/gis/distance.rb"; - sha256 = "1m9zzikcl5pzad66r8vnlj2p2hbbcqb8vdcf34nrhyd4mg1wkgkh"; - }; - libDir = pkgs.runCommandNoCC "libdir" {} '' - mkdir $out - cp ${distanceRb} $out/distance.rb - ''; - in '' - - Exec "${config.services.collectd.user}" "${pkgs.ruby}/bin/ruby" "-I${libDir}" "${./collectd-adsb.rb}" - - ''; - - environment.systemPackages = with pkgs; [ - libraspberrypi - raspberrypi-eeprom - vim - wget - dump1090_sdrplus - soapysdr-with-plugins - hackrf - ]; - - programs.tmux.enable = true; - - # Do not log to flash: - services.journald.extraConfig = '' - Storage=volatile - ''; - - # Enable the OpenSSH daemon. - services.openssh = { - enable = true; - }; - - # Allow access to USB - services.udev.extraRules = '' - SUBSYSTEM=="usb", MODE:="0666" - ''; - - # 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/radiobert/dump1090.nix b/hosts/radiobert/dump1090.nix new file mode 100644 index 00000000..3bf5edb9 --- /dev/null +++ b/hosts/radiobert/dump1090.nix @@ -0,0 +1,51 @@ +{ config, pkgs, ... }: + +{ + boot.blacklistedKernelModules = [ + # no watching TV intended + "dvb_usb_rtl28xxu" + ]; + users.users.dump1090 = { + isSystemUser = true; + group = "dump10190"; + }; + users.groups.dump1090 = {}; + systemd.tmpfiles.rules = [ + "d /tmp/dump1090 0755 dump1090 dump1090 -" + ]; + systemd.services.dump1090 = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${pkgs.dump1090_sdrplus}/bin/dump1090 --aggressive --net"; + User = "dump1090"; + Group = "dump1090"; + ProtectSystem = "full"; + ProtectHome = true; + WorkingDirectory = "/tmp/dump1090"; + WritablePaths = "/tmp/dump1090"; + }; + }; + + + # TODO: `services.collectd.plugins.exec` is already defined by pi-sensors + # (https://github.com/NixOS/nixpkgs/pull/141551) + services.collectd.extraConfig = + let + distanceRb = pkgs.fetchurl { + url = "https://github.com/djberg96/gis-distance/raw/main/lib/gis/distance.rb"; + sha256 = "1m9zzikcl5pzad66r8vnlj2p2hbbcqb8vdcf34nrhyd4mg1wkgkh"; + }; + libDir = pkgs.runCommandNoCC "libdir" {} '' + mkdir $out + cp ${distanceRb} $out/distance.rb + ''; + in '' + + Exec "${config.services.collectd.user}" "${pkgs.ruby}/bin/ruby" "-I${libDir}" "${./collectd-adsb.rb}" + + ''; + + environment.systemPackages = with pkgs; [ + dump1090_sdrplus + ]; +} diff --git a/hosts/radiobert/soapysdr.nix b/hosts/radiobert/soapysdr.nix new file mode 100644 index 00000000..727edc40 --- /dev/null +++ b/hosts/radiobert/soapysdr.nix @@ -0,0 +1,24 @@ +{ pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + soapysdr-with-plugins + hackrf + ]; + + users.users.soapysdr = { + isSystemUser = true; + group = "soapysdr"; + }; + users.groups.soapysdr = {}; + systemd.services.soapysdr-server = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${pkgs.soapysdr-with-plugins}/bin/SoapySDRServer --bind"; + User = "soapysdr"; + Group = "soapysdr"; + ProtectSystem = "full"; + ProtectHome = true; + }; + }; +}