Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to customize devcontainers #484

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"image": "ghcr.io/cachix/devenv:latest",
"overrideCommand": false,
"customizations": {
"vscode": {
"extensions": ["mkhl.direnv"]
"extensions": [
"bbenoist.Nix"
]
}
}
},
"image": "ghcr.io/cachix/devenv:latest",
"overrideCommand": false,
"updateContentCommand": "devenv ci"
}
1 change: 1 addition & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
languages.python.venv.enable = true;

devcontainer.enable = true;
devcontainer.settings.customizations.vscode.extensions = [ "bbenoist.Nix" ];
difftastic.enable = true;

# bin/mkdocs serve --config-file mkdocs.insiders.yml
Expand Down
58 changes: 47 additions & 11 deletions src/modules/integrations/devcontainer.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
{ pkgs, lib, config, ... }:

let
file = pkgs.writeText "devcontainer.json" ''
{
"image": "ghcr.io/cachix/devenv:latest",
"overrideCommand": false,
"customizations": {
"vscode": {
"extensions": ["mkhl.direnv"]
}
}
}
'';
cfg = config.devcontainer;
settingsFormat = pkgs.formats.json { };
file = settingsFormat.generate "devcontainer.json" cfg.settings;
in
{
options.devcontainer = {
enable = lib.mkEnableOption "generation .devcontainer.json for devenv integration";

settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;

options.image = lib.mkOption {
type = lib.types.str;
default = "ghcr.io/cachix/devenv:latest";
description = lib.mdDoc ''
The name of an image in a container registry.
'';
};

options.overrideCommand = lib.mkOption {
type = lib.types.anything;
default = false;
description = lib.mdDoc ''
Override the default command.
'';
};

options.updateContentCommand = lib.mkOption {
type = lib.types.anything;
default = "devenv ci";
description = lib.mdDoc ''
Command to run after container creation.
'';
};

options.customizations.vscode.extensions = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "mkhl.direnv" ];
description = lib.mdDoc ''
List of preinstalled VSCode extensions.
'';
};
};

default = { };

description = lib.mdDoc ''
Devcontainer settings.
'';
};
};

config = lib.mkIf config.devcontainer.enable {
Expand Down