Skip to content

Commit 48cadff

Browse files
committed
allow facter report to be empty.
This makes our code also more robust, if things in the report are not present.
1 parent de2dba4 commit 48cadff

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

flake.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@
6262
checks = eachSystem (
6363
{ pkgs, ... }:
6464
{
65+
minimal-machine =
66+
(pkgs.nixos [
67+
publicInputs.self.nixosModules.facter
68+
(
69+
{ lib, config, ... }:
70+
{
71+
boot.loader.grub.devices = lib.mkForce [ "/dev/sda" ];
72+
fileSystems."/".device = lib.mkDefault "/dev/sda";
73+
users.users.root.initialPassword = "fnord23";
74+
system.stateVersion = config.system.nixos.version;
75+
nixpkgs.pkgs = pkgs;
76+
}
77+
)
78+
]).config.system.build.toplevel;
6579
lib-tests = pkgs.runCommandLocal "lib-tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
6680
export HOME="$(realpath .)"
6781
export NIX_CONFIG='

modules/nixos/facter.nix

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
22
lib,
33
config,
4-
options,
54
...
65
}:
7-
let
8-
cfg = config.facter;
9-
modulePath = lib.concatStringsSep "/" (lib.take 4 (lib.splitString [ "/" ] __curPos.file));
10-
in
116
{
127
imports = [
138
./bluetooth.nix
@@ -23,12 +18,13 @@ in
2318
options.facter = with lib; {
2419
report = mkOption {
2520
type = types.raw;
26-
default = builtins.fromJSON (builtins.readFile config.facter.reportPath);
21+
default = if config.facter.reportPath == null then {} else builtins.fromJSON (builtins.readFile config.facter.reportPath);
2722
description = "An import for the reportPath.";
2823
};
2924

3025
reportPath = mkOption {
31-
type = types.path;
26+
type = types.nullOr types.path;
27+
default = null;
3228
description = "Path to a report generated by nixos-facter.";
3329
};
3430

modules/nixos/virtualisation.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ in
2525
defaultText = "hardware dependent";
2626
};
2727
oracle.enable = lib.mkEnableOption "Enable the Facter Virtualisation Oracle module" // {
28-
default = report.virtualisation == "oracle";
28+
default = report.virtualisation or null == "oracle";
2929
defaultText = "environment dependent";
3030
};
3131
parallels.enable = lib.mkEnableOption "Enable the Facter Virtualisation Parallels module" // {
32-
default = report.virtualisation == "parallels";
32+
default = report.virtualisation or null == "parallels";
3333
defaultText = "environment dependent";
3434
};
3535
qemu.enable = lib.mkEnableOption "Enable the Facter Virtualisation Qemu module" // {
36-
default = builtins.elem report.virtualisation [
36+
default = builtins.elem (report.virtualisation or null) [
3737
"qemu"
3838
"kvm"
3939
"bochs"
4040
];
4141
defaultText = "environment dependent";
4242
};
4343
hyperv.enable = lib.mkEnableOption "Enable the Facter Virtualisation Hyper-V module" // {
44-
default = report.virtualisation == "microsoft";
44+
default = report.virtualisation or null == "microsoft";
4545
defaultText = "environment dependent";
4646
};
4747
# no virtualisation detected
4848
none.enable = lib.mkEnableOption "Enable the Facter Virtualisation None module" // {
49-
default = report.virtualisation == "none";
49+
default = report.virtualisation or null == "none";
5050
defaultText = "environment dependent";
5151
};
5252
};

0 commit comments

Comments
 (0)