Skip to content

Commit ec8fade

Browse files
committed
Revert "switch to switch case"
its not supported in mypy yet :/ and ignore doesn't work yet python/mypy#11829 This reverts commit d86a269.
1 parent d86a269 commit ec8fade

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/nixos_gen_config/hardware.py

+22-25
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,19 @@ def cpu_info(field: str) -> str:
2121
cpudata[left.strip()] = right.strip()
2222
return cpudata[field]
2323

24-
match cpu_info("vendor_id"):
25-
case "AuthenticAMD":
26-
nix_config.attrs.append(
27-
"hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;"
28-
)
29-
case "GenuineIntel":
30-
nix_config.attrs.append(
31-
"hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;"
32-
)
33-
34-
for flag in (cpu_info("flags")).split():
35-
match flag:
36-
case "svm":
37-
nix_config.kernel_modules.append("kvm-amd")
38-
case "vmx":
39-
nix_config.kernel_modules.append("kvm-intel")
24+
if cpu_info("vendor_id") == "AuthenticAMD":
25+
nix_config.attrs.append(
26+
"hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;"
27+
)
28+
elif cpu_info("vendor_id") == "GenuineIntel":
29+
nix_config.attrs.append(
30+
"hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;"
31+
)
32+
33+
if "svm" in cpu_info("flags"):
34+
nix_config.kernel_modules.append("kvm-amd")
35+
elif "vmx" in cpu_info("flags"):
36+
nix_config.kernel_modules.append("kvm-intel")
4037

4138
if Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors").exists():
4239
governors = Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors").read_text("utf-8")
@@ -140,12 +137,12 @@ def virt_section(nix_config: NixConfigAttrs) -> None:
140137
nix_config.imports.append('(modulesPath + "/installer/scan/not-detected.nix")')
141138

142139
if virtcmd:
143-
match (virtcmd.stdout).strip():
144-
case "oracle":
145-
nix_config.attrs.append(af.to_nix_true_attr("virtualisation.virtualbox.guest.enable"))
146-
case "microsoft":
147-
nix_config.attrs.append(af.to_nix_true_attr("virtualisation.hypervGuest.enable"))
148-
case "systemd-nspawn":
149-
nix_config.attrs.append(af.to_nix_true_attr("boot.isContainer"))
150-
case "qemu" | "kvm" | "bochs":
151-
nix_config.imports.append('(modulesPath + "/profiles/qemu-quest.nix")')
140+
virt = (virtcmd.stdout).strip()
141+
if virt == "oracle":
142+
nix_config.attrs.append(af.to_nix_true_attr("virtualisation.virtualbox.guest.enable"))
143+
if virt == "microsoft":
144+
nix_config.attrs.append(af.to_nix_true_attr("virtualisation.hypervGuest.enable"))
145+
if virt == "systemd-nspawn":
146+
nix_config.attrs.append(af.to_nix_true_attr("boot.isContainer"))
147+
if virt in ("qemu", "kvm", "bochs"):
148+
nix_config.imports.append('(modulesPath + "/profiles/qemu-quest.nix")')

0 commit comments

Comments
 (0)