Skip to content

Commit

Permalink
Merge pull request #51 from ElvishJerricco/push-xomprrmsksrq
Browse files Browse the repository at this point in the history
Respect Kernel setting in /etc/nixos-generate-config.conf
  • Loading branch information
vlinkz authored Jan 6, 2025
2 parents 5394ee3 + 381e343 commit 51ced18
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
13 changes: 13 additions & 0 deletions modules/nixos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Calamares is Free Software: see the License-Identifier above.
#

import configparser
import libcalamares
import os
import subprocess
Expand Down Expand Up @@ -336,6 +337,11 @@
}
"""

cfglatestkernel = """ # Use latest kernel.
boot.kernelPackages = pkgs.linuxPackages_latest;
"""
def env_is_set(name):
envValue = os.environ.get(name)
return not (envValue is None or envValue == "")
Expand Down Expand Up @@ -387,6 +393,10 @@ def run():
status = _("Configuring NixOS")
libcalamares.job.setprogress(0.1)

ngc_cfg = configparser.ConfigParser()
ngc_cfg["Defaults"] = { "Kernel": "lts" }
ngc_cfg.read("/etc/nixos-generate-config.conf")

# Create initial config file
cfg = cfghead
gs = libcalamares.globalstorage
Expand All @@ -413,6 +423,9 @@ def run():
else:
cfg += cfgbootnone

if ngc_cfg["Defaults"]["Kernel"] == "latest":
cfg += cfglatestkernel

# Setup encrypted swap devices. nixos-generate-config doesn't seem to notice them.
for part in gs.value("partitions"):
if (
Expand Down
22 changes: 16 additions & 6 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def mock_libcalamares(mocker, globalstorage):
return mock_libcalamares


@pytest.fixture
def mock_open_ngcconf(mocker):
return mocker.Mock('open("nixos-generate-config.conf")')


@pytest.fixture
def mock_open_hwconf(mocker):
return mocker.Mock('open("hardware-configuration.nix")')
Expand All @@ -105,9 +110,13 @@ def mock_open_kbdmodelmap(mocker):


@pytest.fixture
def mock_open(mocker, mock_open_hwconf, mock_open_kbdmodelmap):
def mock_open(mocker, mock_open_ngcconf, mock_open_hwconf, mock_open_kbdmodelmap):
testing_dir = os.path.dirname(__file__)

ngcconf_txt = ""
with open(os.path.join(testing_dir, "nixos-generate-config.conf"), "r") as ngcconf:
ngcconf_txt = ngcconf.read()

hwconf_txt = ""
with open(os.path.join(testing_dir, "hardware-configuration.nix"), "r") as hwconf:
hwconf_txt = hwconf.read()
Expand All @@ -118,12 +127,13 @@ def mock_open(mocker, mock_open_hwconf, mock_open_kbdmodelmap):

mock_open = mocker.Mock("open")

def fake_open(*args):
file, mode, *_ = args

assert mode == "r", "open() called without the 'r' mode"
def fake_open(*args, **kwargs):
file, *mode = args
assert len(mode) == 0 or mode[0] == "r", "open() called with non-'r' mode"

if file.endswith("hardware-configuration.nix"):
if file.endswith("nixos-generate-config.conf"):
return mocker.mock_open(mock=mock_open_ngcconf, read_data=ngcconf_txt)(*args)
elif file.endswith("hardware-configuration.nix"):
return mocker.mock_open(mock=mock_open_hwconf, read_data=hwconf_txt)(*args)
elif file.endswith("kbd-model-map"):
return mocker.mock_open(
Expand Down
2 changes: 2 additions & 0 deletions testing/nixos-generate-config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Defaults]
Kernel=latest
10 changes: 10 additions & 0 deletions testing/test_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# Use latest kernel.
boot.kernelPackages = pkgs.linuxPackages_latest;
networking.hostName = "nixos"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
Expand Down Expand Up @@ -85,6 +88,7 @@ def test_baseline(
mock_libcalamares,
mock_getoutput,
mock_check_output,
mock_open_ngcconf,
mock_open_hwconf,
mock_Popen,
):
Expand All @@ -99,6 +103,8 @@ def test_baseline(
# libcalamares.job.setprogress(0.1)
assert mock_libcalamares.job.setprogress.mock_calls[0] == mocker.call(0.1)



# libcalamares.job.setprogress(0.18)
assert mock_libcalamares.job.setprogress.mock_calls[1] == mocker.call(0.18)

Expand All @@ -119,6 +125,10 @@ def test_baseline(
stderr=subprocess.STDOUT,
)

mock_open_ngcconf.assert_called_once_with(
"/etc/nixos-generate-config.conf"
)

# hf = open(root_mount_point + "/etc/nixos/hardware-configuration.nix", "r")
mock_open_hwconf.assert_called_once_with(
"/mnt/root/etc/nixos/hardware-configuration.nix", "r"
Expand Down

0 comments on commit 51ced18

Please sign in to comment.