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 [2025/03/16 14:08] (current) – [NixOS Flake URI] fix nixos-rebuild aither
Line 5: Line 5:
   * [[#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 **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.
Line 67: Line 70:
  
 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 195:
 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: 2025/03/14 20:31 by aither