344 Commits

Author SHA1 Message Date
Austin Horstman
0560d64401 generators: replace mkImpureConfigMerger targets atomically
The merge overwrote the target in place with `cat "$tmp" > path`, so a
crash mid-write could leave a truncated file, and an application that
saved its config while activation ran had that change silently
overwritten.

Snapshot the existing file, write the merged result to a temporary
file next to the resolved target, copy the existing mode (or apply
`mode` or the umask for a new file), and rename it into place. The
snapshot keeps the configured file name inside a temporary directory,
so a reader that detects the format from the extension still
recognizes it, even through a symlink to a differently named file.
Symlinked targets are written through and stay symlinks; a dangling
symlink creates its target, as the hand-written mergers this helper
replaced did. Activation fails without writing if the content, the
mode, or the symlink target changed since the snapshot, and refuses
targets inside the Nix store. A target that cannot be renamed over,
such as a file bind-mounted by impermanence, is written in place
instead. Temporary files are cleaned up by a trap scoped to a
subshell, since activation owns the top-level EXIT trap; this also
keeps the merge's shell variables out of the activation script.

The change check is not a lock: a write between the final check and
the rename is still lost. The documentation says so, along with the
attributes a rename does not preserve.

This follows the approach programs.vscode uses for its mutable user
settings.
2026-10-02 10:30:05 -05:00
Austin Horstman
3378835aa9 generators: add mode input to mkImpureConfigMerger
Some applications store tokens in the files these merges manage, such
as gh's hosts.yml or Docker's config.json, so callers need a way to
create them as 600.

The new optional `mode` input applies only when the target does not
exist yet; existing files keep their mode. By default it is null and a
new file gets the permissions shell redirection would give it under the
activation's umask, as the hand-written mergers this helper replaces
did, instead of a fixed 644. A value that is not an octal string fails
evaluation, rather than the first activation on a machine where the
file does not exist yet.
2026-10-02 10:30:05 -05:00
Austin Horstman
199871bf7e generators: document TOML date limitation in mkImpureConfigMerger
jaq 3.1.1 reads TOML through toml-span, which does not deserialize
date or time values. An existing TOML file containing one makes the
merge refuse, so activation fails on every switch until the value is
removed. The file itself is left untouched.

Document the limitation and test that the refused merge leaves the
file byte-identical. If a later jaq parses these values, they would
pass through JSON as strings, so the test is expected to fail then and
prompt a review of the documented behavior.
2026-10-02 09:41:18 -05:00
Austin Horstman
22970e1ddb generators: write merged YAML in block style
`jaq --to yaml -c` writes the merged configuration in one-line flow
style, so a user's block-style YAML came back as `{a: {b: [x]}}`. Drop
the compact flag for every non-JSON format: YAML is now written in
block style, while TOML, CBOR, and XML output are byte-identical with
and without it.

Document that comments and formatting are not preserved. Test the
exact block-style output with nested mappings and a list, and that
merging the written file again leaves it unchanged.
2026-10-02 09:41:18 -05:00
Austin Horstman
894214fea9 generators: print mkImpureConfigMerger paths literally
The dry-run message interpolated the configured path into a
double-quoted string, and the parse error embedded an escaped path
inside one. A path containing a command substitution was therefore
executed while printing the message. Quote each complete message as a
single shell argument, as the verbose message already does, and test
both messages with such a path.
2026-10-02 09:36:50 -05:00
Austin Horstman
03cb70e331 generators: remove impure config merger input size limit
Pass JSON documents to jaq through process substitution instead of
--argjson. Linux limits a single argument to 128 KiB, so merging an
existing configuration file or Nix-declared settings above that size
failed activation with "Argument list too long".

Require exactly one JSON value in each input before merging, so
multi-value streams are still rejected as they were with --argjson.
Keep the merge operation on its own line inside that filter so a
trailing comment in it cannot comment out the closing parenthesis, and
name the config file when the merge fails.

Add regression coverage for large existing files, large Nix-declared
settings, an operation ending in a comment, and byte-preserving
rejection of multiple JSON values.
2026-10-02 09:36:50 -05:00
Jairo Llopis
3c8cde701a generators: add mkImpureConfigMerger for runtime config merging
Add a reusable `lib.hm.generators.mkImpureConfigMerger` that generates a
bash snippet merging a Nix-generated config file into an existing user
config at activation time. It preserves interactive changes the user has
made while applying the Nix-declared settings on top.

The merge uses `jaq`, which handles JSON, YAML, TOML, and CBOR natively
through its `--from`/`--to` flags. An optional `reader` parameter allows
custom preprocessing, for example JSON5 files with comments.

The snippet follows the existing activation contract:

- `$DRY_RUN` prints what would be done and skips the merge entirely.
- `$VERBOSE` logs a merge message, customizable through `verboseMsg`.
- A missing or zero-byte file is treated as the `empty` value, kept in
  memory so the target is only created once the merge is serialized.
- An existing file that fails to parse aborts activation with an error
  instead of silently overwriting the user's settings with the generated
  defaults. The reader's exit status is checked because it can emit valid
  JSON before failing, as when jaq prints the first object of a truncated
  stream.
- The result is written to a temporary file and moved into place only
  after the merge succeeds. An existing file is overwritten in place to
  keep its permissions and symlink target; a new file is created with
  mode 644.

The helper is marked experimental: the activation contract edge cases are
still being discovered, so external flakes should pin this input.

Add a lib-level regression test covering the truncated-stream refusal
with byte preservation, first activation on missing JSON and TOML
targets, user-key preservation, and zero-byte files treated as empty.

Assisted-by: Goose + GLM 5.3 Flash
2026-10-02 03:07:18 -05:00
o-az
f0807df654 maintainers: add o-az 2026-09-30 16:47:55 +02:00
hectorgray
395ff18c63 maintainers: add hectorgray 2026-09-24 18:24:37 -05:00
Austin Horstman
e9796a288e lib/deprecations: name exact settings destinations
Forward converted values to the complete settings path so the standard
changed-option warning identifies the destination key. Preserve legacy
reads, priorities, defaults, and shadowed conversions.

Point mpdris2 at Library.music_dir directly and cover nested paths,
literal dotted keys, and the affected callers in warning tests. The
contributor guidelines now describe `to` as the settings path that
contains `key` instead of the settings root.
2026-09-23 22:37:57 -05:00
Austin Horstman
cfcda3f993 lib.deprecations: simplify settings migrations (#9953) 2026-09-13 21:18:31 -05:00
Drew Davis
fab877f9b2 maintainers: add typeparameter 2026-09-13 10:01:07 -05:00
Austin Horstman
fdc36b1280 lib/deprecations: use nixpkgs-style docstrings
Document helper inputs, return values, and examples in the library format. Clarify legacy alias declarations and state-version warning modes without changing executable Nix.
2026-09-12 23:16:50 -05:00
Austin Horstman
bdcb842903 lib/deprecations: preserve settings overlay definitions
Share raw overlay forwarding and effective-key detection for default-empty
legacy options. Keep application defaults and conversions in consumers.

Delegate aliases and diagnostics to doRename without rewrapping prepared
priorities. Cover ordering, composition, empty values, and source filenames
in the existing evaluations.
2026-09-12 23:16:50 -05:00
Austin Horstman
e16bc72cbb lib/deprecations: preserve ordered settings renames
Add opt-in ordered forwarding to the settings rename helper so legacy and canonical list definitions retain priorities and mkBefore/mkAfter ordering.

Keep the default helper path unchanged and cover evaluation in module scopes without a warnings option.
2026-09-12 23:16:50 -05:00
Austin Horstman
10d0acd7f8 lib.strings: move systemd escaping into strings
Reuse the existing strings category and keep the systemd-specific names explicit. Update the caller and test registration together.
2026-09-12 21:48:39 -05:00
Austin Horstman
eef2def9ee lib.systemd: tighten comments and test messages
Keep the escaping rationale and test failures concise without changing behavior.
2026-09-12 21:48:39 -05:00
Austin Horstman
9cc74ef628 lib.systemd: add Exec argument escaping helpers
Expose systemd-specific argument quoting without depending on NixOS utilities. Cover argument boundaries, substitutions, supported types, and string context.
2026-09-12 21:48:39 -05:00
Austin Horstman
73be48878b maintainers: remove libewa duplicate
The updated Nixpkgs pin includes libewa in lib.maintainers.
2026-09-11 22:23:22 -05:00
Robert Helgesson
8e89a2340a home-manager: optionally use putter for file management
The Putter tool is a Rust implementation of the file management
component of Home Manager. It takes a JSON manifest that indicates how
files should be symlinked and when the manifest is applied, does its
best to ensure that the file system reflect the manifest.

Putter offers some additional features that Home Manager does not
expose today, such as file copying (potentially recursive) and support
for overriding files within a recursive tree (e.g., inside a symlinked
tree one could ensure that a specific file is copies with specific
permissions).

This is considered highly experimental at the moment and to use Putter
one must set a hidden option.
2026-09-09 21:34:48 +02:00
Antonio Spadaro
f938f20731 firefoxpwa: add ilovelinux as maintainer 2026-09-05 18:46:00 -05:00
EKHH
29388c8114 maintainers: add ekhh 2026-09-01 21:50:53 -05:00
Austin Horstman
42c3fc301e maintainers: remove duplicate nixpkgs maintainers
Remove the Home Manager entries for nikp123 and rachitvrma now that nixpkgs provides them.
2026-08-22 01:19:16 -05:00
Austin Horstman
aac4965ddb antigravity-cli: use lib.hm.mcp.resolveEnabled for MCP server resolution
Export resolveEnabled from lib.hm.mcp and use it in antigravity-cli.
Add test cases for direct disabled and enabled declarations.
2026-08-16 20:11:26 -05:00
K900
0668fdbc15 treewide: stdenv.is* -> stdenv.hostPlatform.is*
Nixpkgs officialy deprecated the former.
2026-08-13 08:40:58 +02:00
Rachit Kumar Verma
c1b62f9b55 maintainers: update rachitvrma 2026-08-06 10:41:14 -05:00
Vidhan Bhatt
ff1741309e maintainers: add vidhanio
Add myself to the Home Manager maintainer list.
2026-08-05 10:43:29 -05:00
Rachit Kumar Verma
63bd543c9e maintainers: add rachitvrma 2026-08-05 10:21:22 -05:00
MithicSpirit
3d25fa94cf lib: option to escape tabs in lib.hm.generators.toKDL
Disabled by default for backwards compatibility.

Enabled for zellij and niri as per escapeBackslashes.
2026-07-28 15:16:56 -05:00
Austin Horstman
0df0df1aee maintainers: ckgxrg moved to nixpkgs
ckgxrg was added to nixpkgs by NixOS/nixpkgs@ff7b6221c0. Regenerating all-maintainers.nix also restores the existing glmlm entry missing from the generated file.
2026-07-28 12:55:08 -05:00
Austin Horstman
7a0f860e66 maintainers: rsahwe moved to nixpkgs
rsahwe was added to nixpkgs by NixOS/nixpkgs#509659:

44f87293db
2026-07-28 12:55:08 -05:00
glmlm
b8324779d1 wayland.windowManager.niri: add myself as module maintainer 2026-07-28 12:35:56 +02:00
Eman Resu
411408f523 lib/file-type: partially apply hasPrefix and removePrefix 2026-07-20 23:17:54 +02:00
reesilva
a1fc9a1cc3 maintainers: add reesilva 2026-07-08 17:33:28 -05:00
Austin Horstman
cf0c5c3e9f maintainers: drop duplicate yarn entry
Remove HM-only yarn maintainer definition and keep module references aligned with nixpkgs maintainer data.
2026-07-04 22:28:41 -05:00
_
d32537981c lib: escape backslash in lib.hm.generators.toKDL 2026-06-30 23:49:47 -05:00
Austin Horstman
9eec3ef087 maintainers: remove quoted names in set
Prefer underscore to match nixpkgs.
2026-06-29 11:12:43 -05:00
Austin Horstman
789a35fbde maintainers: remove duplicate maintainers 2026-06-28 22:04:23 -05:00
Eman Resu
0f4a317c06 lib.hm.dag: performance improvements
Avoid repeated attribute lookups and unnecessary intermediate allocations in
DAG helpers. Cache DAG names while normalizing before-edges to improve topoSort
performance on large DAGs.

Co-authored-by: Eman Resu <78693624+quatquatt@users.noreply.github.com>
2026-06-18 21:53:23 -05:00
Austin Horstman
6716d811e5 lib: add DAG-aware format generators
Add reusable Home Manager generator helpers for rendering freeform attrsets that contain lib.hm.dag entries.

This keeps ordering support available to JSON and future generated formats without forcing each module to carry its own DAG sorting boilerplate.
2026-06-18 07:59:18 -05:00
csanthiago
a20c21b2fe maintainers: add csanthiago
💘 Generated with Crush

Assisted-by: Crush:glm-5.2
2026-06-17 19:16:21 -05:00
Peter Bittner
bfc003171b maintainers: add bittner 2026-06-17 15:47:24 -05:00
Austin Horstman
ce68ac6958 lib/generators: short-circuit important-field check with any
toHyprconf' tested every important prefix with a non-strict foldl that
always scanned the full list. lib.any expresses the same any-prefix-matches
intent and stops at the first match. Runs once per attribute in the
Hyprland generator.
2026-06-17 13:04:43 -05:00
ErinaYip
7664e05e24 maintainers: add ErinaYip 2026-06-16 22:42:18 -05:00
superflash41
6cf5b64c12 maintainers: add superflash41 2026-06-10 09:48:41 -05:00
Malik
6a66db1360 mcp: extract helper functions into lib/mcp.nix
Extract MCP-related helper functions (renderEnv, mkEnvFilesWrapper,
wrapEnvFilesCommand, addType, transformMcpServer) into a new shared
library module at modules/lib/mcp.nix.
- Add lib.hm.mcp for sharing transformMcpServer logic across consumers
- Add enabled/disabled conflict detection assertion
- Add tests for new library functions
2026-06-09 23:03:52 -05:00
Austin Horstman
d33c97ec1b lib/strings: add isPathLike helper 2026-06-05 11:39:28 -05:00
Nikhil Singh
5fadbec07a maintainers: add semi710 2026-06-05 11:13:52 -05:00
Austin Horstman
5ded124f91 lib: add deprecated option warning helpers 2026-06-04 12:20:09 -05:00
Kays
a7c15f4f65 maintainers: add kayskayskays 2026-06-02 08:56:09 -05:00