From 5d3e8eea68e1fe5fd0796ea5fa8ea8f2e6e64cf4 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 2 Oct 2026 10:02:49 -0500 Subject: [PATCH] github-copilot-cli: write settings to settings.json Since Copilot CLI 1.0.35, user settings live in settings.json and config.json holds internal state. On startup, 1.0.88 moves user keys out of a Home Manager config.json into settings.json and rewrites config.json as a regular file, replacing the link, so the next switch collides on config.json. Link the declared settings as settings.json instead and stop managing config.json, including the firstLaunchAt workaround that only existed for it. A read-only settings.json link survives startup; Copilot CLI replaces it only when it saves a setting. Copilot CLI drops trusted_folders from settings.json and moves trustedFolders into its own state in config.json, rewriting settings.json and so replacing a linked file. Leave both keys out of the file, warn when either is set, and do not manage the file when they are the only settings. Document the canonical allowedUrls and deniedUrls names. The old config.json link is removed by linkGeneration when it still points into a generation; a regular file left by Copilot CLI stays for it to manage. The news entry and release note tell users whose Copilot CLI already wrote a regular settings.json to remove it before switching, since the new link would collide with it. --- docs/release-notes/rl-2611.md | 9 ++ .../misc/news/2026/10/2026-10-02_08-21-58.nix | 23 +++++ modules/programs/github-copilot-cli.nix | 42 ++++++--- .../programs/github-copilot-cli/config.nix | 87 ++++++++++--------- .../programs/github-copilot-cli/default.nix | 1 + .../github-copilot-cli/expected-config.json | 6 +- .../programs/github-copilot-cli/mcp.nix | 2 + .../github-copilot-cli/trusted-folders.nix | 22 +++++ .../github-copilot-cli/xdg-config-dir.nix | 7 +- 9 files changed, 136 insertions(+), 63 deletions(-) create mode 100644 modules/misc/news/2026/10/2026-10-02_08-21-58.nix create mode 100644 tests/modules/programs/github-copilot-cli/trusted-folders.nix diff --git a/docs/release-notes/rl-2611.md b/docs/release-notes/rl-2611.md index 020cf711e2..612cfad287 100644 --- a/docs/release-notes/rl-2611.md +++ b/docs/release-notes/rl-2611.md @@ -111,6 +111,15 @@ This release has the following notable changes: `sourceDirectories` and `patterns`, which allows native patterns and database-only backups. `repositories` is still required. +- [](#opt-programs.github-copilot-cli.settings) is now written to + `settings.json` instead of `config.json`, since Copilot CLI 1.0.35 and later + keep user settings there and replace a linked `config.json`. The old link is + removed on activation. If Copilot CLI already created a regular + `settings.json` from the old `config.json`, remove it before switching; + otherwise activation reports it as a collision. `trusted_folders` and + `trustedFolders` are no longer written, because Copilot CLI keeps trusted + folders in its own state; trust folders from Copilot CLI instead. + ## State Version Changes {#sec-release-26.11-state-version-changes} The state version in this release includes the changes below. These diff --git a/modules/misc/news/2026/10/2026-10-02_08-21-58.nix b/modules/misc/news/2026/10/2026-10-02_08-21-58.nix new file mode 100644 index 0000000000..d2110370e3 --- /dev/null +++ b/modules/misc/news/2026/10/2026-10-02_08-21-58.nix @@ -0,0 +1,23 @@ +{ config, ... }: +{ + time = "2026-10-02T08:21:58+00:00"; + condition = + config.programs.github-copilot-cli.enable && config.programs.github-copilot-cli.settings != { }; + message = '' + The option 'programs.github-copilot-cli.settings' is now written to + settings.json instead of config.json. Copilot CLI 1.0.35 and later read + user settings from settings.json and keep internal state in config.json, + moving declared settings out of a linked config.json and replacing the + link, which caused collisions on later activations. The old config.json + link is removed automatically if it still points to a Home Manager + generation; a regular file left by Copilot CLI stays for it to manage. + + If Copilot CLI already moved your settings into a regular settings.json, + remove that file before switching. Otherwise activation reports it as a + collision, or leaves it unmanaged when its content happens to match. + + 'trusted_folders' and 'trustedFolders' are no longer written, since + Copilot CLI keeps trusted folders in its own state. Trust folders from + Copilot CLI instead. + ''; +} diff --git a/modules/programs/github-copilot-cli.nix b/modules/programs/github-copilot-cli.nix index d6a5f7b53f..c19b3f27a3 100644 --- a/modules/programs/github-copilot-cli.nix +++ b/modules/programs/github-copilot-cli.nix @@ -17,6 +17,17 @@ let jsonFormat = pkgs.formats.json { }; + # Copilot CLI drops trusted_folders from settings.json and moves + # trustedFolders into its own state in config.json, rewriting settings.json + # and so replacing a linked file. A merged copy would also outlive its + # removal from Nix. + trustedFolderKeys = [ + "trusted_folders" + "trustedFolders" + ]; + userSettings = removeAttrs cfg.settings trustedFolderKeys; + settingsFile = jsonFormat.generate "github-copilot-cli-settings.json" userSettings; + upstreamConfigDir = "${config.home.homeDirectory}/.copilot"; # Applied after transformMcpServer so that args = [] is not filtered out. @@ -123,7 +134,7 @@ in example = literalExpression ''"''${config.xdg.configHome}/copilot"''; description = '' Directory holding Copilot CLI configuration files such as - {file}`config.json`, {file}`mcp-config.json`, + {file}`settings.json`, {file}`mcp-config.json`, {file}`lsp-config.json`, and {file}`copilot-instructions.md`. @@ -158,13 +169,17 @@ in example = { model = "claude-sonnet-4-5"; theme = "default"; - trusted_folders = [ "/home/user/projects" ]; renderMarkdown = true; autoUpdate = false; }; description = '' - Configuration written to {file}`config.json` inside - {option}`programs.github-copilot-cli.configDir`. + Configuration written to {file}`settings.json` inside + {option}`programs.github-copilot-cli.configDir`. Empty settings leave + the file unmanaged. + + Trusted folders (`trusted_folders`, `trustedFolders`) are not user + settings: Copilot CLI keeps them in its own state, so they are left + out of the file. Known configuration keys include: - `model` — AI model selection @@ -178,8 +193,7 @@ in - `stream` — token-by-token response streaming (default: `true`) - `includeCoAuthoredBy` — agent commit attribution (default: `true`) - `respectGitignore` — exclude gitignored files from file picker - - `trusted_folders` — list of pre-approved directory paths - - `allowed_urls`, `denied_urls` — URL allowlists/blocklists + - `allowedUrls`, `deniedUrls` — URL allowlists/blocklists - `logLevel` — log verbosity - `disableAllHooks` — global hook disable toggle - `hooks` — inline hook definitions @@ -409,15 +423,15 @@ in home.packages = mkIf (cfg.package != null) [ cfg.package ]; + warnings = lib.optional (lib.any (key: lib.hasAttr key cfg.settings) trustedFolderKeys) '' + programs.github-copilot-cli.settings: trusted_folders and trustedFolders + are not written to settings.json. Copilot CLI keeps trusted folders in + its own state; trust folders from Copilot CLI instead. + ''; + home.file = { - # NOTE: Copilot will try to add a firstLaunchAt date and crash if the - # file exists but does not have this key set. Only generate the file when - # the user has explicitly configured settings, and always inject the - # default so the managed file stays valid. - "${cfg.configDir}/config.json" = mkIf (cfg.settings != { }) { - source = jsonFormat.generate "github-copilot-cli-config.json" ( - { firstLaunchAt = "1970-01-01T00:00:00.000Z"; } // cfg.settings - ); + "${cfg.configDir}/settings.json" = mkIf (userSettings != { }) { + source = settingsFile; }; "${cfg.configDir}/mcp-config.json" = mkIf (mergedMcpServers != { }) { diff --git a/tests/modules/programs/github-copilot-cli/config.nix b/tests/modules/programs/github-copilot-cli/config.nix index 3469f36549..54a786ac87 100644 --- a/tests/modules/programs/github-copilot-cli/config.nix +++ b/tests/modules/programs/github-copilot-cli/config.nix @@ -1,4 +1,8 @@ -{ pkgs, ... }: +{ + config, + pkgs, + ... +}: let inlineAgent = '' --- @@ -38,7 +42,6 @@ in settings = { model = "claude-sonnet-4-5"; theme = "dark"; - trusted_folders = [ "/home/user/projects" ]; }; context = inlineContext; agents = { @@ -54,52 +57,54 @@ in }; }; - nmt.script = '' - assertFileExists home-files/.copilot/config.json - assertFileContent home-files/.copilot/config.json ${./expected-config.json} + nmt.script = + assert !(config.home.activation ? githubCopilotCliSettings); + '' + assertPathNotExists home-files/.copilot/config.json + assertFileContent home-files/.copilot/settings.json ${./expected-config.json} - assertFileExists home-files/.copilot/copilot-instructions.md - assertFileContent home-files/.copilot/copilot-instructions.md \ - ${builtins.toFile "expected-copilot-instructions.md" inlineContext} + assertFileExists home-files/.copilot/copilot-instructions.md + assertFileContent home-files/.copilot/copilot-instructions.md \ + ${builtins.toFile "expected-copilot-instructions.md" inlineContext} - assertFileExists home-files/.copilot/agents/inline-reviewer.agent.md - assertFileContent home-files/.copilot/agents/inline-reviewer.agent.md \ - ${builtins.toFile "expected-inline-reviewer.agent.md" inlineAgent} + assertFileExists home-files/.copilot/agents/inline-reviewer.agent.md + assertFileContent home-files/.copilot/agents/inline-reviewer.agent.md \ + ${builtins.toFile "expected-inline-reviewer.agent.md" inlineAgent} - assertFileExists home-files/.copilot/agents/path-reviewer.agent.md - assertLinkExists home-files/.copilot/agents/path-reviewer.agent.md - assertFileContent home-files/.copilot/agents/path-reviewer.agent.md \ - ${./agents/documentation.agent.md} + assertFileExists home-files/.copilot/agents/path-reviewer.agent.md + assertLinkExists home-files/.copilot/agents/path-reviewer.agent.md + assertFileContent home-files/.copilot/agents/path-reviewer.agent.md \ + ${./agents/documentation.agent.md} - assertFileExists home-files/.copilot/agents/store-reviewer.agent.md - assertLinkExists home-files/.copilot/agents/store-reviewer.agent.md - assertFileContent home-files/.copilot/agents/store-reviewer.agent.md \ - ${storeAgentSrc} + assertFileExists home-files/.copilot/agents/store-reviewer.agent.md + assertLinkExists home-files/.copilot/agents/store-reviewer.agent.md + assertFileContent home-files/.copilot/agents/store-reviewer.agent.md \ + ${storeAgentSrc} - assertFileExists home-files/.copilot/skills/inline-skill/SKILL.md - assertFileContent home-files/.copilot/skills/inline-skill/SKILL.md \ - ${builtins.toFile "expected-inline-skill.md" inlineSkill} + assertFileExists home-files/.copilot/skills/inline-skill/SKILL.md + assertFileContent home-files/.copilot/skills/inline-skill/SKILL.md \ + ${builtins.toFile "expected-inline-skill.md" inlineSkill} - assertFileExists home-files/.copilot/skills/path-skill/SKILL.md - assertLinkExists home-files/.copilot/skills/path-skill/SKILL.md - assertFileContent home-files/.copilot/skills/path-skill/SKILL.md \ - ${./test-skill.md} + assertFileExists home-files/.copilot/skills/path-skill/SKILL.md + assertLinkExists home-files/.copilot/skills/path-skill/SKILL.md + assertFileContent home-files/.copilot/skills/path-skill/SKILL.md \ + ${./test-skill.md} - assertFileExists home-files/.copilot/skills/dir-skill/SKILL.md - assertFileExists home-files/.copilot/skills/dir-skill/notes.txt - assertLinkExists home-files/.copilot/skills/dir-skill/SKILL.md - assertLinkExists home-files/.copilot/skills/dir-skill/notes.txt - assertFileContent home-files/.copilot/skills/dir-skill/SKILL.md \ - ${./skills/data-analysis/SKILL.md} - assertFileContent home-files/.copilot/skills/dir-skill/notes.txt \ - ${./skills/data-analysis/notes.txt} + assertFileExists home-files/.copilot/skills/dir-skill/SKILL.md + assertFileExists home-files/.copilot/skills/dir-skill/notes.txt + assertLinkExists home-files/.copilot/skills/dir-skill/SKILL.md + assertLinkExists home-files/.copilot/skills/dir-skill/notes.txt + assertFileContent home-files/.copilot/skills/dir-skill/SKILL.md \ + ${./skills/data-analysis/SKILL.md} + assertFileContent home-files/.copilot/skills/dir-skill/notes.txt \ + ${./skills/data-analysis/notes.txt} - assertFileExists home-files/.copilot/skills/store-skill/SKILL.md - assertLinkExists home-files/.copilot/skills/store-skill/SKILL.md - assertFileContent home-files/.copilot/skills/store-skill/SKILL.md \ - "${storeSkillSrc}/skills/external-skill/SKILL.md" + assertFileExists home-files/.copilot/skills/store-skill/SKILL.md + assertLinkExists home-files/.copilot/skills/store-skill/SKILL.md + assertFileContent home-files/.copilot/skills/store-skill/SKILL.md \ + "${storeSkillSrc}/skills/external-skill/SKILL.md" - assertPathNotExists home-files/.copilot/mcp-config.json - assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'COPILOT_HOME' - ''; + assertPathNotExists home-files/.copilot/mcp-config.json + assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'COPILOT_HOME' + ''; } diff --git a/tests/modules/programs/github-copilot-cli/default.nix b/tests/modules/programs/github-copilot-cli/default.nix index a507d5fc24..faa7325599 100644 --- a/tests/modules/programs/github-copilot-cli/default.nix +++ b/tests/modules/programs/github-copilot-cli/default.nix @@ -7,5 +7,6 @@ github-copilot-cli-path-not-directory = ./path-not-directory.nix; github-copilot-cli-store-path-dir = ./store-path-dir.nix; github-copilot-cli-store-path-skills = ./store-path-skills.nix; + github-copilot-cli-trusted-folders = ./trusted-folders.nix; github-copilot-cli-xdg-config-dir = ./xdg-config-dir.nix; } diff --git a/tests/modules/programs/github-copilot-cli/expected-config.json b/tests/modules/programs/github-copilot-cli/expected-config.json index d2f594c2f0..7ff4ce4d94 100644 --- a/tests/modules/programs/github-copilot-cli/expected-config.json +++ b/tests/modules/programs/github-copilot-cli/expected-config.json @@ -1,8 +1,4 @@ { - "firstLaunchAt": "1970-01-01T00:00:00.000Z", "model": "claude-sonnet-4-5", - "theme": "dark", - "trusted_folders": [ - "/home/user/projects" - ] + "theme": "dark" } diff --git a/tests/modules/programs/github-copilot-cli/mcp.nix b/tests/modules/programs/github-copilot-cli/mcp.nix index 7bd4c558f5..b9b3043e1b 100644 --- a/tests/modules/programs/github-copilot-cli/mcp.nix +++ b/tests/modules/programs/github-copilot-cli/mcp.nix @@ -20,5 +20,7 @@ assertFileExists home-files/.copilot/mcp-config.json assertFileContent home-files/.copilot/mcp-config.json ${./expected-mcp-config.json} assertPathNotExists home-files/.copilot/config.json + assertPathNotExists home-files/.copilot/settings.json + assertFileNotRegex activate 'githubCopilotCliSettings|github-copilot-cli-settings.json' ''; } diff --git a/tests/modules/programs/github-copilot-cli/trusted-folders.nix b/tests/modules/programs/github-copilot-cli/trusted-folders.nix new file mode 100644 index 0000000000..02f18bffea --- /dev/null +++ b/tests/modules/programs/github-copilot-cli/trusted-folders.nix @@ -0,0 +1,22 @@ +{ config, ... }: +{ + programs.github-copilot-cli = { + enable = true; + settings.trusted_folders = [ "/home/user/projects" ]; + }; + + test.asserts.warnings.expected = [ + '' + programs.github-copilot-cli.settings: trusted_folders and trustedFolders + are not written to settings.json. Copilot CLI keeps trusted folders in + its own state; trust folders from Copilot CLI instead. + '' + ]; + + nmt.script = + assert !(config.home.activation ? githubCopilotCliSettings); + '' + assertPathNotExists home-files/.copilot/settings.json + assertPathNotExists home-files/.copilot/config.json + ''; +} diff --git a/tests/modules/programs/github-copilot-cli/xdg-config-dir.nix b/tests/modules/programs/github-copilot-cli/xdg-config-dir.nix index 3dde2a190a..08925001d2 100644 --- a/tests/modules/programs/github-copilot-cli/xdg-config-dir.nix +++ b/tests/modules/programs/github-copilot-cli/xdg-config-dir.nix @@ -2,17 +2,18 @@ home.preferXdgDirectories = true; programs.github-copilot-cli = { enable = true; + package = null; context = ./context.md; settings = { model = "claude-sonnet-4-5"; theme = "dark"; - trusted_folders = [ "/home/user/projects" ]; }; }; nmt.script = '' - assertFileExists home-files/.config/copilot/config.json - assertFileContent home-files/.config/copilot/config.json ${./expected-config.json} + assertPathNotExists home-files/.config/copilot/config.json + assertFileContent home-files/.config/copilot/settings.json ${./expected-config.json} + assertPathNotExists home-files/.copilot/settings.json assertFileExists home-files/.config/copilot/copilot-instructions.md assertLinkExists home-files/.config/copilot/copilot-instructions.md assertFileContent home-files/.config/copilot/copilot-instructions.md \