diff --git a/nixos-anywhere/digitalocean.nix b/nixos-anywhere/digitalocean.nix deleted file mode 100644 index b2d5eef..0000000 --- a/nixos-anywhere/digitalocean.nix +++ /dev/null @@ -1,70 +0,0 @@ -{ lib, modulesPath, ... }: -{ - imports = [ - "${modulesPath}/virtualisation/digital-ocean-config.nix" - ]; - - # do not use DHCP, as DigitalOcean provisions IPs using cloud-init - networking.useDHCP = lib.mkForce false; - - # Disables all modules that do not work with NixOS - services.cloud-init = { - enable = true; - network.enable = true; - settings = { - datasource_list = [ - "ConfigDrive" - "Digitalocean" - ]; - datasource.ConfigDrive = { }; - datasource.Digitalocean = { }; - # Based on https://github.com/canonical/cloud-init/blob/main/config/cloud.cfg.tmpl - cloud_init_modules = [ - "seed_random" - "bootcmd" - "write_files" - "growpart" - "resizefs" - "set_hostname" - "update_hostname" - # Not support on NixOS - #"update_etc_hosts" - # throws error - #"users-groups" - # tries to edit /etc/ssh/sshd_config - #"ssh" - "set_password" - ]; - cloud_config_modules = [ - "ssh-import-id" - "keyboard" - # doesn't work with nixos - #"locale" - "runcmd" - "disable_ec2_metadata" - ]; - ## The modules that run in the 'final' stage - cloud_final_modules = [ - "write_files_deferred" - "puppet" - "chef" - "ansible" - "mcollective" - "salt_minion" - "reset_rmc" - # install dotty agent fails - #"scripts_vendor" - "scripts_per_once" - "scripts_per_boot" - # /var/lib/cloud/scripts/per-instance/machine_id.sh has broken shebang - #"scripts_per_instance" - "scripts_user" - "ssh_authkey_fingerprints" - "keys_to_console" - "install_hotplug" - "phone_home" - "final_message" - ]; - }; - }; -} diff --git a/nixos-anywhere/configuration.nix b/nixos-anywhere/digitalocean/configuration.nix similarity index 74% rename from nixos-anywhere/configuration.nix rename to nixos-anywhere/digitalocean/configuration.nix index d08fd58..ad496c8 100644 --- a/nixos-anywhere/configuration.nix +++ b/nixos-anywhere/digitalocean/configuration.nix @@ -20,9 +20,4 @@ pkgs.dig ]; - myModules = { - # Disable standard cloud-init, use nixos-anywhere special cloud-init instead - cloud-init.enable = false; - do-agent.enable = true; - }; } diff --git a/nixos-anywhere/digitalocean/default.nix b/nixos-anywhere/digitalocean/default.nix new file mode 100644 index 0000000..7e4a8ba --- /dev/null +++ b/nixos-anywhere/digitalocean/default.nix @@ -0,0 +1,77 @@ +{ lib, modulesPath, ... }: +{ + imports = [ + "${modulesPath}/virtualisation/digital-ocean-config.nix" + ./configuration.nix + ]; + + myModules = { + # Disable standard cloud-init, use nixos-anywhere special cloud-init instead + cloud-init.enable = false; + do-agent.enable = true; + }; + + # do not use DHCP, as DigitalOcean provisions IPs using cloud-init + networking.useDHCP = lib.mkForce false; + + # Disables all modules that do not work with NixOS + services.cloud-init = { + enable = true; + network.enable = true; + settings = { + datasource_list = [ + "ConfigDrive" + "Digitalocean" + ]; + datasource.ConfigDrive = { }; + datasource.Digitalocean = { }; + # Based on https://github.com/canonical/cloud-init/blob/main/config/cloud.cfg.tmpl + cloud_init_modules = [ + "seed_random" + "bootcmd" + "write_files" + "growpart" + "resizefs" + "set_hostname" + "update_hostname" + # Not support on NixOS + #"update_etc_hosts" + # throws error + #"users-groups" + # tries to edit /etc/ssh/sshd_config + #"ssh" + "set_password" + ]; + cloud_config_modules = [ + "ssh-import-id" + "keyboard" + # doesn't work with nixos + #"locale" + "runcmd" + "disable_ec2_metadata" + ]; + ## The modules that run in the 'final' stage + cloud_final_modules = [ + "write_files_deferred" + "puppet" + "chef" + "ansible" + "mcollective" + "salt_minion" + "reset_rmc" + # install dotty agent fails + #"scripts_vendor" + "scripts_per_once" + "scripts_per_boot" + # /var/lib/cloud/scripts/per-instance/machine_id.sh has broken shebang + #"scripts_per_instance" + "scripts_user" + "ssh_authkey_fingerprints" + "keys_to_console" + "install_hotplug" + "phone_home" + "final_message" + ]; + }; + }; +} diff --git a/nixos-anywhere/digitalocean/disk-config.nix b/nixos-anywhere/digitalocean/disk-config.nix new file mode 100644 index 0000000..f5d3b94 --- /dev/null +++ b/nixos-anywhere/digitalocean/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" + ]; + }; + }; + }; + }; + }; + }; +} diff --git a/nixos-anywhere/disk-config.nix b/nixos-anywhere/disk-config.nix deleted file mode 100644 index 75ae234..0000000 --- a/nixos-anywhere/disk-config.nix +++ /dev/null @@ -1,56 +0,0 @@ -# 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" - ]; - }; - }; - }; - }; - }; - }; -} diff --git a/nixos-anywhere/flake.nix b/nixos-anywhere/flake.nix index f7f894c..07cfa8b 100644 --- a/nixos-anywhere/flake.nix +++ b/nixos-anywhere/flake.nix @@ -42,8 +42,7 @@ # tested with 2GB/2CPU droplet, 1GB droplets do not have enough RAM for kexec nixosConfigurations.digitalocean = nixpkgs.lib.nixosSystem { modules = [ - ./configuration.nix - ./digitalocean.nix + ./digitalocean disko.nixosModules.disko { disko.devices.disk.disk1.device = "/dev/vda"; } home-manager.nixosModules.home-manager { @@ -71,5 +70,34 @@ }; system = "${system}"; }; + nixosConfigurations.nocix = nixpkgs.lib.nixosSystem { + modules = [ + ../modules + ../users + ./nocix + disko.nixosModules.disko + home-manager.nixosModules.home-manager { + home-manager.extraSpecialArgs = { inherit configFiles; }; + home-manager.sharedModules = [ + nixvim.homeManagerModules.nixvim + ../modules/home/nixvim.nix + ]; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + } + sops-nix.nixosModules.sops { + sops = { + age.generateKey = true; + age.keyFile = "/var/libs/sops-nix/key.txt"; + age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ]; + defaultSopsFile = ./secrets/secrets.yaml; + }; + } + ]; + specialArgs = { + inherit configFiles; + }; + system = "${system}"; + }; }; } diff --git a/nixos-anywhere/nocix/configuration.nix b/nixos-anywhere/nocix/configuration.nix new file mode 100644 index 0000000..a7fd7b7 --- /dev/null +++ b/nixos-anywhere/nocix/configuration.nix @@ -0,0 +1,36 @@ +{ + modulesPath, + lib, + pkgs, + ... +} @ args: +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + (modulesPath + "/profiles/qemu-guest.nix") + ./disk-config.nix + ]; + boot.loader.grub = { + # no need to set devices, disko will add all devices that have a EF02 partition to the list already + # devices = [ ]; + efiSupport = true; + efiInstallAsRemovable = true; + }; + environment.systemPackages = map lib.lowPrio [ + pkgs.dig + ]; + networking = { + defaultGateway = { + address = "107.150.59.201"; + interface = "enp2s0"; + }; + interfaces.enp2s0 = { + ipv4.addresses = [{ + address = "107.150.59.202"; + prefixLength = 29; + }]; + }; + nameservers = ["192.187.107.16"]; + search = ["nocix.net"]; + }; +} diff --git a/nixos-anywhere/nocix/default.nix b/nixos-anywhere/nocix/default.nix new file mode 100644 index 0000000..246ffea --- /dev/null +++ b/nixos-anywhere/nocix/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./configuration.nix + ./hardware-configuration.nix + ]; +} diff --git a/nixos-anywhere/nocix/disk-config.nix b/nixos-anywhere/nocix/disk-config.nix new file mode 100644 index 0000000..f5d3b94 --- /dev/null +++ b/nixos-anywhere/nocix/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" + ]; + }; + }; + }; + }; + }; + }; +} diff --git a/nixos-anywhere/nocix/hardware-configuration.nix b/nixos-anywhere/nocix/hardware-configuration.nix new file mode 100644 index 0000000..b28296a --- /dev/null +++ b/nixos-anywhere/nocix/hardware-configuration.nix @@ -0,0 +1,18 @@ +# 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. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "ahci" "ohci_pci" "ehci_pci" "xhci_pci" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +}