Revert "nixosModules,pkgs: remove installer. clanModules: init installer module"
This reverts commit 29a7f0312b.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
./clan-cli/flake-module.nix
|
||||
./clan-app/flake-module.nix
|
||||
./clan-vm-manager/flake-module.nix
|
||||
./installer/flake-module.nix
|
||||
./schemas/flake-module.nix
|
||||
./webview-ui/flake-module.nix
|
||||
./distro-packages/flake-module.nix
|
||||
|
||||
60
pkgs/installer/base64.nix
Normal file
60
pkgs/installer/base64.nix
Normal file
@@ -0,0 +1,60 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
toBase64 =
|
||||
text:
|
||||
let
|
||||
inherit (lib)
|
||||
sublist
|
||||
mod
|
||||
stringToCharacters
|
||||
concatMapStrings
|
||||
;
|
||||
inherit (lib.strings) charToInt;
|
||||
inherit (builtins)
|
||||
substring
|
||||
foldl'
|
||||
genList
|
||||
elemAt
|
||||
length
|
||||
concatStringsSep
|
||||
stringLength
|
||||
;
|
||||
lookup = stringToCharacters "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
sliceN =
|
||||
size: list: n:
|
||||
sublist (n * size) size list;
|
||||
pows = [
|
||||
(64 * 64 * 64)
|
||||
(64 * 64)
|
||||
64
|
||||
1
|
||||
];
|
||||
intSextets = i: map (j: mod (i / j) 64) pows;
|
||||
compose =
|
||||
f: g: x:
|
||||
f (g x);
|
||||
intToChar = elemAt lookup;
|
||||
convertTripletInt = sliceInt: concatMapStrings intToChar (intSextets sliceInt);
|
||||
sliceToInt = foldl' (acc: val: acc * 256 + val) 0;
|
||||
convertTriplet = compose convertTripletInt sliceToInt;
|
||||
join = concatStringsSep "";
|
||||
convertLastSlice =
|
||||
slice:
|
||||
let
|
||||
len = length slice;
|
||||
in
|
||||
if len == 1 then
|
||||
(substring 0 2 (convertTripletInt ((sliceToInt slice) * 256 * 256))) + "=="
|
||||
else if len == 2 then
|
||||
(substring 0 3 (convertTripletInt ((sliceToInt slice) * 256))) + "="
|
||||
else
|
||||
"";
|
||||
len = stringLength text;
|
||||
nFullSlices = len / 3;
|
||||
bytes = map charToInt (stringToCharacters text);
|
||||
tripletAt = sliceN 3 bytes;
|
||||
head = genList (compose convertTriplet tripletAt) nFullSlices;
|
||||
tail = convertLastSlice (tripletAt nFullSlices);
|
||||
in
|
||||
join (head ++ [ tail ]);
|
||||
}
|
||||
71
pkgs/installer/flake-module.nix
Normal file
71
pkgs/installer/flake-module.nix
Normal file
@@ -0,0 +1,71 @@
|
||||
{ self, lib, ... }:
|
||||
|
||||
let
|
||||
|
||||
flashInstallerModule =
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
./iwd.nix
|
||||
self.nixosModules.installer
|
||||
# Allow to download pre-build binaries from our nix caches
|
||||
self.clanModules.trusted-nix-caches
|
||||
];
|
||||
|
||||
system.stateVersion = config.system.nixos.version;
|
||||
nixpkgs.pkgs = self.inputs.nixpkgs.legacyPackages.x86_64-linux;
|
||||
}
|
||||
// flashDiskoConfig;
|
||||
|
||||
# Important: The partition names need to be different to the clan install
|
||||
flashDiskoConfig = {
|
||||
boot.loader.grub.efiSupport = lib.mkDefault true;
|
||||
boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true;
|
||||
disko.devices = {
|
||||
disk = {
|
||||
main = {
|
||||
type = "disk";
|
||||
device = lib.mkDefault "/dev/null";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
installer-boot = {
|
||||
size = "1M";
|
||||
type = "EF02"; # for grub MBR
|
||||
priority = 1;
|
||||
};
|
||||
installer-ESP = {
|
||||
size = "512M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
};
|
||||
installer-root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
clan = {
|
||||
# To directly flash the installer to a disk, use the following command:
|
||||
# $ clan flash flash-installer --disk main /dev/sdX --yes
|
||||
# This will include your ssh public keys in the installer.
|
||||
machines.flash-installer = {
|
||||
imports = [ flashInstallerModule ];
|
||||
boot.loader.grub.enable = lib.mkDefault true;
|
||||
};
|
||||
};
|
||||
}
|
||||
67
pkgs/installer/iwd.nix
Normal file
67
pkgs/installer/iwd.nix
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.clan.iwd;
|
||||
toBase64 = (pkgs.callPackage ./base64.nix { inherit lib; }).toBase64;
|
||||
wifi_config = password: ''
|
||||
[Security]
|
||||
Passphrase=${password}
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.clan.iwd = {
|
||||
networks = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
options = {
|
||||
ssid = lib.mkOption {
|
||||
type = lib.types.strMatching "^[a-zA-Z0-9._-]+$";
|
||||
default = name;
|
||||
description = "The name of the wifi network";
|
||||
};
|
||||
password = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The password of the wifi network";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
description = "Wifi networks to predefine";
|
||||
};
|
||||
};
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf (cfg.networks != { }) {
|
||||
# Systemd tmpfiles rule to create /var/lib/iwd/example.psk file
|
||||
systemd.tmpfiles.rules = lib.mapAttrsToList (
|
||||
_: value:
|
||||
"f+~ /var/lib/iwd/${value.ssid}.psk 0600 root root - ${toBase64 (wifi_config value.password)}"
|
||||
) cfg.networks;
|
||||
|
||||
})
|
||||
{
|
||||
# disable wpa supplicant
|
||||
networking.wireless.enable = false;
|
||||
|
||||
# Use iwd instead of wpa_supplicant. It has a user friendly CLI
|
||||
networking.wireless.iwd = {
|
||||
enable = true;
|
||||
settings = {
|
||||
Network = {
|
||||
EnableIPv6 = true;
|
||||
RoutePriorityOffset = 300;
|
||||
};
|
||||
Settings.AutoConnect = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user