Install using a flake

This commit is contained in:
Michael Smith 2024-09-02 21:41:55 +02:00
parent 436d299588
commit 12f929d699

View File

@ -21,7 +21,6 @@ _ = gettext.translation("calamares-python",
languages=libcalamares.utils.gettext_languages(), languages=libcalamares.utils.gettext_languages(),
fallback=True).gettext fallback=True).gettext
def random_hostname():
adjectives = [ adjectives = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark", "summer", "autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark", "summer",
"icy", "delicate", "quiet", "white", "cool", "spring", "winter", "patient", "icy", "delicate", "quiet", "white", "cool", "spring", "winter", "patient",
@ -48,14 +47,36 @@ def random_hostname():
noun = secrets.choice(nouns) noun = secrets.choice(nouns)
number = secrets.randbelow(10_000) number = secrets.randbelow(10_000)
return f"{adjective}-{noun}-{number}" random_hostname = f"{adjective}-{noun}-{number}"
flake = f"""
{{
description = "deskOS flake";
inputs = {{
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
}};
outputs = {{
self,
nixpkgs,
}} @ inputs: {{
nixosConfigurations.{random_hostname} = nixpkgs.lib.nixosSystem {{
system = "x86_64-linux";
specialArgs = {{inherit inputs;}};
modules = [
./configuration.nix
];
}};
}};
}}
"""
configuration_head = """ configuration_head = """
{ config, pkgs, ... }: { pkgs, lib, inputs, ... }:
{ {
imports = imports = [
[
./hardware-configuration.nix ./hardware-configuration.nix
]; ];
""" """
@ -102,7 +123,7 @@ configuration_body = """
""" """
cfghostname = f""" cfghostname = f"""
networking.hostName = "{random_hostname()}"; networking.hostName = "{random_hostname}";
""" """
cfgtime = """ cfgtime = """
@ -189,6 +210,8 @@ def run():
# Setup variables # Setup variables
root_mount_point = gs.value("rootMountPoint") root_mount_point = gs.value("rootMountPoint")
configFile = os.path.join(root_mount_point, "etc/nixos/configuration.nix") configFile = os.path.join(root_mount_point, "etc/nixos/configuration.nix")
flakeFile = os.path.join(root_mount_point, "etc/nixos/flake.nix")
flakePath = os.path.join(root_mount_point, "etc/nixos")
# Pick config parts and prepare substitution # Pick config parts and prepare substitution
@ -327,13 +350,17 @@ def run():
libcalamares.utils.host_env_process_output( libcalamares.utils.host_env_process_output(
["cp", "/dev/stdin", configFile], None, cfg) ["cp", "/dev/stdin", configFile], None, cfg)
# Write the flake.nix file
libcalamares.utils.host_env_process_output(
["cp", "/dev/stdin", flakeFile], None, flake)
status = _("Installing Desk OS") status = _("Installing Desk OS")
libcalamares.job.setprogress(0.3) libcalamares.job.setprogress(0.3)
# Install # Install
try: try:
output = "" output = ""
proc = subprocess.Popen(["pkexec", "nixos-install", "--no-root-passwd", "--root", root_mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) proc = subprocess.Popen(["pkexec", "nixos-install", "--no-root-passwd", "--flake", f"{flakePath}#{random_hostname}", "--root", root_mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True: while True:
line = proc.stdout.readline().decode("utf-8") line = proc.stdout.readline().decode("utf-8")
output += line output += line