@@ -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;
@@ -47,7 +47,8 @@ string[string] getProcInfo(string fileOrData, bool file = true)
4747{
4848 string [string ] r;
4949 foreach (line; file ? fileOrData.readText().split(
50- " \n " ).map! (strip).array : fileOrData.split(" \n " ).map! (strip).array)
50+ " \n " ).map! (strip).array
51+ : fileOrData.split(" \n " ).map! (strip).array)
5152 {
5253 if (line.indexOf(" :" ) == - 1 || line.strip == " edid-decode (hex):" )
5354 {
@@ -205,7 +206,7 @@ ProcessorInfo getProcessorInfo()
205206 r.vendor = cpuid.x86_any.vendor;
206207 char [48 ] modelCharArr;
207208 cpuid.x86_any.brand(modelCharArr);
208- r.model = modelCharArr.idup[0 .. (strlen(modelCharArr.ptr)- 1 )];
209+ r.model = modelCharArr.idup[0 .. (strlen(modelCharArr.ptr) - 1 )];
209210 r.cpus = cpuid.unified.cpus();
210211 r.cores = [r.cpus * cpuid.unified.cores()];
211212 r.threads = [cpuid.unified.threads()];
@@ -384,8 +385,15 @@ MemoryInfo getMemoryInfo()
384385 r.count = dmi.getFromDmi(" Type:" ).length;
385386 r.slots = dmi.getFromDmi(" Memory Device" )
386387 .filter! (a => a.indexOf(" DMI type 17" ) != - 1 ).array.length;
387- r.totalGB = dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ]).array.filter! (isNumeric).array.map! (to! int ).array.sum();
388- r.total =r.totalGB.to! string ~ " GB (" ~ dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ]).join(" /" ) ~ " )" ;
388+ r.totalGB = dmi.getFromDmi(" Size:" ).map! (a => a.split(" " )[0 ])
389+ .array
390+ .filter! (isNumeric)
391+ .array
392+ .map! (to! int )
393+ .array
394+ .sum();
395+ r.total = r.totalGB.to! string ~ " GB (" ~ dmi.getFromDmi(" Size:" )
396+ .map! (a => a.split(" " )[0 ]).join(" /" ) ~ " )" ;
389397 auto totalWidth = dmi.getFromDmi(" Total Width" );
390398 auto dataWidth = dmi.getFromDmi(" Data Width" );
391399 foreach (i, width; totalWidth)
@@ -570,7 +578,8 @@ DisplayInfo getDisplayInfo()
570578 d.model = (" Model" in edidData) ? edidData[" Model" ] : " Unknown" ;
571579 d.serial = (" Serial Number" in edidData) ? edidData[" Serial Number" ] : " Unknown" ;
572580 d.manufactureDate = (" Made in" in edidData) ? edidData[" Made in" ] : " Unknown" ;
573- d.size = (" Maximum image size" in edidData) ? edidData[" Maximum image size" ] : " Unknown" ;
581+ d.size = (" Maximum image size" in edidData) ? edidData[" Maximum image size" ]
582+ : " Unknown" ;
574583 }
575584
576585 r.displays ~= d;
@@ -596,11 +605,14 @@ struct GraphicsProcessorInfo
596605GraphicsProcessorInfo getGraphicsProcessorInfo ()
597606{
598607 GraphicsProcessorInfo r;
599- if (" DISPLAY" ! in environment) return r;
600- try {
608+ if (" DISPLAY" ! in environment)
609+ return r;
610+ try
611+ {
601612 auto glxinfo = getProcInfo(execute(" glxinfo" , false ), false );
602613 r.vendor = (" OpenGL vendor string" in glxinfo) ? glxinfo[" OpenGL vendor string" ] : " Unknown" ;
603- r.model = (" OpenGL renderer string" in glxinfo) ? glxinfo[" OpenGL renderer string" ] : " Unknown" ;
614+ r.model = (" OpenGL renderer string" in glxinfo) ? glxinfo[" OpenGL renderer string" ]
615+ : " Unknown" ;
604616 r.coreProfile = (" OpenGL core profile version string" in glxinfo) ? glxinfo[" OpenGL core profile version string" ] : " Unknown" ;
605617 r.vram = (" Video memory" in glxinfo) ? glxinfo[" Video memory" ] : " Unknown" ;
606618 }
@@ -641,7 +653,6 @@ MachineConfigInfo getMachineConfigInfo()
641653{
642654 MachineConfigInfo r;
643655
644-
645656 // PCI devices
646657 foreach (path; dirEntries(" /sys/bus/pci/devices" , SpanMode.shallow).map! (a => a.name).array)
647658 {
@@ -751,31 +762,38 @@ MachineConfigInfo getMachineConfigInfo()
751762 }
752763
753764 if (_module != " " &&
754- // Mass-storage controller. Definitely important.
755- _class.startsWith(" 0x08" ) ||
756- // Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
757- (subClass.startsWith(" 0x03" ) || protocol.startsWith(" 0x01" )))
765+ // Mass-storage controller. Definitely important.
766+ _class.startsWith(" 0x08" ) ||
767+ // Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
768+ (subClass.startsWith(" 0x03" ) || protocol.startsWith(" 0x01" )))
758769 {
759770 r.availableKernelModules ~= _module;
760771 }
761772 }
762773
763774 // Block and MMC devices
764775 foreach (path; (
765- (exists(" /sys/class/block" ) ? dirEntries(" /sys/class/block" , SpanMode.shallow).array : []) ~
766- (exists(" /sys/class/mmc_host" ) ? dirEntries(" /sys/class/mmc_host" , SpanMode.shallow).array : []))
776+ (exists(" /sys/class/block" ) ? dirEntries(" /sys/class/block" , SpanMode.shallow)
777+ .array : []) ~
778+ (exists(" /sys/class/mmc_host" ) ? dirEntries(" /sys/class/mmc_host" , SpanMode.shallow).array
779+ : []))
767780 .map! (a => a.name).array)
768781 {
769- if (exists(path ~ " /device/driver/module" )) {
782+ if (exists(path ~ " /device/driver/module" ))
783+ {
770784 string _module = readLink(path ~ " /device/driver/module" ).baseName;
771785 r.availableKernelModules ~= _module;
772786 }
773787 }
774788 // Bcache
775- auto bcacheDevices = dirEntries(" /dev" , SpanMode.shallow).map! (a => a.name).array.filter! (a => a.startsWith(" bcache" )).array;
789+ auto bcacheDevices = dirEntries(" /dev" , SpanMode.shallow).map! (a => a.name)
790+ .array
791+ .filter! (a => a.startsWith(" bcache" ))
792+ .array;
776793 bcacheDevices = bcacheDevices.filter! (device => device.indexOf(" dev/bcachefs" ) == - 1 ).array;
777794
778- if (bcacheDevices.length > 0 ) {
795+ if (bcacheDevices.length > 0 )
796+ {
779797 r.availableKernelModules ~= " bcache" ;
780798 }
781799 // Prevent unbootable systems if LVM snapshots are present at boot time.
@@ -785,27 +803,29 @@ MachineConfigInfo getMachineConfigInfo()
785803 }
786804 // Check if we're in a VirtualBox guest. If so, enable the guest additions.
787805 auto virt = execute! ProcessPipes(" systemd-detect-virt" , false ).stdout.readln.strip;
788- switch (virt) {
789- case " oracle" :
790- r.literalAttrs ~= Literal(" virtualisation.virtualbox.guest.enable = true;" );
791- break ;
792- case " parallels" :
793- r.literalAttrs ~= Literal(" hardware.parallels.enable = true;" );
794- r.literalAttrs ~= Literal(" nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \" prl-tools\" ];" );
795- break ;
796- case " qemu" :
797- case " kvm" :
798- case " bochs" :
799- r.imports ~= Literal(" (modulesPath + \" /profiles/qemu-guest.nix\" )" );
800- break ;
801- case " microsoft" :
802- r.literalAttrs ~= Literal(" virtualization.hypervGuest.enable = true;" );
803- break ;
804- case " systemd-nspawn" :
805- r.literalAttrs ~= Literal(" boot.isContainer;" );
806- break ;
807- default :
808- break ;
806+ switch (virt)
807+ {
808+ case " oracle" :
809+ r.literalAttrs ~= Literal(" virtualisation.virtualbox.guest.enable = true;" );
810+ break ;
811+ case " parallels" :
812+ r.literalAttrs ~= Literal(" hardware.parallels.enable = true;" );
813+ r.literalAttrs ~= Literal(
814+ " nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \" prl-tools\" ];" );
815+ break ;
816+ case " qemu" :
817+ case " kvm" :
818+ case " bochs" :
819+ r.imports ~= Literal(" (modulesPath + \" /profiles/qemu-guest.nix\" )" );
820+ break ;
821+ case " microsoft" :
822+ r.literalAttrs ~= Literal(" virtualization.hypervGuest.enable = true;" );
823+ break ;
824+ case " systemd-nspawn" :
825+ r.literalAttrs ~= Literal(" boot.isContainer;" );
826+ break ;
827+ default :
828+ break ;
809829 }
810830
811831 return r;
0 commit comments