mkModule code-server

This commit is contained in:
mjallen18
2025-12-15 09:17:26 -06:00
parent 5c9a42fe71
commit 03b00c59b2
4 changed files with 29 additions and 100 deletions

View File

@@ -122,6 +122,10 @@ rec {
port = mkOpt types.int 80 "Port for ${name} redis to be hosted on"; port = mkOpt types.int 80 "Port for ${name} redis to be hosted on";
}; };
hashedPassword = mkOpt (types.nullOr types.str) "$y$j9T$EkPXmsmIMFFZ.WRrBYCxS1$P0kwo6e4.WM5DsqUcEqWC3MrZp5KfCjxffraMFZWu06" "Hashed password for code-server authentication";
extraEnvironment = mkOpt (types.attrsOf types.str) { } "Extra environment variables for code-server";
reverseProxy = mkReverseProxyOpt; reverseProxy = mkReverseProxyOpt;
} }
// options; // options;

View File

@@ -6,32 +6,32 @@
}: }:
with lib; with lib;
let let
cfg = config.${namespace}.services.code-server; name = "code-server";
in cfg = config.${namespace}.services.${name};
{
imports = [ ./options.nix ];
config = mkIf cfg.enable { codeServerConfig = lib.${namespace}.mkModule {
# Configure the standard NixOS code-server service inherit config name;
services.code-server = { description = "vscode server";
enable = true; options = { };
port = cfg.port; moduleConfig = {
user = cfg.user; # Configure the standard NixOS code-server service
group = cfg.group; services.code-server = {
host = cfg.host; enable = true;
auth = cfg.auth; port = cfg.port;
disableTelemetry = cfg.disableTelemetry; user = "nix-apps";
disableUpdateCheck = cfg.disableUpdateCheck; group = "jallen-nas";
extraEnvironment = cfg.extraEnvironment; host = cfg.listenAddress;
} auth = "none"; # "password"
// optionalAttrs (cfg.hashedPassword != null) { disableTelemetry = true;
hashedPassword = cfg.hashedPassword; disableUpdateCheck = true;
}; extraEnvironment = cfg.extraEnvironment;
}
# Open firewall for code-server if enabled // optionalAttrs (cfg.hashedPassword != null) {
networking.firewall = mkIf cfg.openFirewall { hashedPassword = cfg.hashedPassword;
allowedTCPPorts = [ cfg.port ]; };
allowedUDPPorts = [ cfg.port ];
}; };
}; };
in
{
imports = [ codeServerConfig ];
} }

View File

@@ -1,70 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.code-server = {
enable = mkEnableOption "code-server with enhanced configuration";
port = mkOption {
type = types.port;
default = 4444;
description = "Port for code-server";
};
openFirewall = mkOption {
type = types.bool;
default = true;
description = "Whether to open firewall for code-server";
};
user = mkOption {
type = types.str;
default = "admin";
description = "User to run code-server as";
};
group = mkOption {
type = types.str;
default = "users";
description = "Group to run code-server as";
};
host = mkOption {
type = types.str;
default = "0.0.0.0";
description = "Host to bind code-server to";
};
auth = mkOption {
type = types.enum [
"none"
"password"
];
default = "none";
description = "Authentication method for code-server";
};
hashedPassword = mkOption {
type = types.nullOr types.str;
default = null;
description = "Hashed password for code-server authentication";
};
extraEnvironment = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Extra environment variables for code-server";
};
disableTelemetry = mkOption {
type = types.bool;
default = true;
description = "Whether to disable telemetry";
};
disableUpdateCheck = mkOption {
type = types.bool;
default = true;
description = "Whether to disable update checks";
};
};
}

View File

@@ -52,11 +52,6 @@ in
code-server = { code-server = {
enable = true; enable = true;
port = 4444; port = 4444;
user = "admin";
group = "jallen-nas";
host = "0.0.0.0";
auth = "none";
hashedPassword = "$y$j9T$EkPXmsmIMFFZ.WRrBYCxS1$P0kwo6e4.WM5DsqUcEqWC3MrZp5KfCjxffraMFZWu06";
extraEnvironment = { extraEnvironment = {
PROXY_DOMAIN = "code.mjallen.dev"; PROXY_DOMAIN = "code.mjallen.dev";
}; };