From c5e5a7edc701e3e3c5d2ffd7addeedbeac65588e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 5 Apr 2024 15:19:39 +0200 Subject: [PATCH 1/4] grub: enable efi support by default --- clanModules/diskLayouts.nix | 56 ++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/clanModules/diskLayouts.nix b/clanModules/diskLayouts.nix index 097ff2fa..32de6f11 100644 --- a/clanModules/diskLayouts.nix +++ b/clanModules/diskLayouts.nix @@ -6,33 +6,37 @@ example = "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345"; }; }; - config.disko.devices = { - disk = { - main = { - type = "disk"; - device = config.clan.diskLayouts.singleDiskExt4.device; - content = { - type = "gpt"; - partitions = { - boot = { - size = "1M"; - type = "EF02"; # for grub MBR - }; - ESP = { - size = "512M"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; + config = { + boot.loader.grub.efiSupport = lib.mkDefault true; + boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true; + disko.devices = { + disk = { + main = { + type = "disk"; + device = config.clan.diskLayouts.singleDiskExt4.device; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR }; - }; - root = { - size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; + ESP = { + size = "512M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; }; }; }; From 818cc4d135fa513d571aac264d3379895e9c62bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 5 Apr 2024 15:54:58 +0200 Subject: [PATCH 2/4] flash: expose mode option --- pkgs/clan-cli/clan_cli/flash.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/flash.py b/pkgs/clan-cli/clan_cli/flash.py index e59d2102..a03c1af5 100644 --- a/pkgs/clan-cli/clan_cli/flash.py +++ b/pkgs/clan-cli/clan_cli/flash.py @@ -4,6 +4,7 @@ import logging import os import shlex import shutil +import textwrap from collections.abc import Sequence from dataclasses import dataclass from pathlib import Path @@ -20,7 +21,7 @@ log = logging.getLogger(__name__) def flash_machine( - machine: Machine, disks: dict[str, str], dry_run: bool, debug: bool + machine: Machine, mode: str, disks: dict[str, str], dry_run: bool, debug: bool ) -> None: secret_facts_module = importlib.import_module(machine.secret_facts_module) secret_facts_store: SecretStoreBase = secret_facts_module.SecretStore( @@ -56,6 +57,7 @@ def flash_machine( disko_install.extend(["--extra-files", str(local_dir), upload_dir]) disko_install.extend(["--flake", str(machine.flake) + "#" + machine.name]) + disko_install.extend(["--mode", str(mode)]) cmd = nix_shell( ["nixpkgs#disko"], @@ -73,6 +75,7 @@ class FlashOptions: dry_run: bool confirm: bool debug: bool + mode: str class AppendDiskAction(argparse.Action): @@ -99,6 +102,7 @@ def flash_command(args: argparse.Namespace) -> None: dry_run=args.dry_run, confirm=not args.yes, debug=args.debug, + mode=args.mode, ) machine = Machine(opts.machine, flake=opts.flake) if opts.confirm and not opts.dry_run: @@ -110,7 +114,9 @@ def flash_command(args: argparse.Namespace) -> None: ask = input(msg) if ask != "y": return - flash_machine(machine, disks=opts.disks, dry_run=opts.dry_run, debug=opts.debug) + flash_machine( + machine, opts.mode, disks=opts.disks, dry_run=opts.dry_run, debug=opts.debug + ) def register_parser(parser: argparse.ArgumentParser) -> None: @@ -128,6 +134,20 @@ def register_parser(parser: argparse.ArgumentParser) -> None: help="device to flash to", default={}, ) + mode_help = textwrap.dedent("""\ + Specify the mode of operation. Valid modes are: format, mount." + Format will format the disk before installing. + Mount will mount the disk before installing. + Mount is useful for updating an existing system without losing data. + """) + parser.add_argument( + "--mode", + type=str, + help=mode_help, + choices=["format", "mount"], + default="format", + ) + parser.add_argument( "--yes", action="store_true", From 1fd28f2f4cee728b2cf10f798bbd05c5214dd924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 5 Apr 2024 18:40:08 +0200 Subject: [PATCH 3/4] flake-parts: fixup type for specialArgs --- flakeModules/clan.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flakeModules/clan.nix b/flakeModules/clan.nix index 4df243ae..fa4cc981 100644 --- a/flakeModules/clan.nix +++ b/flakeModules/clan.nix @@ -22,7 +22,7 @@ in description = "The directory containing the clan subdirectory"; }; specialArgs = mkOption { - type = types.attrsOf types.str; + type = types.attrsOf types.raw; default = { }; description = "Extra arguments to pass to nixosSystem i.e. useful to make self available"; }; From e68eba914e7acd394501e53cb854693d75b8507f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 5 Apr 2024 13:08:32 +0200 Subject: [PATCH 4/4] improve starter template --- templates/new-clan/flake.nix | 39 ++++++++++++++++++++++++++++ templates/new-clan/modules/disko.nix | 36 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 templates/new-clan/modules/disko.nix diff --git a/templates/new-clan/flake.nix b/templates/new-clan/flake.nix index 2f34b17c..315a88dd 100644 --- a/templates/new-clan/flake.nix +++ b/templates/new-clan/flake.nix @@ -11,6 +11,45 @@ clan = clan-core.lib.buildClan { directory = self; clanName = "__CHANGE_ME__"; + machines = { + machine1 = { + nixpkgs.hostPlatform = system; + imports = [ + # TODO: boot into the installer + # remote> nixos-generate-config --root /tmp/config --no-filesystems + # local> mkdir -p ./machines/machine1 + # local> scp -r root@machine1:/tmp/config ./machines/machine1 + # local> Edit ./machines/machine1/configuration.nix to your liking + ./modules/disko.nix + clan-core.clanModules.sshd + { + # Set this for clan commands use ssh i.e. `clan machines update` + clan.networking.targetHost = pkgs.lib.mkDefault "root@"; + # remote> lsblk --output NAME,PTUUID,FSTYPE,SIZE,MOUNTPOINT + + config.disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__"; + + clan.networking.zerotier.controller.enable = true; + } + ]; + }; + machine2 = { + nixpkgs.hostPlatform = system; + imports = [ + # ./machines/machine2/configuration.nix + ./modules/disko.nix + clan-core.clanModules.sshd + { + # Set this for clan commands use ssh i.e. `clan machines update` + clan.networking.targetHost = pkgs.lib.mkDefault "root@"; + + config.disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__"; + # local> clan facts generate + clan.networking.zerotier.networkId = builtins.readFile ./machines/machine1/facts/zerotier-network-id; + } + ]; + }; + }; }; in { diff --git a/templates/new-clan/modules/disko.nix b/templates/new-clan/modules/disko.nix new file mode 100644 index 00000000..ba8700b6 --- /dev/null +++ b/templates/new-clan/modules/disko.nix @@ -0,0 +1,36 @@ +{ + config.disko.devices = { + disk = { + main = { + type = "disk"; + device = throw "Change this to your disk device"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR + }; + ESP = { + size = "512M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; +}