diff --git a/.devcontainer.json b/.devcontainer.json index 4a7005ffd..e76098216 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -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" } diff --git a/devenv.nix b/devenv.nix index da2443964..1b0a1506c 100644 --- a/devenv.nix +++ b/devenv.nix @@ -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 diff --git a/src/modules/integrations/devcontainer.nix b/src/modules/integrations/devcontainer.nix index 846b6eee8..239bc2142 100644 --- a/src/modules/integrations/devcontainer.nix +++ b/src/modules/integrations/devcontainer.nix @@ -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 {