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 { nixosModule = lib.mkOption {
default = {...}: {}; default = {...}: {};
type = lib.types.anything; type = lib.types.anything;

View file

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

View file

@ -1,28 +1,26 @@
{ {
self, self,
pkgs, pkgs,
config,
lib, lib,
inputs, inputs,
machine, machine,
config,
... ...
}: { }: {
imports = imports = [
[ ./storage.nix
./storage.nix ./backups.nix
./backups.nix ./networking
./networking ./data-sharing.nix
./data-sharing.nix ./monitoring
./monitoring ./k3s
./k3s ./tailscale.nix
./tailscale.nix ./facter.nix
machine.nixosModule machine.nixosModule
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
inputs.nix-snapshotter.nixosModules.nix-snapshotter 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 = { config = {
time.timeZone = "Europe/Amsterdam"; time.timeZone = "Europe/Amsterdam";
@ -107,7 +105,7 @@
fastfetch fastfetch
]; ];
boot = lib.mkIf (! machine.isRaspberryPi) { boot = lib.mkIf (! config.facter.lab.isRaspberryPi) {
loader = { loader = {
systemd-boot.enable = lib.mkDefault true; systemd-boot.enable = lib.mkDefault true;
efi.canTouchEfiVariables = 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, lib,
config,
machine, machine,
... ...
}: { }: {
@ -16,7 +17,7 @@
enable = true; enable = true;
networks = lib.attrsets.mergeAttrsList [ networks = lib.attrsets.mergeAttrsList [
(lib.optionalAttrs (! machine.isRaspberryPi) { (lib.optionalAttrs (! config.facter.lab.isRaspberryPi) {
"30-main-nic" = { "30-main-nic" = {
matchConfig.Name = "en*"; matchConfig.Name = "en*";
@ -25,7 +26,7 @@
}; };
}; };
}) })
(lib.optionalAttrs machine.isRaspberryPi { (lib.optionalAttrs config.facter.lab.isRaspberryPi {
"30-main-nic" = { "30-main-nic" = {
matchConfig.Name = "end*"; matchConfig.Name = "end*";
networkConfig = { networkConfig = {