Simplify PWM and i2c loading using nixos-hardware
This commit is contained in:
parent
b418c9c892
commit
23395b8e6d
19
flake.nix
19
flake.nix
|
@ -3,24 +3,29 @@
|
|||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
agenix.url = "github:ryantm/agenix";
|
||||
agenix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
agenix = {
|
||||
url = "github:ryantm/agenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
nixos-hardware.url = "github:NixOS/nixos-hardware";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, agenix, ... }@inputs:
|
||||
outputs = { self, nixpkgs, agenix, nixos-hardware, ... }@inputs:
|
||||
let
|
||||
system = "aarch64-linux";
|
||||
|
||||
pkgs = import pkgs {
|
||||
inherit system;
|
||||
};
|
||||
pkgs = import pkgs { inherit system; };
|
||||
|
||||
lib = nixpkgs.lib;
|
||||
|
||||
in {
|
||||
nixosConfigurations.zion = lib.nixosSystem {
|
||||
inherit system;
|
||||
modules = [ (import ./configuration.nix) agenix.nixosModules.age ];
|
||||
modules = [
|
||||
(import ./configuration.nix)
|
||||
agenix.nixosModules.age
|
||||
nixos-hardware.nixosModules.raspberry-pi-4
|
||||
];
|
||||
specialArgs = { inherit inputs; };
|
||||
};
|
||||
|
||||
|
|
|
@ -15,37 +15,25 @@ with pkgs;
|
|||
];
|
||||
|
||||
# Enable SATA-HAT GPIO features
|
||||
boot.loader.grub.enable = false;
|
||||
boot.loader = {
|
||||
grub.enable = false;
|
||||
generic-extlinux-compatible.enable = lib.mkForce false;
|
||||
};
|
||||
boot.loader.raspberryPi = {
|
||||
enable = true;
|
||||
version = 4;
|
||||
firmwareConfig = ''
|
||||
iomem=relaxed
|
||||
strict-devmem=0
|
||||
dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
|
||||
dtoverlay=w1-gpio
|
||||
dtparam=i2c1=on
|
||||
'';
|
||||
};
|
||||
|
||||
# Load PWM hardware timers
|
||||
boot.kernelModules = [ "pwm_bcm2835" "w1-gpio" "w1-therm" ];
|
||||
hardware.deviceTree = {
|
||||
enable = true;
|
||||
filter = "*-rpi-*.dtb";
|
||||
overlays = [
|
||||
{
|
||||
name = "pwm-2chan";
|
||||
dtboFile = "${device-tree_rpi.overlays}/pwm-2chan.dtbo";
|
||||
}
|
||||
{
|
||||
name = "w1-gpio";
|
||||
dtboFile = "${device-tree_rpi.overlays}/w1-gpio.dtbo";
|
||||
}
|
||||
];
|
||||
};
|
||||
# Load PWM hardware timers
|
||||
hardware.raspberry-pi."4".pwm0.enable = true;
|
||||
|
||||
# Enable I2C
|
||||
hardware.i2c.enable = true;
|
||||
hardware.raspberry-pi."4".i2c1.enable = true;
|
||||
|
||||
}
|
||||
|
|
|
@ -30,23 +30,14 @@ in {
|
|||
};
|
||||
|
||||
# Enable SATA HAT
|
||||
systemd.services.sata-hat = let
|
||||
overlay-directory =
|
||||
"/boot/nixos/4mamyanz1hlc4wz3c427qjh6rabngwvj-linux-5.10.17-1.20210303-dtbs/overlays/";
|
||||
in {
|
||||
systemd.services.sata-hat = {
|
||||
description = "Enable software support for SATA Hat";
|
||||
wantedBy = [ "zfs-import.target" ];
|
||||
script = ''
|
||||
${pkgs.bash}/bin/bash -c "/etc/nixos/scripts/SATA-hat.sh on"
|
||||
'';
|
||||
preStart = ''
|
||||
${pkgs.libraspberrypi}/bin/dtoverlay -d ${overlay-directory} pwm-2chan pin=12 func=4 pin2=13 func2=4
|
||||
${pkgs.libraspberrypi}/bin/dtoverlay -d ${overlay-directory} w1-gpio
|
||||
${pkgs.bash}/bin/bash -c "/home/coolneng/system/scripts/SATA-hat.sh on"
|
||||
'';
|
||||
preStop = ''
|
||||
${pkgs.libraspberrypi}/bin/dtoverlay -r -d ${overlay-directory} pwm-2chan
|
||||
${pkgs.libraspberrypi}/bin/dtoverlay -r -d ${overlay-directory} w1-gpio
|
||||
${pkgs.bash}/bin/bash -c "/etc/nixos/scripts/SATA-hat.sh off"
|
||||
${pkgs.bash}/bin/bash -c "/home/coolneng/system/scripts/SATA-hat.sh off"
|
||||
'';
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
|
Loading…
Reference in New Issue