Skip to content

Commit 9614462

Browse files
authored
Merge pull request #42 from numtide/testing
Do basic evaluation tests
2 parents 0bea32e + f8bd05e commit 9614462

File tree

3 files changed

+23
-96
lines changed

3 files changed

+23
-96
lines changed

flake.nix

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,7 @@
4343
flake = publicInputs.self;
4444
}).value;
4545
};
46-
nixosModules = {
47-
boot = ./modules/nixos/boot.nix;
48-
facter = ./modules/nixos/facter.nix;
49-
firmware = ./modules/nixos/firmware.nix;
50-
networking = ./modules/nixos/networking;
51-
system = ./modules/nixos/system.nix;
52-
virtualisation = ./modules/nixos/virtualisation.nix;
53-
};
46+
nixosModules.facter = ./modules/nixos/facter.nix;
5447
}
5548
//
5649
# DevOutputs
@@ -69,6 +62,20 @@
6962
checks = eachSystem (
7063
{ pkgs, ... }:
7164
{
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;
7279
lib-tests = pkgs.runCommandLocal "lib-tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
7380
export HOME="$(realpath .)"
7481
export NIX_CONFIG='

modules/nixos/facter.nix

Lines changed: 3 additions & 83 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,89 +18,14 @@ 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
};
34-
35-
debug = {
36-
options = mkOption {
37-
type = types.raw;
38-
description = "All of the options affected by Facter modules";
39-
};
40-
config = mkOption {
41-
type = types.raw;
42-
description = "A breakdown of the NixOS config being applied by each Facter module.";
43-
};
44-
};
4530
};
46-
47-
config.facter.debug = {
48-
options =
49-
let
50-
# we want all options except our own, otherwise we get into recursive issues
51-
otherOptions = lib.filterAttrs (n: _: n != "facter") options;
52-
53-
# a filter for identifying options where a Facter module has affected the value
54-
touchedByFacter =
55-
{ definitionsWithLocations, ... }:
56-
let
57-
# some options fail when we try to evaluate them, so we wrap this in tryEval
58-
eval = builtins.tryEval (
59-
builtins.any (
60-
{
61-
file ? "",
62-
...
63-
}:
64-
# we only want options affected by our modules
65-
lib.hasPrefix "${modulePath}/modules/nixos" file
66-
) definitionsWithLocations
67-
);
68-
in
69-
eval.success && eval.value;
70-
in
71-
lib.fold (a: b: lib.recursiveUpdate a b) { } (
72-
map (value@{ loc, ... }: lib.setAttrByPath loc value) (
73-
# we collect the options first with simple option filter, and then we filter them some more, otherwise we get
74-
# a max-call depth exceeded error (dunno why)
75-
lib.filter touchedByFacter (lib.collect lib.isOption otherOptions)
76-
)
77-
);
78-
79-
config =
80-
# extract the config values for each option, broken down by facter module
81-
lib.mapAttrsRecursiveCond
82-
(
83-
{
84-
definitionsWithLocations ? null,
85-
...
86-
}:
87-
# keep recursing if we are not processing an option, otherwise apply the map function
88-
definitionsWithLocations == null
89-
)
90-
(
91-
_:
92-
{ definitionsWithLocations, ... }:
93-
builtins.listToAttrs (
94-
map
95-
(
96-
{ file, value }:
97-
{
98-
name = "<facter>${lib.removePrefix modulePath file}";
99-
inherit value;
100-
}
101-
)
102-
(
103-
# we only want facter modules
104-
lib.filter ({ file, ... }: lib.hasPrefix modulePath file) definitionsWithLocations
105-
)
106-
)
107-
)
108-
cfg.debug.options;
109-
};
110-
11131
}

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)