Commit Graph

116 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
Silvan Mosberger
e2d2b0bc58 testers.hasPkgConfigModules: Fix meta propagation (#534949) 2026-06-29 06:55:10 +00: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
Silvan Mosberger
b8a0cab8d5 testers.hasPkgConfigModules: Fix meta propagation
Needs to forward `nonTeamMaintainers` instead of `maintainers`, because
the latter is autopopulated from the former, which in case of teams
means all teams members would be added as well.

This is what caused an update to curlMinimal to request individual team
members instead of the team itself: https://github.com/NixOS/nixpkgs/pull/534906
2026-06-24 15:27:13 +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
Robert Hensing
f9be9e95fb testers.lycheeLinkCheck: use structuredAttrs
Makes it easy to use arrays in next commits.
2026-05-09 22:54:09 +02:00
Thomas Zahner
39aea2d52a lychee: 0.23.0 -> 0.24.1 2026-04-29 11:38:16 +02:00
Thomas Zahner
3238052222 lychee: 0.22.0 -> 0.23.0
Thank you @Scrumplex for suggesting the fix for lycheeLinkCheck

Co-authored-by: Philip Taron <philip.taron@gmail.com>
2026-03-06 11:16:45 -08:00
Yueh-Shun Li
1548251cfa testers.invalidateFetcherByDrvHash: take fixed-point arguments args 2025-12-19 22:44:22 +08:00
Yueh-Shun Li
7ba63c64a6 testers.invalidateFetcherByDrvHash: use overrideAttrs if fetcher ignore name arguments 2025-12-19 22:44:21 +08:00
Yueh-Shun Li
cb39a53e9f testers.invalidateFetcherByDrvHash: salt pname if presented 2025-12-19 22:44:21 +08: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
NAHO
c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
nixpkgs-ci[bot]
04220127ea Merge staging-next into staging 2025-08-26 00:17:21 +00: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
899c40e6f8 stdenv: remove .attrs.sh fallback for structuredAttrs
This was eventually fixed in Nix 2.16+. More discussion in #357053.
2025-08-12 12:34:30 +02:00
mivorasu
ee0866bddd treewide: conform descriptions to the standards 2025-07-28 04:39:00 +00:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Robert Hensing
7845abc842 NixOS test framework: add overriding methods (#421480) 2025-07-06 13:40:24 +02:00
Robert Hensing
f2b3aeb383 nixos.runTest: Add extendNixOS 2025-07-06 13:39:15 +02:00
Connor Baker
4b80e5995e testers.testEqualArrayOrMap: use arrayUtilities where possible
Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
2025-06-11 17:08:13 +00:00
qbisi
e4ab873cc1 testers.hasCmakeConfigModules: add self tests 2025-05-31 04:24:58 +08:00
qbisi
11291afcb3 testers.hasCmakeConfigModules: init 2025-05-31 04:24:52 +08:00
Léana 江
f85b04bd6f testers.shellcheck: specify script sourcepath 2025-05-08 12:23:13 +02:00
Fernando Rodrigues
05580f4b44 treewide: switch instances of lib.teams.*.members to the new meta.teams attribute
Follow-up to #394797.

Signed-off-by: Fernando Rodrigues <alpha@sigmasquadron.net>
2025-04-25 22:20:17 -03:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Connor Baker
871cda0b06 testers.shellcheck: refactor, update docs, and simplify tests (#385940) 2025-03-07 20:53:33 -08:00
Connor Baker
ea7ec7044b tests.testers.shellcheck: switch to testBuildFailure' 2025-03-08 00:15:22 +00: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
674c90732c tests.testers.testEqualArrayOrMap: switch to testBuildFailure' 2025-03-03 16:30:41 +00:00
Connor Baker
b2bb494410 testers.testEqualArrayOrMap: inline let expression 2025-03-03 16:30:39 +00:00
Connor Baker
12ffaa4e85 testers.testEqualArrayOrMap: switch to callPackage 2025-03-03 16:30:15 +00:00
Connor Baker
40019a5e14 testers.testEqualArrayOrMap: unwrap namerefs before passing to avoid nesting 2025-03-03 16:30:15 +00:00
Connor Baker
4e6be8f313 testers.testEqualArrayOrMap: use default.nix and move recurseIntoAttrs into tests.nix 2025-03-03 16:30:15 +00:00
Connor Baker
abf9e606cf testers.testEqualArrayOrMap: move argument check from bash to Nix 2025-03-03 16:30:13 +00:00
Connor Baker
c80dc38159 testers.testEqualArrayOrMap: remove unused finalAttrs 2025-03-03 16:29:54 +00:00
Connor Baker
1a47f317c2 testers.testEqualArrayOrMap: remove old comment 2025-03-03 16:29:41 +00: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
33c162c090 testers.testBuildFailure': inline let expression 2025-02-27 18:01:30 +00:00
Connor Baker
d2a0e52d09 testers.testBuildFailure': replace import with callPackage 2025-02-27 17:55:13 +00:00
Connor Baker
9e422e63ca testers.testBuildFailure': create local bindings for loop variables to prevent lexical scoping mistakes 2025-02-27 15:56:46 +00:00
Connor Baker
25833baaa4 testers.testBuildFailure': use default.nix and move recurseIntoAttrs into tests.nix 2025-02-27 15:56:46 +00:00