Commit Graph

38 Commits

Author SHA1 Message Date
K900
ec69cf3f7b Revert "nixos/modular-services: add portable process.environment" 2026-07-25 10:19:30 +03:00
Robert Hensing
541a6f371f nixos/modular-services: add portable process.environment (#518860) 2026-07-24 17:40:13 +00:00
cinereal
ae9994806c lib/services: fix reload/readiness bugs and add compliance coverage
Fixes several correctness bugs primarily around modular services' recent
reload/notification options (#535695) and adds compliance coverage to guard them.

Fixes:

- `lib/services/service.nix`:
  - the reload-conflict assertion had inverted polarity, so it fired on the
    default configuration
  - the `mkIf` guard on `process.reloadCommand` had a misplaced paren, applying
    `!= null` to the `mkIf` result rather than to the condition
  - `process.reloadSignal` derives `process.reloadCommand`, so the assertion
    could not check `reloadCommand != null` -- that fired on every signal-only
    service. The command is now derived at `mkDefault` priority and the
    assertion is gated on `options.process.reloadCommand.highestPrio`, firing
    only when the user also set `reloadCommand` explicitly.
  - change `notificationProtocol` to a sub-module type
- `nixos/modules/system/service/systemd/service.nix`:
  - `systemd.mainExecReload`'s default ran `escapeSystemdExecArgs` (a list
    escaper) on the `nullOr str` `process.reloadCommand`; this threw
    `expected a list but found a string` and would have mangled `$MAINPID`. It
    now uses `process.reloadCommand` verbatim.
  - the `Type` default read a non-existent
    `config.serviceManager.notificationProtocol` instead of
    `config.notificationProtocol`.

Tests:

Extend the modular-service compliance suite to guard the above:

- Portable (manager-agnostic) eval assertions: `reloadSignal` derives
  `reloadCommand`, the conflict assertion does not fire on signal-only services
  but does when both are set explicitly, and `notificationProtocol.systemd`/`.s6`
  default to `false`.
- systemd-specific eval assertions: `serviceConfig.Type` (simple/notify) and
  `serviceConfig.ExecReload` are asserted on the resolved host units. This
  directly guards the `mainExecReload` fix, which threw before it.
- Runtime reload compliance test: a nested reloadable sub-service is started and
  reloaded, asserting the service observed the reload (recorded a SIGHUP marker).
  `callReload` receives the service's name path (the list of names from the
  top-level service down to the target sub-service); each integration joins it
  per its own unit-naming convention (NixOS dash-joins to the systemd unit name,
  e.g. `reload-inner.service`). Keeping it a path list rather than a read-only
  submodule option keeps the suite manager-agnostic.
- `doc/build-helpers/testers.chapter.md`: document `callReload`.

Follow-up to #535695.

Signed-off-by: cinereal <cinereal@riseup.net>
Assisted-by: Claude:claude-opus-4-8
2026-07-20 11:01:04 +02:00
cinereal
608690995f nixos/modular-services: add portable process.environment
Adds modular service option `process.environment` to pass an attrset of
env vars to the service manager.
`null` values actively unset the variable before the process starts.

Values are `coercedTo (either path package) str` via interpolation,
mirroring `pathOrStr`, so paths and packages render to store-path strings
with string context preserved. The type is `lazyAttrsOf`, allowing one
entry to reference another (recursive env definitions).

The systemd backend unsets entries using `unexport` in `ExecStart`,
so the variable is absent even when `Environment=` or
the inherited environment would otherwise supply it.

The systemd backend lifts non-null entries onto the primary unit wrapped
per-key with `lib.mkDefault` so they merge with the existing priority-100
`environment.PATH` binding in `nixos/lib/systemd-lib.nix` while still letting
explicit `systemd.service.environment.<k>` overrides win.

The systemd extra-root modules are loaded via `importApply`, closing `pkgs`
over `systemd/service.nix` as a non-module argument (matching the portable
`lib/services/service.nix` convention) instead of passing a redundant `pkgs`
specialArg. The docs eval threads `pkgs = throw` accordingly.

Portable coverage lives in `testers.modularServiceCompliance`: an eval-level
check that a set value round-trips and a `null` value is preserved, plus an
integration test that records the service's own `/proc/$$/environ` and asserts
the set variable is present and the null variable is absent. The
systemd-specific grep assertions in `systemd/test.nix` cover how systemd
achieves this (`Environment=` rendering, null filtering, the `unexport`
wrapper, and override precedence).

Assisted-by: Claude:claude-opus-4-8
2026-07-11 22:54:46 +02:00
Robert Hensing
ef8925c8e1 testers.modularServiceCompliance: init (#531062) 2026-06-26 15:12:52 +00:00
Robert Hensing
43908e0d12 testers.modularServiceCompliance: init
Portable test suite for modular services, designed to be usable with
other service managers and use cases, inside Nixpkgs and externally.

Like modular services itself, it's still quite bare-bones. New
features can crystallize around this kind of infrastructure.

Assisted-By: Claude Opus 4.7/4.8 era Claude models
2026-06-26 14:25:32 +02:00
Robert Hensing
fb0d18ee0b testers.lycheeLinkCheck: improve root-relative link UX
Lychee by itself does not have a way to explicitly declare the
intent for the site to be relocatable.
Recent-ish changes in lychee and/or its dependencies have made
it catch the a root reference in all mdbook 404.html pages,
which is quite confusing.
By improving the UX around this aspect of the site, we resolve
at least part of that confusion.
(Though mdbook users should probably exclude the 404 page)
2026-05-16 12:35:07 +02:00
Robert Hensing
71a39baee8 testers.lycheeLinkCheck: add extraArgs 2026-05-09 23:01:02 +02:00
Ben Siraphob
c7e10647ea treewide: fix typos 2026-01-13 14:45:11 -05:00
Matt Sturgeon
237b3cb5ce testers.testEqualContents: add checkMetadata option
Allows ignoring file metadata differences (permissions, ownership)
when comparing files.

This is especially useful on darwin, where we often run into subtle
issues like:

    -Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ wheel)
    +Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 350/ nixbld)
2025-10-17 16:18:56 +01:00
Ben Siraphob
1e82a2f358 doc: fix typos 2025-09-09 13:14:34 +07:00
Ben Siraphob
cc5b731ed3 doc: fix typos 2025-08-27 11:46:26 -07:00
Robert Hensing
8d128a4138 testers.testEqualContents: add postFailureMessage parameter
Add an optional postFailureMessage parameter to testEqualContents that allows
users to provide additional context when tests fail. This is particularly useful
for providing instructions on how to update expected results when they change
intentionally.

The message is displayed after the standard failure output, helping maintainers
understand what to do next when a test fails.
2025-08-24 20:09:54 +02:00
Wolfgang Walther
62fe016519 treewide: run treefmt with mdcr/nixfmt 2025-07-24 13:52:31 +02:00
qbisi
11291afcb3 testers.hasCmakeConfigModules: init 2025-05-31 04:24:52 +08:00
Pol Dellaiera
bcea0cf344 doc: update Nix code snippets format
Command: `mdcr --config doc/tests/mdcr-config.toml doc/`
2025-04-17 01:30:34 +02:00
Connor Baker
871cda0b06 testers.shellcheck: refactor, update docs, and simplify tests (#385940) 2025-03-07 20:53:33 -08:00
Connor Baker
3de1aeac1f testers.shellcheck: refactor and update docs 2025-03-08 00:15:22 +00:00
Philip Taron
cb26667f94 testers.shfmt: init (#385939) 2025-03-07 15:45:30 -08:00
Connor Baker
6f52f21ad2 testers.shfmt: init 2025-03-05 12:40:58 -08:00
Connor Baker
731b74db8b testers.testEqualArrayOrMap: use buildCommandPath and change checkSetupScript argument to script 2025-03-03 16:29:40 +00:00
Connor Baker
261693fe5d testers.testEqualArrayOrMap: init 2025-03-03 16:29:11 +00:00
Connor Baker
f71332b2ae testers.testBuildFailure': output is created so long as checks succeed 2025-02-27 15:56:45 +00:00
Connor Baker
38745b132d testers.testBuildFailure': init 2025-02-27 15:56:45 +00:00
Seth Flynn
d73ab2f142 doc: emphasize trade-off between versionCheckHook and testers.testVersion (#344321) 2025-01-27 00:44:44 -05:00
Peder Bergebakken Sundt
4762d9ba6e doc: emphasize trade-off between versionCheckHook and testers.testVersion 2025-01-26 17:11:00 +01:00
Gavin John
67a56f27f2 doc/build-helpers/testers: Fix command renamed to script (#352713) 2024-12-04 22:53:21 +00:00
nicoo
e0fc12cd12 doc: add type signature of testers.runCommand 2024-08-08 15:43:47 +00:00
nicoo
d0a96c6eda testers.runCommand: add, document, and test 2024-08-08 15:29:14 +00:00
Robert Hensing
4ca52fdf5f Merge pull request #323613 from CyberShadow/fix-nix-path-without-channels-v2
nix-channel: do not set empty nix-path when disabling channels
2024-07-28 13:31:10 +02:00
Robert Hensing
3fb14db08a testers.shellcheck: init
Needed for testing upcoming commit.
2024-07-16 20:10:02 +02:00
Doron Behar
f42d4debf0 doc: recommend versionCheckHook whenever relevant 2024-06-28 18:03:59 +03:00
Ivan Trubach
b25101d1fb doc: fix testers.testEqualContents fragment link 2024-05-31 05:35:48 +03:00
Robert Hensing
e0c43a96d2 testers.lycheeLinkCheck: init (#298665)
* testers.lycheeLinkCheck: init

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2024-05-27 01:14:19 +02:00
Janne Heß
fcc95ff817 treewide: Fix all Nix ASTs in all markdown files
This allows for correct highlighting and maybe future automatic
formatting. The AST was verified to work with nixfmt only.
2024-03-28 09:28:12 +01:00
Daniel Sidhion
292ea0d917 doc: migrate examples in testers chapter to admonitions (#275791) 2023-12-21 12:54:32 +01:00
DS
b47d073e2d doc: add more details on testers.testVersion 2023-12-20 03:04:32 -08:00
Yueh-Shun Li
9963ad5c5f doc: builders -> build helpers to reduce ambigualty 2023-11-07 19:58:53 +00:00