From 9d888222669e6f2ebd4e875d5f6dab7dcdb97f51 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Mon, 25 Nov 2024 22:37:08 -0600 Subject: [PATCH] started draft for installer --- build-installer.sh | 30 +++++++++++++ .../installer/basic/configuration.nix | 19 ++++++++ configurations/installer/basic/default.nix | 5 +++ flake.nix | 45 ++++++++++++------- util/default.nix | 10 +++++ 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 build-installer.sh create mode 100644 configurations/installer/basic/configuration.nix create mode 100644 configurations/installer/basic/default.nix diff --git a/build-installer.sh b/build-installer.sh new file mode 100644 index 0000000..e124091 --- /dev/null +++ b/build-installer.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +while [ $# -gt 0 ]; do + case "$1" in + --flake*|-f*) + if [[ "$1" != *=* ]]; then shift; fi + flake="${1#*=}" + ;; + # --user*|-u*) + # if [[ "$1" != *=* ]]; then shift; fi + # user="${1#*=}" + # ;; + --help|-h) + echo "--help -h: print this message" + echo "--flake -f: set the flake to build an installer for" + # echo "--user -u: set the user to install flake as on the target system" + exit 0 + ;; + *) + echo "Error: Invalid argument $1" + exit 1 + ;; + esac + shift +done + +flake=${flake:-"basic"} +user=${user:-$USER} + +nix build .#installerConfigurations.$flake.config.system.build.isoImage \ No newline at end of file diff --git a/configurations/installer/basic/configuration.nix b/configurations/installer/basic/configuration.nix new file mode 100644 index 0000000..4e63727 --- /dev/null +++ b/configurations/installer/basic/configuration.nix @@ -0,0 +1,19 @@ +{ + lib, + pkgs, + modulesPath, + ... +}: { + imports = [(modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")]; + + systemd.services.sshd.wantedBy = pkgs.lib.mkForce ["multi-user.target"]; + users.users.root.openssh.authorizedKeys.keys = [ + "ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host" + ]; + + isoImage.squashfsCompression = "gzip -Xcompression-level 1"; + + networking.hostName = "installer"; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/configurations/installer/basic/default.nix b/configurations/installer/basic/default.nix new file mode 100644 index 0000000..220a6fb --- /dev/null +++ b/configurations/installer/basic/default.nix @@ -0,0 +1,5 @@ +{...}: { + imports = [ + ./configuration.nix + ]; +} diff --git a/flake.nix b/flake.nix index 152ea63..e90e17c 100644 --- a/flake.nix +++ b/flake.nix @@ -76,10 +76,30 @@ util = import ./util {inherit inputs;}; forEachPkgs = util.forEachPkgs; + mkNixosInstaller = util.mkNixosInstaller; mkNixosSystem = util.mkNixosSystem; mkDarwinSystem = util.mkDarwinSystem; mkHome = util.mkHome; + installerSystems = { + basic = mkNixosInstaller "basic" []; + }; + + nixosSystems = { + horizon = mkNixosSystem "horizon"; + twilight = mkNixosSystem "twilight"; + defiant = mkNixosSystem "defiant"; + }; + + darwinSystems = { + hesperium = mkDarwinSystem "hesperium"; + }; + + homeSystems = { + # stand alone home manager configurations here: + # name = mkHome "name" + }; + systemsHomes = nixpkgs.lib.attrsets.mergeAttrsList ( nixpkgs.lib.attrsets.mapAttrsToList (hostname: system: ( nixpkgs.lib.attrsets.mapAttrs' (user: _: { @@ -88,8 +108,12 @@ }) system.config.home-manager.users )) - (inputs.self.nixosConfigurations // inputs.self.darwinConfigurations) + (nixosSystems // darwinSystems) ); + + homeConfigurations = + systemsHomes + // homeSystems; in { formatter = forEachPkgs (pkgs: pkgs.alejandra); @@ -113,21 +137,12 @@ }; }); - nixosConfigurations = { - horizon = mkNixosSystem "horizon"; - twilight = mkNixosSystem "twilight"; - defiant = mkNixosSystem "defiant"; - }; + installerConfigurations = installerSystems; - darwinConfigurations = { - hesperium = mkDarwinSystem "hesperium"; - }; + nixosConfigurations = nixosSystems; - homeConfigurations = - systemsHomes - // { - # stand alone configurations here: - # name = mkHome "name" - }; + darwinConfigurations = darwinSystems; + + homeConfigurations = homeConfigurations; }; } diff --git a/util/default.nix b/util/default.nix index f04f9c9..41d985a 100644 --- a/util/default.nix +++ b/util/default.nix @@ -55,6 +55,16 @@ in { (lib.mkUnless condition no) ]; + mkNixosInstaller = host: userKeys: + nixpkgs.lib.nixosSystem { + modules = [ + { + # TODO: authorized keys for all users + } + ../configurations/nixos/${host} + ]; + }; + mkNixosSystem = host: nixpkgs.lib.nixosSystem { specialArgs = {inherit inputs outputs util;};