forked from mirrors/nixpkgs
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
140 lines
3.8 KiB
Nix
140 lines
3.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
let
|
|
|
|
cfg = config.services.code-server;
|
|
defaultUser = "code-server";
|
|
defaultGroup = defaultUser;
|
|
|
|
in {
|
|
###### interface
|
|
options = {
|
|
services.code-server = {
|
|
enable = mkEnableOption "code-server";
|
|
|
|
package = mkOption {
|
|
default = pkgs.code-server;
|
|
defaultText = "pkgs.code-server";
|
|
description = lib.mdDoc "Which code-server derivation to use.";
|
|
type = types.package;
|
|
};
|
|
|
|
extraPackages = mkOption {
|
|
default = [ ];
|
|
description = lib.mdDoc "Packages that are available in the PATH of code-server.";
|
|
example = "[ pkgs.go ]";
|
|
type = types.listOf types.package;
|
|
};
|
|
|
|
extraEnvironment = mkOption {
|
|
type = types.attrsOf types.str;
|
|
description =
|
|
lib.mdDoc "Additional environment variables to passed to code-server.";
|
|
default = { };
|
|
example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
|
|
};
|
|
|
|
extraArguments = mkOption {
|
|
default = [ "--disable-telemetry" ];
|
|
description = lib.mdDoc "Additional arguments that passed to code-server";
|
|
example = ''[ "--verbose" ]'';
|
|
type = types.listOf types.str;
|
|
};
|
|
|
|
host = mkOption {
|
|
default = "127.0.0.1";
|
|
description = lib.mdDoc "The host-ip to bind to.";
|
|
type = types.str;
|
|
};
|
|
|
|
port = mkOption {
|
|
default = 4444;
|
|
description = lib.mdDoc "The port where code-server runs.";
|
|
type = types.port;
|
|
};
|
|
|
|
auth = mkOption {
|
|
default = "password";
|
|
description = lib.mdDoc "The type of authentication to use.";
|
|
type = types.enum [ "none" "password" ];
|
|
};
|
|
|
|
hashedPassword = mkOption {
|
|
default = "";
|
|
description =
|
|
lib.mdDoc "Create the password with: 'echo -n 'thisismypassword' | npx argon2-cli -e'.";
|
|
type = types.str;
|
|
};
|
|
|
|
user = mkOption {
|
|
default = defaultUser;
|
|
example = "yourUser";
|
|
description = lib.mdDoc ''
|
|
The user to run code-server as.
|
|
By default, a user named `${defaultUser}` will be created.
|
|
'';
|
|
type = types.str;
|
|
};
|
|
|
|
group = mkOption {
|
|
default = defaultGroup;
|
|
example = "yourGroup";
|
|
description = lib.mdDoc ''
|
|
The group to run code-server under.
|
|
By default, a group named `${defaultGroup}` will be created.
|
|
'';
|
|
type = types.str;
|
|
};
|
|
|
|
extraGroups = mkOption {
|
|
default = [ ];
|
|
description =
|
|
lib.mdDoc "An array of additional groups for the `${defaultUser}` user.";
|
|
example = [ "docker" ];
|
|
type = types.listOf types.str;
|
|
};
|
|
|
|
};
|
|
};
|
|
|
|
###### implementation
|
|
config = mkIf cfg.enable {
|
|
systemd.services.code-server = {
|
|
description = "VSCode server";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network-online.target" ];
|
|
path = cfg.extraPackages;
|
|
environment = {
|
|
HASHED_PASSWORD = cfg.hashedPassword;
|
|
} // cfg.extraEnvironment;
|
|
serviceConfig = {
|
|
ExecStart = "${cfg.package}/bin/code-server --bind-addr ${cfg.host}:${toString cfg.port} --auth ${cfg.auth} " + builtins.concatStringsSep " " cfg.extraArguments;
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
RuntimeDirectory = cfg.user;
|
|
User = cfg.user;
|
|
Group = cfg.group;
|
|
Restart = "on-failure";
|
|
};
|
|
|
|
};
|
|
|
|
users.users."${cfg.user}" = mkMerge [
|
|
(mkIf (cfg.user == defaultUser) {
|
|
isNormalUser = true;
|
|
description = "code-server user";
|
|
inherit (cfg) group;
|
|
})
|
|
{
|
|
packages = cfg.extraPackages;
|
|
inherit (cfg) extraGroups;
|
|
}
|
|
];
|
|
|
|
users.groups."${defaultGroup}" = mkIf (cfg.group == defaultGroup) { };
|
|
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ stackshadow ];
|
|
}
|