diff --git a/configurations/nixos/hello/default.nix b/configurations/nixos/hello/default.nix new file mode 100644 index 0000000..27f4e2d --- /dev/null +++ b/configurations/nixos/hello/default.nix @@ -0,0 +1,19 @@ +{ flake, pkgs, ... }: + +let + inherit (flake) inputs; + inherit (inputs) self; +in +{ + nixos-unified.sshTarget = "srid@hello"; + + imports = [ + ../public-vm/configuration.nix + ]; + + networking.hostName = "hello"; + + environment.systemPackages = with pkgs; [ + neovim + ]; +} diff --git a/configurations/nixos/public-vm/configuration.nix b/configurations/nixos/public-vm/configuration.nix new file mode 100644 index 0000000..97ac6e7 --- /dev/null +++ b/configurations/nixos/public-vm/configuration.nix @@ -0,0 +1,27 @@ +{ flake, pkgs, ... }: + +let + inherit (flake) inputs; + inherit (inputs) self; +in +{ + imports = [ + "${inputs.nixpkgs}/nixos/modules/virtualisation/lxd-virtual-machine.nix" + (self + /modules/nixos/shared/primary-as-admin.nix) + ]; + + nixpkgs.hostPlatform = "x86_64-linux"; + services.openssh = { + enable = true; + settings.PasswordAuthentication = false; + }; + networking.firewall = { + enable = true; + allowedTCPPorts = [ 22 ]; + }; + + # Workaround the annoying `Failed to start Network Manager Wait Online` error on switch. + # https://github.com/NixOS/nixpkgs/issues/180175 + systemd.services.NetworkManager-wait-online.enable = false; + system.stateVersion = "24.11"; +} diff --git a/configurations/nixos/public-vm/default.nix b/configurations/nixos/public-vm/default.nix new file mode 100644 index 0000000..82f667e --- /dev/null +++ b/configurations/nixos/public-vm/default.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + imports = [ + ./configuration.nix + ]; + + + # Hello world service + services.nginx = { + enable = true; + # Return "Hello World" on / request + virtualHosts."_" = { + root = "${pkgs.writeTextDir "index.html" "Hello World"}"; + }; + }; + networking.firewall = { + allowedTCPPorts = [ 80 ]; + }; +} diff --git a/modules/flake-parts/incus-image.nix b/modules/flake-parts/incus-image.nix new file mode 100644 index 0000000..fff789d --- /dev/null +++ b/modules/flake-parts/incus-image.nix @@ -0,0 +1,18 @@ +{ inputs, ... }: { + perSystem = { pkgs, ... }: { + apps.incus-image-import.program = pkgs.writeShellApplication { + name = "incus-image-import"; + text = '' + NAME=$1 + + echo "Building image ... " + METADATA=$(nix build --no-link --print-out-paths ${inputs.self}#nixosConfigurations."$NAME".config.system.build.metadata)/tarball/ + IMG=$(nix build --no-link --print-out-paths ${inputs.self}#nixosConfigurations."$NAME".config.system.build.qemuImage)/nixos.qcow2 + + echo "Importing ... " + set -x + sudo incus image import --alias srid/"$NAME" "$METADATA"/*.tar.xz "$IMG" + ''; + }; + }; +}