Skip to content

Commit

Permalink
Merge pull request #39 from numtide/hardware-config
Browse files Browse the repository at this point in the history
move all hardware detection to its own namespace
  • Loading branch information
Mic92 authored Sep 25, 2024
2 parents 33534a3 + fdf703e commit eb948c9
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 63 deletions.
21 changes: 2 additions & 19 deletions docs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,9 @@ pkgs.mkShellNoCC {
cat ${optionsDoc.optionsCommonMark} > $out/${snakeCase name}.md
'';

# Allows us to gather all options that are immediate children of `facter` and which have no child options.
# e.g. facter.reportPath, facter.report.
# For all other options we group them by the first immediate child of `facter`.
# e.g. facter.bluetooth, facter.boot and so on.
# This allows us to have a page for root facter options "facter.md", and a page each for the major sub modules.
facterOptionsFilter =
_:
{
loc ? [ ],
options ? [ ],
...
}:
(lib.length loc) == 2 && ((lib.elemAt loc 0) == "facter") && (lib.length options) == 0;

otherOptionsFilter = n: v: !(facterOptionsFilter n v);

facterMarkdown = mkMarkdown "facter" (lib.filterAttrs facterOptionsFilter eval.options.facter);
facterMarkdown = mkMarkdown "facter" eval.options.facter.detected;
otherMarkdown = lib.mapAttrsToList mkMarkdown (
lib.filterAttrs otherOptionsFilter eval.options.facter
lib.filterAttrs (n: v: n != "detected") eval.options.facter
);

optionsMarkdown = pkgs.symlinkJoin {
Expand All @@ -92,7 +76,6 @@ pkgs.mkShellNoCC {
};

in
with pkgs;
[
(pkgs.writeScriptBin "mkdocs" ''
# rsync in NixOS modules doc to avoid issues with symlinks being owned by root
Expand Down
4 changes: 2 additions & 2 deletions modules/nixos/bluetooth.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib, config, ... }:
{
options.facter.bluetooth.enable = lib.mkEnableOption "Enable the Facter bluetooth module" // {
options.facter.detected.bluetooth.enable = lib.mkEnableOption "Enable the Facter bluetooth module" // {
default = builtins.length (config.facter.report.hardware.bluetooth or []) > 0;
};

config.hardware.bluetooth.enable = lib.mkIf config.facter.bluetooth.enable (lib.mkDefault true);
config.hardware.bluetooth.enable = lib.mkIf config.facter.detected.bluetooth.enable (lib.mkDefault true);
}
28 changes: 0 additions & 28 deletions modules/nixos/boot.nix

This file was deleted.

27 changes: 27 additions & 0 deletions modules/nixos/disk.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ lib, config, ... }:
let
facterLib = import ../../lib/lib.nix lib;

inherit (config.facter) report;
in
{
options.facter.detected.boot.disk.kernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = facterLib.stringSet (
facterLib.collectDrivers (
# A disk might be attached.
(report.hardware.firewire_controller or [ ])
# definitely important
++ (report.hardware.disk or [ ])
++ (report.hardware.storage_controller or [ ])
)
);
description = ''
List of kernel modules that are needed to access the disk.
'';
};

config = {
boot.initrd.availableKernelModules = config.facter.detected.boot.disk.kernelModules;
};
}
3 changes: 2 additions & 1 deletion modules/nixos/facter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ in
{
imports = [
./bluetooth.nix
./boot.nix
./disk.nix
./keyboard.nix
./firmware.nix
./graphics.nix
./networking
Expand Down
2 changes: 1 addition & 1 deletion modules/nixos/firmware.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let
facterLib = import ../../lib/lib.nix lib;

inherit (config.facter) report;
isBaremetal = config.facter.virtualisation.none.enable;
isBaremetal = config.facter.detected.virtualisation.none.enable;
hasAmdCpu = facterLib.hasAmdCpu report;
hasIntelCpu = facterLib.hasIntelCpu report;
in
Expand Down
24 changes: 18 additions & 6 deletions modules/nixos/graphics.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{ lib, config, ... }:
let
facterLib = import ../../lib/lib.nix lib;
cfg = config.facter.detected.graphics;
in
{
options.facter.graphics.enable = lib.mkEnableOption "Enable the Graphics module" // {
default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0;
options.facter.detected = {
graphics.enable = lib.mkEnableOption "Enable the Graphics module" // {
default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0;
};
boot.graphics.kernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
# We currently don't auto import nouveau, in case the user might want to use the proprietary nvidia driver,
# We might want to change this in future, if we have a better idea, how to handle this.
default = lib.remove "nouveau" (
facterLib.stringSet (facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ]))
);
description = ''
List of kernel modules to load at boot for the graphics card.
'';
};
};

config = lib.mkIf config.facter.graphics.enable {
config = lib.mkIf cfg.enable {
hardware.graphics.enable = lib.mkDefault true;
boot.initrd.kernelModules = facterLib.stringSet (
facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ])
);
boot.initrd.kernelModules = config.facter.detected.boot.graphics.kernelModules;
};
}
20 changes: 20 additions & 0 deletions modules/nixos/keyboard.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib, config, ... }:
let
facterLib = import ../../lib/lib.nix lib;

inherit (config.facter) report;
in
{
options.facter.detected.boot.keyboard.kernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = facterLib.collectDrivers (report.hardware.usb_controller or [ ]);
example = [ "usbhid" ];
description = ''
List of kernel modules to include in the initrd to support the keyboard.
'';
};

config = {
boot.initrd.availableKernelModules = config.facter.detected.boot.keyboard.kernelModules;
};
}
4 changes: 2 additions & 2 deletions modules/nixos/networking/broadcom.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ lib, config, ... }:
let
inherit (config.facter) report;
cfg = config.facter.networking.broadcom;
cfg = config.facter.detected.networking.broadcom;
in
{
options.facter.networking.broadcom = with lib; {
options.facter.detected.networking.broadcom = with lib; {
full_mac.enable = mkEnableOption "Enable the Facter Broadcom Full MAC module" // {

default = lib.any (
Expand Down
4 changes: 2 additions & 2 deletions modules/nixos/networking/intel.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ lib, config, ... }:
let
inherit (config.facter) report;
cfg = config.facter.networking.intel;
cfg = config.facter.detected.networking.intel;
in
{
options.facter.networking.intel = with lib; {
options.facter.detected.networking.intel = with lib; {
_2200BG.enable = mkEnableOption "Enable the Facter Intel 2200BG module" // {

default = lib.any (
Expand Down
4 changes: 2 additions & 2 deletions modules/nixos/virtualisation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
}:
let
inherit (config.facter) report;
cfg = config.facter.virtualisation;
cfg = config.facter.detected.virtualisation;
in
{
options.facter.virtualisation = {
options.facter.detected.virtualisation = {
virtio_scsi.enable = lib.mkEnableOption "Enable the Facter Virtualisation Virtio SCSI module" // {
default = lib.any (
{ vendor, device, ... }:
Expand Down

0 comments on commit eb948c9

Please sign in to comment.