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

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