From 00002b462a9dee91802510fb74bb63bd3c8f8150 Mon Sep 17 00:00:00 2001 From: Tom Charnock Date: Sun, 8 Dec 2024 21:29:41 +0100 Subject: [PATCH] Making nixosModules work as a flake --- cm4/default.nix | 37 --------------------------- cm4/dtb-audremap.nix | 51 -------------------------------------- cm4/dtb-gpio40-45.nix | 55 ----------------------------------------- deskpi/default.nix | 44 --------------------------------- deskpi/deskpi-tools.nix | 43 -------------------------------- deskpi/trim.nix | 17 ------------- flake.nix | 4 ++- 7 files changed, 3 insertions(+), 248 deletions(-) delete mode 100644 cm4/default.nix delete mode 100644 cm4/dtb-audremap.nix delete mode 100644 cm4/dtb-gpio40-45.nix delete mode 100644 deskpi/default.nix delete mode 100644 deskpi/deskpi-tools.nix delete mode 100644 deskpi/trim.nix diff --git a/cm4/default.nix b/cm4/default.nix deleted file mode 100644 index d77fff3..0000000 --- a/cm4/default.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ - config, - lib, - fn, - nixos-hardware, - ... -}: let - inherit (lib) mkIf mkEnableOption mkOption types; - cfg = config.hardware.cm4; -in { - options.hardware.cm4 = { - enable = mkEnableOption "custom CM4"; - }; - - imports = [nixos-hardware.nixosModules.raspberry-pi-4] ++ (fn.scanPaths ./.); - - config = mkIf cfg.enable { - hardware.raspberry-pi."4" = { - apply-overlays-dtmerge.enable = true; - xhci.enable = true; - overlays = { - audremap.enable = true; - spi-gpio40-45.enable = true; - }; - }; - - hardware.deviceTree = { - enable = true; - filter = "*-rpi-cm4.dtb"; - }; - - users.groups.spi = {}; - services.udev.extraRules = '' - SUBSYSTEM=="spidev", KERNEL=="spidev0.0", GROUP="spi", MODE="0660" - ''; - }; -} diff --git a/cm4/dtb-audremap.nix b/cm4/dtb-audremap.nix deleted file mode 100644 index 641a7cd..0000000 --- a/cm4/dtb-audremap.nix +++ /dev/null @@ -1,51 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkIf mkMerge; - cfg = config.hardware.raspberry-pi."4".overlays; -in { - options.hardware = { - raspberry-pi."4".overlays.audremap.enable = mkEnableOption ''audremap enable ''; - }; - - config = mkMerge [ - (mkIf cfg.audremap.enable { - hardware.deviceTree.overlays = [ - { - name = "audremap.overlay"; - filter = "*rpi-cm4*"; - dtsText = '' - /dts-v1/; - /plugin/; - / { - compatible = "brcm,bcm2711"; - fragment@0 { - target = <&audio_pins>; - frag0: __overlay__ { - brcm,pins = <12 13>; - brcm,function = <4>; /* alt0 alt0 */ - }; - }; - fragment@1 { - target = <&chosen>; - __overlay__ { - bootargs = "snd_bcm2835.enable_headphones=1"; - }; - }; - __overrides__ { - swap_lr = <&frag0>, "swap_lr?"; - enable_jack = <&frag0>, "enable_jack?"; - pins_12_13 = <&frag0>,"brcm,pins:0=12", <&frag0>,"brcm,pins:4=13", <&frag0>,"brcm,function:0=4"; - pins_18_19 = <&frag0>,"brcm,pins:0=18", <&frag0>,"brcm,pins:4=19", <&frag0>,"brcm,function:0=2"; - pins_40_41 = <&frag0>,"brcm,pins:0=40", <&frag0>,"brcm,pins:4=41", <&frag0>,"brcm,function:0=4"; - pins_40_45 = <&frag0>,"brcm,pins:0=40", <&frag0>,"brcm,pins:4=45", <&frag0>,"brcm,function:0=4"; - }; - }; - ''; - } - ]; - }) - ]; -} diff --git a/cm4/dtb-gpio40-45.nix b/cm4/dtb-gpio40-45.nix deleted file mode 100644 index c30a0c4..0000000 --- a/cm4/dtb-gpio40-45.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkIf mkMerge; - cfg = config.hardware.raspberry-pi."4".overlays; -in { - options.hardware = { - raspberry-pi."4".overlays.spi-gpio40-45.enable = mkEnableOption ''spi-gpio40-45 enable ''; - }; - - config = mkMerge [ - (mkIf cfg.spi-gpio40-45.enable { - hardware.deviceTree = { - overlays = [ - { - name = "spi-gpio40-45.overlay"; - filter = "*rpi-cm4*"; - dtsText = '' - /dts-v1/; - /plugin/; - / { - compatible = "brcm,bcm2711"; - fragment@0 { - target = <&spi0>; - __overlay__ { - cs-gpios = <&gpio 43 1>, <&gpio 44 1>, <&gpio 45 1>; - status = "okay"; - }; - }; - fragment@1 { - target = <&spi0_cs_pins>; - __overlay__ { - brcm,pins = <45 44 43>; - brcm,function = <1>; /* output */ - status = "okay"; - }; - }; - fragment@2 { - target = <&spi0_pins>; - __overlay__ { - brcm,pins = <40 41 42>; - brcm,function = <3>; /* alt4 */ - status = "okay"; - }; - }; - }; - ''; - } - ]; - }; - }) - ]; -} diff --git a/deskpi/default.nix b/deskpi/default.nix deleted file mode 100644 index d5f4472..0000000 --- a/deskpi/default.nix +++ /dev/null @@ -1,44 +0,0 @@ -{ - nixos-hardware, - lib, - config, - ... -}: let - inherit (lib) mkEnableOption mkOption types mkDefault; - cfg = config.hardware.deskpi; -in { - options.hardware.deskpi = { - enable = mkEnableOption "enable DeskPi Pro daemons"; - device = mkOption { - type = types.str; - default = "/dev/deskPi"; - }; - }; - - imports = - [nixos-hardware.nixosModules.raspberry-pi-4] - ++ [../raspberry-pi/overlays] - ++ [../raspberry-pi/apply-overlays] - ++ [./deskpi-tools.nix] - ++ [./trim.nix]; - - config = { - hardware.raspberry-pi."4" = { - xhci.enable = mkDefault false; - dwc2.enable = mkDefault true; - dwc2.dr_mode = mkDefault "host"; - overlays = { - rpi4-disable-pwrled.enable = mkDefault true; - }; - }; - - hardware.deviceTree = { - enable = true; - filter = "bcm2711-rpi-4-b.dtb"; - }; - - services.udev.extraRules = '' - ACTION=="add", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SUBSYSTEM=="tty", SYMLINK+="${builtins.baseNameOf cfg.device}" - ''; - }; -} diff --git a/deskpi/deskpi-tools.nix b/deskpi/deskpi-tools.nix deleted file mode 100644 index 0384428..0000000 --- a/deskpi/deskpi-tools.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ - config, - pkgs, - ... -}: let - deskpi-tools = pkgs.callPackage ../raspberry-pi/packages/deskpi-tools {}; - cfg = config.hardware.deskpi; -in { - systemd.packages = [deskpi-tools]; - - systemd.services."deskpi-safe-shut" = { - description = "DeskPi Safe-Shutdown Service"; - after = ["shutdown.target"]; - before = ["final.target"]; - wantedBy = ["shutdown.target"]; - conflicts = ["reboot.target"]; - unitConfig = { - ConditionPathExists = cfg.device; - DefaultDependencies = "no"; - }; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${deskpi-tools}/bin/safeCutOffPower"; - RemainAfterExit = "yes"; - TimeoutSec = "infinity"; - StandardOutput = "tty"; - }; - }; - - systemd.services."deskpi" = { - description = "DeskPi PWM Control Fan Service"; - after = ["multi-user.target"]; - wantedBy = ["multi-user.target"]; - unitConfig = { - ConditionPathExists = cfg.device; - }; - serviceConfig = { - Type = "simple"; - ExecStart = "${deskpi-tools}/bin/pwmFanControl"; - RemainAfterExit = "no"; - }; - }; -} diff --git a/deskpi/trim.nix b/deskpi/trim.nix deleted file mode 100644 index e44372f..0000000 --- a/deskpi/trim.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkIf mkEnableOption types; - cfg = config.hardware.deskpi.trim; -in { - options.hardware.deskpi.trim = { - enable = mkEnableOption "enable uas fstrim support"; - }; - config = mkIf cfg.enable { - services.udev.extraRules = '' - ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap" - ''; - }; -} diff --git a/flake.nix b/flake.nix index 712ca7a..e4afdba 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,9 @@ in { nixosModules = { uconsole = import ./uconsole {inherit pkgs nixos-hardware;}; - deskpi = import ./deskpi {inherit pkgs nixos-hardware;}; + uconsole-kernel = import ./uconsole/kernel {inherit pkgs}; + raspberry-pi-overlays = import ./raspberry-pi/overlays; + raspberry-pi-apply-overlays = import ./raspberry-pi/apply-overlays; }; }; }