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

View file

@ -1,28 +1,26 @@
{
self,
pkgs,
config,
lib,
inputs,
machine,
config,
...
}: {
imports =
[
./storage.nix
./backups.nix
./networking
./data-sharing.nix
./monitoring
./k3s
./tailscale.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;
imports = [
./storage.nix
./backups.nix
./networking
./data-sharing.nix
./monitoring
./k3s
./tailscale.nix
./facter.nix
machine.nixosModule
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.nix-snapshotter.nixosModules.nix-snapshotter
];
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 = {