headplane_headscale_nix/headplane.nix.original

115 lines
3.6 KiB
Plaintext

{ config, pkgs, ... }:
let
domain = "kennys.mom";
headplanePort = 3000; # Adjusted to match your configuration
headplaneDir = "/opt/headplane"; # Directory to store the project
configYamlPath = "/etc/headplane/config/headplane.yaml"; # Path to the generated config YAML
headscaleConfigPath = "/var/lib/headscale/config.yaml"; # Default path for Headscale config
cookieSecret = "iQ0bUyaFgwaijWaSyZ1ILA9RwfywrbZ3";
# Define the structure of the YAML file data
yamlData = {
server = {
host = "0.0.0.0";
port = headplanePort;
cookie_secret = cookieSecret;
cookie_secure = false;
};
headscale = {
url = "https://headscale.${domain}";
config_path = headscaleConfigPath;
config_strict = true;
};
integration = {
proc = {
enabled = true;
};
};
};
# Define a YAML format for generating the configuration
settingsFormat = pkgs.formats.yaml { };
# Generate the headplane.yaml file using the settings format
configFile = settingsFormat.generate "headplane.yaml" yamlData;
# If you need to create another config file for CLI, you could do so here (optional)
# cliConfigFile = settingsFormat.generate "cli_config.yaml" cliData;
in
{
# Ensure the generated config file is placed in the correct location
environment.etc."headplane/config/headplane.yaml".source = configFile;
services = {
# NGINX configuration for Headplane
nginx = {
enable = true;
virtualHosts."headplane.${domain}" = {
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://localhost:${toString headplanePort}";
proxyWebsockets = true;
};
};
};
};
# Ensure the necessary directories exist
# systemd.tmpfiles.rules = [
# "d /etc/headplane/config 0755 root root" # Creating directory for headplane.yaml
# "d /opt/headplane 0755 root root" # Ensure the main directory for Headplane exists
# ];
# Systemd service for building, running, and managing Headplane
# systemd.services.headplane = {
# description = "Headplane Service";
# wantedBy = [ "multi-user.target" ];
# # Use a shell script to automate building and running Headplane
# # script = ''
# # # Clone Headplane repository if not already cloned
# # if [ ! -d "${headplaneDir}" ]; then
# # echo "CLONING REPO NOW";
# # git clone https://github.com/tale/headplane ${headplaneDir}
# # fi
# # cd ${headplaneDir}
# # # Install dependencies and build the project
# # ${pkgs.pnpm}/bin/pnpm install
# # ${pkgs.pnpm}/bin/pnpm build
# # # Start the Headplane server with the generated config
# # node build/headplane/server.js --config ${configYamlPath}
# # # ${pkgs.nodejs}/bin/node ${headplaneDir}/build/headplane/server.js --config ${configYamlPath}
# # '';
# # serviceConfig = {
# # Restart = "always"; # Ensure the service is always running
# # User = "headplane"; # You may need to create this user (e.g., `useradd headplane`)
# # Group = "headplane"; # Same for the group
# # WorkingDirectory = headplaneDir;
# # ExecStart = "${pkgs.nodejs}/bin/node ${headplaneDir}/build/server/index.js --config ${configYamlPath}";
# # };
# };
# Optional: Ensure we have necessary dependencies like Node.js, pnpm, etc.
# environment.systemPackages = with pkgs; [
# nodejs
# nodePackages.pnpm
# git
# ];
# # Create the headplane user and group
# users.groups.headplane = {};
# users.users.headplane = {
# isSystemUser = true;
# home = "/opt/headplane";
# group = "headplane";
# };
}