Skip to content

Commit eb948c9

Browse files
authored
Merge pull request #39 from numtide/hardware-config
move all hardware detection to its own namespace
2 parents 33534a3 + fdf703e commit eb948c9

File tree

11 files changed

+78
-63
lines changed

11 files changed

+78
-63
lines changed

docs.nix

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,9 @@ pkgs.mkShellNoCC {
6565
cat ${optionsDoc.optionsCommonMark} > $out/${snakeCase name}.md
6666
'';
6767

68-
# Allows us to gather all options that are immediate children of `facter` and which have no child options.
69-
# e.g. facter.reportPath, facter.report.
70-
# For all other options we group them by the first immediate child of `facter`.
71-
# e.g. facter.bluetooth, facter.boot and so on.
72-
# This allows us to have a page for root facter options "facter.md", and a page each for the major sub modules.
73-
facterOptionsFilter =
74-
_:
75-
{
76-
loc ? [ ],
77-
options ? [ ],
78-
...
79-
}:
80-
(lib.length loc) == 2 && ((lib.elemAt loc 0) == "facter") && (lib.length options) == 0;
81-
82-
otherOptionsFilter = n: v: !(facterOptionsFilter n v);
83-
84-
facterMarkdown = mkMarkdown "facter" (lib.filterAttrs facterOptionsFilter eval.options.facter);
68+
facterMarkdown = mkMarkdown "facter" eval.options.facter.detected;
8569
otherMarkdown = lib.mapAttrsToList mkMarkdown (
86-
lib.filterAttrs otherOptionsFilter eval.options.facter
70+
lib.filterAttrs (n: v: n != "detected") eval.options.facter
8771
);
8872

8973
optionsMarkdown = pkgs.symlinkJoin {
@@ -92,7 +76,6 @@ pkgs.mkShellNoCC {
9276
};
9377

9478
in
95-
with pkgs;
9679
[
9780
(pkgs.writeScriptBin "mkdocs" ''
9881
# rsync in NixOS modules doc to avoid issues with symlinks being owned by root

modules/nixos/bluetooth.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{ lib, config, ... }:
22
{
3-
options.facter.bluetooth.enable = lib.mkEnableOption "Enable the Facter bluetooth module" // {
3+
options.facter.detected.bluetooth.enable = lib.mkEnableOption "Enable the Facter bluetooth module" // {
44
default = builtins.length (config.facter.report.hardware.bluetooth or []) > 0;
55
};
66

7-
config.hardware.bluetooth.enable = lib.mkIf config.facter.bluetooth.enable (lib.mkDefault true);
7+
config.hardware.bluetooth.enable = lib.mkIf config.facter.detected.bluetooth.enable (lib.mkDefault true);
88
}

modules/nixos/boot.nix

Lines changed: 0 additions & 28 deletions
This file was deleted.

modules/nixos/disk.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{ lib, config, ... }:
2+
let
3+
facterLib = import ../../lib/lib.nix lib;
4+
5+
inherit (config.facter) report;
6+
in
7+
{
8+
options.facter.detected.boot.disk.kernelModules = lib.mkOption {
9+
type = lib.types.listOf lib.types.str;
10+
default = facterLib.stringSet (
11+
facterLib.collectDrivers (
12+
# A disk might be attached.
13+
(report.hardware.firewire_controller or [ ])
14+
# definitely important
15+
++ (report.hardware.disk or [ ])
16+
++ (report.hardware.storage_controller or [ ])
17+
)
18+
);
19+
description = ''
20+
List of kernel modules that are needed to access the disk.
21+
'';
22+
};
23+
24+
config = {
25+
boot.initrd.availableKernelModules = config.facter.detected.boot.disk.kernelModules;
26+
};
27+
}

modules/nixos/facter.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ in
1111
{
1212
imports = [
1313
./bluetooth.nix
14-
./boot.nix
14+
./disk.nix
15+
./keyboard.nix
1516
./firmware.nix
1617
./graphics.nix
1718
./networking

modules/nixos/firmware.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let
33
facterLib = import ../../lib/lib.nix lib;
44

55
inherit (config.facter) report;
6-
isBaremetal = config.facter.virtualisation.none.enable;
6+
isBaremetal = config.facter.detected.virtualisation.none.enable;
77
hasAmdCpu = facterLib.hasAmdCpu report;
88
hasIntelCpu = facterLib.hasIntelCpu report;
99
in

modules/nixos/graphics.nix

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
{ lib, config, ... }:
22
let
33
facterLib = import ../../lib/lib.nix lib;
4+
cfg = config.facter.detected.graphics;
45
in
56
{
6-
options.facter.graphics.enable = lib.mkEnableOption "Enable the Graphics module" // {
7-
default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0;
7+
options.facter.detected = {
8+
graphics.enable = lib.mkEnableOption "Enable the Graphics module" // {
9+
default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0;
10+
};
11+
boot.graphics.kernelModules = lib.mkOption {
12+
type = lib.types.listOf lib.types.str;
13+
# We currently don't auto import nouveau, in case the user might want to use the proprietary nvidia driver,
14+
# We might want to change this in future, if we have a better idea, how to handle this.
15+
default = lib.remove "nouveau" (
16+
facterLib.stringSet (facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ]))
17+
);
18+
description = ''
19+
List of kernel modules to load at boot for the graphics card.
20+
'';
21+
};
822
};
923

10-
config = lib.mkIf config.facter.graphics.enable {
24+
config = lib.mkIf cfg.enable {
1125
hardware.graphics.enable = lib.mkDefault true;
12-
boot.initrd.kernelModules = facterLib.stringSet (
13-
facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ])
14-
);
26+
boot.initrd.kernelModules = config.facter.detected.boot.graphics.kernelModules;
1527
};
1628
}

modules/nixos/keyboard.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ lib, config, ... }:
2+
let
3+
facterLib = import ../../lib/lib.nix lib;
4+
5+
inherit (config.facter) report;
6+
in
7+
{
8+
options.facter.detected.boot.keyboard.kernelModules = lib.mkOption {
9+
type = lib.types.listOf lib.types.str;
10+
default = facterLib.collectDrivers (report.hardware.usb_controller or [ ]);
11+
example = [ "usbhid" ];
12+
description = ''
13+
List of kernel modules to include in the initrd to support the keyboard.
14+
'';
15+
};
16+
17+
config = {
18+
boot.initrd.availableKernelModules = config.facter.detected.boot.keyboard.kernelModules;
19+
};
20+
}

modules/nixos/networking/broadcom.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{ lib, config, ... }:
22
let
33
inherit (config.facter) report;
4-
cfg = config.facter.networking.broadcom;
4+
cfg = config.facter.detected.networking.broadcom;
55
in
66
{
7-
options.facter.networking.broadcom = with lib; {
7+
options.facter.detected.networking.broadcom = with lib; {
88
full_mac.enable = mkEnableOption "Enable the Facter Broadcom Full MAC module" // {
99

1010
default = lib.any (

modules/nixos/networking/intel.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{ lib, config, ... }:
22
let
33
inherit (config.facter) report;
4-
cfg = config.facter.networking.intel;
4+
cfg = config.facter.detected.networking.intel;
55
in
66
{
7-
options.facter.networking.intel = with lib; {
7+
options.facter.detected.networking.intel = with lib; {
88
_2200BG.enable = mkEnableOption "Enable the Facter Intel 2200BG module" // {
99

1010
default = lib.any (

modules/nixos/virtualisation.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
}:
77
let
88
inherit (config.facter) report;
9-
cfg = config.facter.virtualisation;
9+
cfg = config.facter.detected.virtualisation;
1010
in
1111
{
12-
options.facter.virtualisation = {
12+
options.facter.detected.virtualisation = {
1313
virtio_scsi.enable = lib.mkEnableOption "Enable the Facter Virtualisation Virtio SCSI module" // {
1414
default = lib.any (
1515
{ vendor, device, ... }:

0 commit comments

Comments
 (0)