User Tools

Site Tools


manuals:vps:userdata

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
manuals:vps:userdata [2025/03/14 20:31] – created aithermanuals:vps:userdata [2026/07/12 20:30] (current) – Annotate vpsAdmin navigation paths and update interface labels aither
Line 1: Line 1:
 ====== User Data ====== ====== User Data ======
-When creating or reinstalling a VPS, vpsAdmin can upload a script or configuration for [[https://cloud-init.io/|cloud-init]] into the VPS. This script or configuration is applied on the first startup of the VPS. We support three formats for the initial configuration:+When creating or reinstalling a VPS, vpsAdmin can upload a script or configuration for [[https://cloud-init.io/|cloud-init]] into the VPS. This script or configuration is applied on the first startup of the VPS. We support these formats for the initial configuration:
  
   * [[#script|script]]   * [[#script|script]]
   * [[#cloud-init_config|cloud-init config]]   * [[#cloud-init_config|cloud-init config]]
   * [[#cloud-init_script|cloud-init script]]   * [[#cloud-init_script|cloud-init script]]
 +  * [[#nixos_configuration|NixOS configuration]]
 +  * [[#nixos_flake_configuration|NixOS flake configuration]]
 +  * [[#nixos_flake_uri|NixOS flake URI]]
  
-Scripts and configurations can be stored in vpsAdmin, and you can select the configuration method when creating/reinstalling a VPS. You can manage stored configurations in vpsAdmin under **VPS** -> **User data**, or **Edit profile** -> **User data**. Alternatively, you can provide a configuration directly during the creation/reinstallation of a VPS without saving it in vpsAdmin. Saving configurations is optional but can simplify repeated use of unchanged configurations.+Scripts and configurations can be stored in vpsAdmin, and you can select the configuration method when creating/reinstalling a VPS. You can manage stored configurations in vpsAdmin under <vpsadmin-nav id="userdata.manage-vps.open">**VPS** -> **User data**</vpsadmin-nav>, or <vpsadmin-nav id="userdata.manage-profile.open">**Edit profile** -> **User data**</vpsadmin-nav>. Alternatively, you can provide a configuration directly during the creation/reinstallation of a VPS without saving it in vpsAdmin. Saving configurations is optional but can simplify repeated use of unchanged configurations.
  
 For development and testing, you can deploy a stored configuration to a VPS at any time: For development and testing, you can deploy a stored configuration to a VPS at any time:
-**vpsAdmin** -> **VPS** -> **User data** -> Edit an entry from the list, then use the **Deploy to VPS** form.+<vpsadmin-nav id="userdata.deploy.open">**vpsAdmin** -> **VPS** -> **User data** -> Edit an entry from the list, then use the **Deploy to VPS** form</vpsadmin-nav>. This action will only create the script/configuration files inside the VPS, it will not run/apply 
 +it.
  
 ===== Configuration Formats ===== ===== Configuration Formats =====
Line 67: Line 71:
  
 The cloud-init output can be seen in the kernel log and is stored in ''/var/log/cloud-init-output.log''. The cloud-init output can be seen in the kernel log and is stored in ''/var/log/cloud-init-output.log''.
 +
 +==== NixOS Configuration ====
 +The provided configuration is saved to ''/etc/vpsadmin-nixos/configuration.nix'' and upon VPS startup, the command ''nixos-rebuild switch'' is executed. Keep in mind that the provided configuration must import ''vpsadminos.nix'' or include it directly.
 +
 +Example configuration:
 +
 +<code nix>
 +{ config, pkgs, lib, ... }:
 +{
 +  imports = [
 +    /etc/nixos/vpsadminos.nix
 +  ];
 +
 +  environment.systemPackages = with pkgs; [
 +    vim
 +  ];
 +
 +  services.openssh.enable = true;
 +  services.openssh.settings.PermitRootLogin = "yes";
 +  #users.extraUsers.root.openssh.authorizedKeys.keys =
 +  #  [ "..." ];
 +
 +  systemd.extraConfig = ''
 +    DefaultTimeoutStartSec=900s
 +  '';
 +
 +  time.timeZone = "Europe/Amsterdam";
 +
 +  system.stateVersion = "24.11";
 +}
 +</code>
 +
 +The output of the ''nixos-rebuild'' command is stored in ''/var/log/vpsadmin-nixos-output.log''.
 +
 +==== NixOS Flake Configuration ====
 +The configuration is saved to the file ''/etc/vpsadmin-nixos/flake.nix'', and the command ''nixos-rebuild switch --flake /etc/vpsadmin-nixos#vps'' is executed. The configuration for the ''vps'' system must be included within the provided ''flake.nix''.
 +
 +Example configuration:
 +
 +<code nix>
 +{
 +  inputs = {
 +    nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11;
 +    vpsadminos.url = github:vpsfreecz/vpsadminos/staging;
 +  };
 +  
 +  outputs = { self, nixpkgs, vpsadminos }: {
 +    # The configuration must include a system named "vps"
 +    nixosConfigurations.vps = nixpkgs.lib.nixosSystem {
 +      modules = [
 +        ({ config, pkgs, lib, ... }:
 +        {
 +          imports = [
 +            vpsadminos.nixosConfigurations.container
 +          ];
 +
 +          environment.systemPackages = with pkgs; [
 +            vim
 +          ];
 +
 +          services.openssh.enable = true;
 +          services.openssh.settings.PermitRootLogin = "yes";
 +          #users.extraUsers.root.openssh.authorizedKeys.keys =
 +          #  [ "..." ];
 +
 +          systemd.extraConfig = ''
 +            DefaultTimeoutStartSec=900s
 +          '';
 +
 +          time.timeZone = "Europe/Amsterdam";
 +
 +          nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
 +
 +          system.stateVersion = "24.11";
 +        })
 +      ];
 +    };
 +  };
 +}
 +</code>
 +
 +The output of the ''nixos-rebuild'' command is stored in ''/var/log/vpsadmin-nixos-output.log''.
 +
 +==== NixOS Flake URI ====
 +Upon VPS startup, the command ''nixos-rebuild switch --flake $flake_uri'' is executed. This allows you to easily deploy a configuration that is publicly available, for example, on GitHub.
 +
 +Example configuration:
 +
 +<code nix>
 +github:vpsfreecz/example-vps-flake#vps
 +</code>
 +
 +You can find this configuration at https://github.com/vpsfreecz/example-vps-flake.
 +
 +The output of the ''nixos-rebuild'' command is stored in ''/var/log/vpsadmin-nixos-output.log''.
  
 ===== Usage with vpsfreectl ===== ===== Usage with vpsfreectl =====
Line 97: Line 196:
 vpsfreectl vps reinstall 123 -- --user-data-format script --user-data-content @my-script.sh vpsfreectl vps reinstall 123 -- --user-data-format script --user-data-content @my-script.sh
 </code> </code>
 +
 +===== Supported distributions =====
 +
 +All distributions are supported with the following exceptions:
 +
 +  * script is not supported on Guix, NixOS and Slackware
 +  * cloud-init is not supported on Guix, NixOS, Slackware and Void Linux
  
manuals/vps/userdata.1741984271.txt.gz · Last modified: by aither