@@ -14,7 +14,7 @@ import std.file : exists, write, readText, readLink, dirEntries, SpanMode;
1414import std.path : baseName;
1515import std.json ;
1616import std.process : ProcessPipes, environment;
17- import core.stdc.string : strlen;
17+ import core.stdc.string : strlen;
1818
1919import mcl.utils.env : parseEnv, optional;
2020import mcl.utils.json : toJSON;
@@ -50,7 +50,8 @@ string[string] getProcInfo(string fileOrData, bool file = true)
5050{
5151 string [string ] r;
5252 foreach (line; file ? fileOrData.readText().split(
53- " \n " ).map! (strip).array : fileOrData.split(" \n " ).map! (strip).array)
53+ " \n " ).map! (strip).array
54+ : fileOrData.split(" \n " ).map! (strip).array)
5455 {
5556 if (line.indexOf(" :" ) == - 1 || line.strip == " edid-decode (hex):" )
5657 {
@@ -292,7 +293,7 @@ ProcessorInfo getProcessorInfo()
292293 r.vendor = cpuid.x86_any.vendor;
293294 char [48 ] modelCharArr;
294295 cpuid.x86_any.brand(modelCharArr);
295- r.model = modelCharArr.idup[0 .. (strlen(modelCharArr.ptr)- 1 )];
296+ r.model = modelCharArr.idup[0 .. (strlen(modelCharArr.ptr) - 1 )];
296297 r.cpus = cpuid.unified.cpus();
297298 r.cores = [r.cpus * cpuid.unified.cores()];
298299 r.threads = [cpuid.unified.threads()];
@@ -471,8 +472,15 @@ MemoryInfo getMemoryInfo()
471472 r.count = dmi.getFromDmi(" Type:" ).length;
472473 r.slots = dmi.getFromDmi(" Memory Device" )
473474 .filter! (a => a.indexOf(" DMI type 17" ) != - 1 ).array.length;
474- r.totalGB = dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ]).array.filter! (isNumeric).array.map! (to! int ).array.sum();
475- r.total =r.totalGB.to! string ~ " GB (" ~ dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ]).join(" /" ) ~ " )" ;
475+ r.totalGB = dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ])
476+ .array
477+ .filter! (isNumeric)
478+ .array
479+ .map! (to! int )
480+ .array
481+ .sum();
482+ r.total = r.totalGB.to! string ~ " GB (" ~ dmi.getFromDmi(" Size:" )
483+ .map! (a => a.split(" " )[0 ]).join(" /" ) ~ " )" ;
476484 auto totalWidth = dmi.getFromDmi(" Total Width" );
477485 auto dataWidth = dmi.getFromDmi(" Data Width" );
478486 foreach (i, width; totalWidth)
@@ -657,7 +665,8 @@ DisplayInfo getDisplayInfo()
657665 d.model = (" Model" in edidData) ? edidData[" Model" ] : " Unknown" ;
658666 d.serial = (" Serial Number" in edidData) ? edidData[" Serial Number" ] : " Unknown" ;
659667 d.manufactureDate = (" Made in" in edidData) ? edidData[" Made in" ] : " Unknown" ;
660- d.size = (" Maximum image size" in edidData) ? edidData[" Maximum image size" ] : " Unknown" ;
668+ d.size = (" Maximum image size" in edidData) ? edidData[" Maximum image size" ]
669+ : " Unknown" ;
661670 }
662671
663672 r.displays ~= d;
@@ -683,11 +692,14 @@ struct GraphicsProcessorInfo
683692GraphicsProcessorInfo getGraphicsProcessorInfo ()
684693{
685694 GraphicsProcessorInfo r;
686- if (" DISPLAY" ! in environment) return r;
687- try {
695+ if (" DISPLAY" ! in environment)
696+ return r;
697+ try
698+ {
688699 auto glxinfo = getProcInfo(execute(" glxinfo" , false ), false );
689700 r.vendor = (" OpenGL vendor string" in glxinfo) ? glxinfo[" OpenGL vendor string" ] : " Unknown" ;
690- r.model = (" OpenGL renderer string" in glxinfo) ? glxinfo[" OpenGL renderer string" ] : " Unknown" ;
701+ r.model = (" OpenGL renderer string" in glxinfo) ? glxinfo[" OpenGL renderer string" ]
702+ : " Unknown" ;
691703 r.coreProfile = (" OpenGL core profile version string" in glxinfo) ? glxinfo[" OpenGL core profile version string" ] : " Unknown" ;
692704 r.vram = (" Video memory" in glxinfo) ? glxinfo[" Video memory" ] : " Unknown" ;
693705 }
@@ -728,7 +740,6 @@ MachineConfigInfo getMachineConfigInfo()
728740{
729741 MachineConfigInfo r;
730742
731-
732743 // PCI devices
733744 foreach (path; dirEntries(" /sys/bus/pci/devices" , SpanMode.shallow).map! (a => a.name).array)
734745 {
@@ -838,31 +849,38 @@ MachineConfigInfo getMachineConfigInfo()
838849 }
839850
840851 if (_module != " " &&
841- // Mass-storage controller. Definitely important.
842- _class.startsWith(" 0x08" ) ||
843- // Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
844- (subClass.startsWith(" 0x03" ) || protocol.startsWith(" 0x01" )))
852+ // Mass-storage controller. Definitely important.
853+ _class.startsWith(" 0x08" ) ||
854+ // Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
855+ (subClass.startsWith(" 0x03" ) || protocol.startsWith(" 0x01" )))
845856 {
846857 r.availableKernelModules ~= _module;
847858 }
848859 }
849860
850861 // Block and MMC devices
851862 foreach (path; (
852- (exists(" /sys/class/block" ) ? dirEntries(" /sys/class/block" , SpanMode.shallow).array : []) ~
853- (exists(" /sys/class/mmc_host" ) ? dirEntries(" /sys/class/mmc_host" , SpanMode.shallow).array : []))
863+ (exists(" /sys/class/block" ) ? dirEntries(" /sys/class/block" , SpanMode.shallow)
864+ .array : []) ~
865+ (exists(" /sys/class/mmc_host" ) ? dirEntries(" /sys/class/mmc_host" , SpanMode.shallow).array
866+ : []))
854867 .map! (a => a.name).array)
855868 {
856- if (exists(path ~ " /device/driver/module" )) {
869+ if (exists(path ~ " /device/driver/module" ))
870+ {
857871 string _module = readLink(path ~ " /device/driver/module" ).baseName;
858872 r.availableKernelModules ~= _module;
859873 }
860874 }
861875 // Bcache
862- auto bcacheDevices = dirEntries(" /dev" , SpanMode.shallow).map! (a => a.name).array.filter! (a => a.startsWith(" bcache" )).array;
876+ auto bcacheDevices = dirEntries(" /dev" , SpanMode.shallow).map! (a => a.name)
877+ .array
878+ .filter! (a => a.startsWith(" bcache" ))
879+ .array;
863880 bcacheDevices = bcacheDevices.filter! (device => device.indexOf(" dev/bcachefs" ) == - 1 ).array;
864881
865- if (bcacheDevices.length > 0 ) {
882+ if (bcacheDevices.length > 0 )
883+ {
866884 r.availableKernelModules ~= " bcache" ;
867885 }
868886 // Prevent unbootable systems if LVM snapshots are present at boot time.
@@ -872,27 +890,29 @@ MachineConfigInfo getMachineConfigInfo()
872890 }
873891 // Check if we're in a VirtualBox guest. If so, enable the guest additions.
874892 auto virt = execute! ProcessPipes(" systemd-detect-virt" , false ).stdout.readln.strip;
875- switch (virt) {
876- case " oracle" :
877- r.literalAttrs ~= Literal(" virtualisation.virtualbox.guest.enable = true;" );
878- break ;
879- case " parallels" :
880- r.literalAttrs ~= Literal(" hardware.parallels.enable = true;" );
881- r.literalAttrs ~= Literal(" nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \" prl-tools\" ];" );
882- break ;
883- case " qemu" :
884- case " kvm" :
885- case " bochs" :
886- r.imports ~= Literal(" (modulesPath + \" /profiles/qemu-guest.nix\" )" );
887- break ;
888- case " microsoft" :
889- r.literalAttrs ~= Literal(" virtualization.hypervGuest.enable = true;" );
890- break ;
891- case " systemd-nspawn" :
892- r.literalAttrs ~= Literal(" boot.isContainer;" );
893- break ;
894- default :
895- break ;
893+ switch (virt)
894+ {
895+ case " oracle" :
896+ r.literalAttrs ~= Literal(" virtualisation.virtualbox.guest.enable = true;" );
897+ break ;
898+ case " parallels" :
899+ r.literalAttrs ~= Literal(" hardware.parallels.enable = true;" );
900+ r.literalAttrs ~= Literal(
901+ " nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \" prl-tools\" ];" );
902+ break ;
903+ case " qemu" :
904+ case " kvm" :
905+ case " bochs" :
906+ r.imports ~= Literal(" (modulesPath + \" /profiles/qemu-guest.nix\" )" );
907+ break ;
908+ case " microsoft" :
909+ r.literalAttrs ~= Literal(" virtualization.hypervGuest.enable = true;" );
910+ break ;
911+ case " systemd-nspawn" :
912+ r.literalAttrs ~= Literal(" boot.isContainer;" );
913+ break ;
914+ default :
915+ break ;
896916 }
897917
898918 return r;
0 commit comments