Implement raspberry pi check using nixos-facter

This commit is contained in:
Pim Kunis 2024-11-04 22:27:24 +01:00
parent 4d7e81fd63
commit 2a63bee83b
5 changed files with 46 additions and 32 deletions

View file

@ -25,11 +25,6 @@ flake-utils.lib.eachDefaultSystem (system: let
'';
};
isRaspberryPi = lib.mkOption {
default = false;
type = lib.types.bool;
};
nixosModule = lib.mkOption {
default = {...}: {};
type = lib.types.anything;

View file

@ -1,10 +1,13 @@
{
machines.warwick = {
arch = "aarch64-linux";
isRaspberryPi = true;
facterReportPath = ./facter.json;
nixosModule.lab = {
nixosModule = {inputs, ...}: {
imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
config = {
lab = {
storage.profile = "pi";
monitoring.server.enable = true;
@ -14,4 +17,6 @@
};
};
};
};
};
}

View file

@ -1,14 +1,13 @@
{
self,
pkgs,
config,
lib,
inputs,
machine,
config,
...
}: {
imports =
[
imports = [
./storage.nix
./backups.nix
./networking
@ -16,13 +15,12 @@
./monitoring
./k3s
./tailscale.nix
./facter.nix
machine.nixosModule
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.nix-snapshotter.nixosModules.nix-snapshotter
inputs.nixos-facter-modules.nixosModules.facter
]
++ lib.lists.optional (machine.isRaspberryPi) inputs.nixos-hardware.nixosModules.raspberry-pi-4;
];
config = {
time.timeZone = "Europe/Amsterdam";
@ -107,7 +105,7 @@
fastfetch
];
boot = lib.mkIf (! machine.isRaspberryPi) {
boot = lib.mkIf (! config.facter.lab.isRaspberryPi) {
loader = {
systemd-boot.enable = lib.mkDefault true;
efi.canTouchEfiVariables = true;

15
modules/facter.nix Normal file
View file

@ -0,0 +1,15 @@
{
inputs,
lib,
config,
...
}: {
imports = [inputs.nixos-facter-modules.nixosModules.facter];
options.facter.lab = {
isRaspberryPi = lib.mkOption {
type = lib.types.bool;
default = config.facter.report.system == "aarch64-linux";
};
};
}

View file

@ -1,5 +1,6 @@
{
lib,
config,
machine,
...
}: {
@ -16,7 +17,7 @@
enable = true;
networks = lib.attrsets.mergeAttrsList [
(lib.optionalAttrs (! machine.isRaspberryPi) {
(lib.optionalAttrs (! config.facter.lab.isRaspberryPi) {
"30-main-nic" = {
matchConfig.Name = "en*";
@ -25,7 +26,7 @@
};
};
})
(lib.optionalAttrs machine.isRaspberryPi {
(lib.optionalAttrs config.facter.lab.isRaspberryPi {
"30-main-nic" = {
matchConfig.Name = "end*";
networkConfig = {