From eb83880671d4ab366ccfed87c3f69d036e68fbf1 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Tue, 20 Aug 2024 12:13:09 -0400 Subject: [PATCH] Create host/vm named smarthome --- flake.nix | 15 +++++ modules/home-manager/hosts/smarthome/gene.nix | 7 +++ modules/hosts/nixos/smarthome/default.nix | 53 ++++++++++++++++++ modules/hosts/nixos/smarthome/disk-config.nix | 56 +++++++++++++++++++ .../smarthome/hardware-configuration.nix | 15 +++++ 5 files changed, 146 insertions(+) create mode 100644 modules/home-manager/hosts/smarthome/gene.nix create mode 100644 modules/hosts/nixos/smarthome/default.nix create mode 100644 modules/hosts/nixos/smarthome/disk-config.nix create mode 100644 modules/hosts/nixos/smarthome/hardware-configuration.nix diff --git a/flake.nix b/flake.nix index 5a65fdf..dcbe4b3 100644 --- a/flake.nix +++ b/flake.nix @@ -122,6 +122,14 @@ }; overlays = [ nixpkgs-terraform.overlays.default ]; }; + pkgs-unstable = import nixpkgs-unstable { + inherit system; + config = { + allowUnfree = true; + permittedInsecurePackages = [ "electron-21.4.4" ]; + }; + overlays = [ ]; + }; } // additionalSpecialArgs; modules = [ disko.nixosModules.disko @@ -233,6 +241,13 @@ ]; additionalSpecialArgs = {}; }; + smarthome = nixosHostConfig { + system = "x86_64-linux"; + hostname = "smarthome"; + username = "gene"; + additionalModules = []; + additionalSpecialArgs = {}; + }; }; # end nixosConfigurations # Home Manager (only) users diff --git a/modules/home-manager/hosts/smarthome/gene.nix b/modules/home-manager/hosts/smarthome/gene.nix new file mode 100644 index 0000000..2645578 --- /dev/null +++ b/modules/home-manager/hosts/smarthome/gene.nix @@ -0,0 +1,7 @@ +{ ... }: { + home.stateVersion = "24.05"; + imports = [ + ../../common/all-cli.nix + ../../common/all-linux.nix + ]; +} diff --git a/modules/hosts/nixos/smarthome/default.nix b/modules/hosts/nixos/smarthome/default.nix new file mode 100644 index 0000000..2e363e6 --- /dev/null +++ b/modules/hosts/nixos/smarthome/default.nix @@ -0,0 +1,53 @@ +{ pkgs-unstable, username, ... }: { + imports = [ # Include the results of the hardware scan. + ./disk-config.nix + ./hardware-configuration.nix + ../../../system/common/linux/restic.nix + ]; + + system.stateVersion = "24.05"; + + boot.loader.grub.enable = true; + + networking = { + firewall.allowedTCPPorts = [ + 22 # ssh + ]; + hostId = "aedb8615"; + useDHCP = false; + networkmanager.enable = false; + useNetworkd = true; + interfaces.ens18.ipv4.addresses = [{ + address = "192.168.22.23"; + prefixLength = 24; + }]; + }; + + services = { + esphome = { + enable = true; + package = pkgs-unstable.esphome; + address = "0.0.0.0"; + openFirewall = true; + port = 6052; + }; + qemuGuest.enable = true; + resolved.enable = true; + restic.backups.daily.paths = [ + "/var/lib/esphome" + ]; + }; + + users.users.${username} = { + isNormalUser = true; + description = "Gene Liverman"; + extraGroups = [ "wheel" ]; + hashedPassword = + linger = true; + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBjigwV0KnnaTnFmKjjvnULa5X+hvsy2FAlu+lUUY59f gene@rainbow-planet" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIp42X5DZ713+bgbOO+GXROufUFdxWo7NjJbGQ285x3N gene.liverman@ltnglobal.com" + ]; + }; +} + diff --git a/modules/hosts/nixos/smarthome/disk-config.nix b/modules/hosts/nixos/smarthome/disk-config.nix new file mode 100644 index 0000000..be92b4a --- /dev/null +++ b/modules/hosts/nixos/smarthome/disk-config.nix @@ -0,0 +1,56 @@ +# Example to create a bios compatible gpt partition +{ lib, ... }: +{ + disko.devices = { + disk.disk1 = { + device = lib.mkDefault "/dev/sda"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + name = "boot"; + size = "1M"; + type = "EF02"; + }; + esp = { + name = "ESP"; + size = "500M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + name = "root"; + size = "100%"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + }; + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + size = "100%FREE"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = [ + "defaults" + ]; + }; + }; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/modules/hosts/nixos/smarthome/hardware-configuration.nix b/modules/hosts/nixos/smarthome/hardware-configuration.nix new file mode 100644 index 0000000..e7f5c2d --- /dev/null +++ b/modules/hosts/nixos/smarthome/hardware-configuration.nix @@ -0,0 +1,15 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ lib, modulesPath, ... }: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +}