diff --git a/nixos/22.05/capsul-init b/nixos/22.05/capsul-init index 2b29897..fdef65d 100644 --- a/nixos/22.05/capsul-init +++ b/nixos/22.05/capsul-init @@ -5,7 +5,7 @@ homedir="/home/$user" mkdir -p "$homedir/.ssh" chmod 700 "$homedir/.ssh" -chown "$user" "$homedir/.ssh" +chown -R "$user:$user" "$homedir" mount -t iso9660 -o ro /dev/sr0 /mnt @@ -13,38 +13,9 @@ grep '\- ssh' /mnt/user-data | cut -d ' ' -f 8- > "$homedir/.ssh/authorized_key chmod 600 "$homedir/.ssh/authorized_keys" -chown "$user" "$homedir/.ssh/authorized_keys" +chown "$user:$user" "$homedir/.ssh/authorized_keys" /run/current-system/profile/sbin/resize2fs /dev/vda2 -cat < /etc/configuration.nix -{ config, pkgs, ... }: - -{ - imports = [ - ./hardware-configuration.nix - ]; - - # we always want git and vim - environment.systemPackages = with pkgs; [ - git - vim - ]; - - boot.loader.grub.enable = true; - boot.loader.grub.version = 2; - boot.loader.grub.device = "/dev/vda"; - system.stateVersion = "22.05"; - - users.users.cyberian = { - isNormalUser = true; - }; - - services.openssh = { - enable = true; - }; -EOF - umount /mnt rm /root/capsul-init -sudo nixos-rebuild switch diff --git a/nixos/22.05/configuration.nix b/nixos/22.05/configuration.nix index d5c9120..257ba17 100644 --- a/nixos/22.05/configuration.nix +++ b/nixos/22.05/configuration.nix @@ -1,3 +1,6 @@ +# this configuration is intended to give us ssh +# access to the build machine + { config, pkgs, ... }: { @@ -5,10 +8,10 @@ ./hardware-configuration.nix ]; - # we always want git and vim + # we always want nano & vi environment.systemPackages = with pkgs; [ - git - vim + vi + nano ]; boot.loader.grub.enable = true; @@ -18,7 +21,6 @@ users.users.cyberian = { isNormalUser = true; - password = "password"; }; users.users.root.password = "password"; @@ -27,16 +29,4 @@ permitRootLogin = "yes"; passwordAuthentication = true; }; - - # Feel free to remove this after first boot - # /root/capsul-init gets deleted after first run - systemd.services.capsul-init = { - serviceConfig.Type = "oneshot"; - unitConfig = { - ConditionPathExists = "/root/capsul-init"; - }; - serviceConfig = { - ExecStart = "/root/capsul-init"; - }; - }; } diff --git a/nixos/22.05/final-configuration.nix b/nixos/22.05/final-configuration.nix new file mode 100644 index 0000000..ddb46ce --- /dev/null +++ b/nixos/22.05/final-configuration.nix @@ -0,0 +1,43 @@ +# this configuration is meant to be the final +# handed over to the user + +{ config, pkgs, ... }: + +{ + imports = [ + ./hardware-configuration.nix + ]; + + # we always want nano & vi + environment.systemPackages = with pkgs; [ + nano + vi + ]; + + boot.loader.grub.enable = true; + boot.loader.grub.version = 2; + boot.loader.grub.device = "/dev/vda"; + system.stateVersion = "22.05"; + + users.users.cyberian = { + isNormalUser = true; + }; + + services.openssh = { + enable = true; + }; + + # Feel free to remove this after first boot + # /root/capsul-init gets deleted after first run + systemd.services.capsul-init = { + enable = true; + unitConfig = { + ConditionPathExists = "/root/capsul-init"; + }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "/root/capsul-init"; + }; + wantedBy = [ "multi-user.target" ]; + }; +} diff --git a/nixos/22.05/packer.json b/nixos/22.05/packer.json index f75fa52..d48ac78 100644 --- a/nixos/22.05/packer.json +++ b/nixos/22.05/packer.json @@ -30,11 +30,11 @@ "inline": ["echo 'executing trigger-reboot...' && /tmp/trigger-reboot & exit 0"], "expect_disconnect": true }, - { - "type": "shell", - "inline": ["echo 'reconnected after rebooting'"], - "pause_before": "30s" - }, + { + "type": "shell", + "inline": ["echo 'reconnected after rebooting'"], + "pause_before": "30s" + }, { "type": "file", "source": "capsul-init", @@ -43,9 +43,22 @@ { "type": "shell", "inline": [ - "mv /tmp/capsul-init /root/capsul-init", - "chmod +x /root/capsul-init" - ] + "mv /tmp/capsul-init /root/capsul-init", + "chmod +x /root/capsul-init" + ] + }, + { + "type": "file", + "source": "final-configuration.nix", + "destination": "/etc/nixos/configuration.nix" + }, + { + "type": "shell", + "inline": [ + "nixos-rebuild switch", + "rm -f /etc/ssh/*key*", + "printf '' > /etc/machine-id" + ] } ], "builders": [ diff --git a/nixos/22.05/post-install.sh b/nixos/22.05/post-install.sh index 7ff7fef..10c9843 100755 --- a/nixos/22.05/post-install.sh +++ b/nixos/22.05/post-install.sh @@ -1,6 +1,5 @@ #!/bin/sh -sudo su parted -s --align=none /dev/vda mktable gpt mkpart primary ext2 0 2MB mkpart primary ext2 2MB 100% set 1 bios_grub on mkfs.ext4 -L root /dev/vda2 mount LABEL=root /mnt diff --git a/nixos/OWNERS b/nixos/OWNERS new file mode 100644 index 0000000..4f10b4f --- /dev/null +++ b/nixos/OWNERS @@ -0,0 +1 @@ +@aynish:sealight.xyz