204 lines
5.9 KiB
Nix
Raw Normal View History

2023-02-23 00:01:15 +03:00
{ config, options, lib, pkgs, ... }:
2023-01-26 00:24:32 +03:00
with lib;
let
cfg = config.autoinstall;
2023-02-23 00:01:15 +03:00
autoinstallOptions = { name, ... }: {
options = rec {
2023-01-26 00:24:32 +03:00
autoReboot = mkOption {
type = types.bool;
default = false;
description = "Auto reboot after install complete successufuly";
};
partitioning = {
useEntireDisk = mkOption {
type = types.bool;
default = true;
description = "Wipe entire disk and write new partition table";
};
nullifyDisk = mkOption {
type = types.bool;
default = false;
description = "Nullify entire disk. Very slow!";
};
disk = mkOption {
type = types.str;
default = "";
description = "Path to the disk to wipe";
};
2023-03-25 19:28:11 +03:00
emptySpace = mkOption {
type = types.str;
default = "0";
2023-03-26 19:24:28 +03:00
description = "Empty space at the end of the disk";
};
createBootPool = mkOption {
type = types.bool;
default = true;
description = "";
2023-03-25 19:28:11 +03:00
};
2023-01-26 00:24:32 +03:00
# partitions = mkOption {
# type = types.nullOr attrsOf partitionsAttrs;
# default = null;
# description = "If not wipe entire disk";
# };
};
debug = mkOption {
type = types.bool;
default = false;
description = "If we should exit before installing or not to let debugging occur";
};
mainuser = mkOption {
type = types.str;
2023-03-25 19:28:11 +03:00
default = "ataraxia";
2023-01-26 00:24:32 +03:00
description = "Name of the main user (used for creation of home folder)";
};
flakesPath = mkOption {
type = types.str;
default = "";
description = "Path to config folder with flakes";
};
efiSize = mkOption {
type = types.str;
default = "512MiB";
description = "Size of EFI partition";
};
2023-03-26 19:24:28 +03:00
efiMountPoint = mkOption {
type = types.str;
default = "/boot";
description = "EFI mount point";
};
2023-01-26 00:24:32 +03:00
bootSize = mkOption {
type = types.str;
default = "4GiB";
description = "Size of boot partition";
};
rootSize = mkOption {
type = types.str;
default = "0";
description = "Size of root partition. If using 0, expand root partition to entire free space on disk";
};
swapPartition = {
enable = mkOption {
type = types.bool;
default = true;
description = "Use swap partition";
};
size = mkOption {
type = types.str;
default = "2GiB";
description = "Size of swap partition";
};
};
encryption = {
2023-03-25 19:28:11 +03:00
encryptBoot = mkOption {
2023-01-26 00:24:32 +03:00
type = types.bool;
default = false;
2023-03-25 19:28:11 +03:00
description = "Encrypt boot partition";
};
encryptRoot = mkOption {
type = types.bool;
default = false;
description = "Encrypt boot partition";
2023-01-26 00:24:32 +03:00
};
argonIterTime = mkOption {
type = types.str;
default = "5000";
description = "iter-time for argon2 in ms";
};
cryptBoot = mkOption {
type = types.str;
default = "cryptboot";
description = "Name of luks boot device";
};
cryptRoot = mkOption {
type = types.str;
default = "cryptroot";
description = "Name of luks root device";
};
passwordFile = mkOption {
type = types.str;
default = "";
description = "Path to file that contains password that pass to luksFormat";
};
};
zfsOpts = {
ashift = mkOption {
type = types.int;
default = 13;
description = "ashift passed to zfs pool creation";
};
bootPoolReservation = mkOption {
type = types.str;
default = "0";
description = "Reserve some space on boot pool";
};
rootPoolReservation = mkOption {
type = types.str;
default = "0";
description = "Reserve some space on root pool";
};
};
persist = {
enable = mkOption {
type = types.bool;
default = true;
description = "Use persist module";
};
persistRoot = mkOption {
type = types.str;
default = "/persist";
description = "Path to persist mount point";
};
persistHome = mkOption {
type = types.str;
2023-02-23 00:01:15 +03:00
default = "/home/${cfg.${name}.mainuser}";
2023-01-26 00:24:32 +03:00
description = "Path to home user folder relative to persistRoot";
};
};
2023-01-26 00:34:37 +03:00
oldUefi = mkOption {
type = types.bool;
default = false;
description = "Copy bootx64.efi to windows efi location (EFI/Microsoft/Boot/bootmgr.efi)";
};
2023-01-26 00:24:32 +03:00
};
};
2023-02-23 00:01:15 +03:00
mkService = name: opt: {
description = "Autoinstall NixOS on ${name}";
# wantedBy = [ "multi-user.target" ];
# after = [ "network.target" "polkit.service" ];
path = with pkgs; [
"/run/current-system/sw/"
"/usr/bin/"
"${systemd}/bin/"
"${git}/bin"
];
script = import ./install.nix {
inherit lib; inherit opt; hostname = name;
};
environment = config.nix.envVars // rec {
inherit (config.environment.sessionVariables) NIX_PATH;
HOME = "/root";
2023-01-26 00:24:32 +03:00
};
2023-02-23 00:01:15 +03:00
serviceConfig = { Type = "oneshot"; };
};
2023-03-25 19:28:11 +03:00
# asserts = opt: [{
# assertion = opt.flakesPath != "";
# message = "flakesPath can't be empty";
# } {
# assertion = !(opt.encryption.enable && opt.encryption.passwordFile == "");
# message = "If you use encryption, you need to set path to password file";
# }];
2023-02-23 00:01:15 +03:00
in {
options.autoinstall = mkOption {
default = {};
type = types.attrsOf (types.submodule autoinstallOptions);
};
config = lib.mkIf (cfg != {}) {
systemd.services = mapAttrs' (n: v: nameValuePair "autoinstall-${n}" (mkService n v)) cfg;
2023-01-26 00:24:32 +03:00
};
2023-03-26 19:24:28 +03:00
}