Commit Graph

29 Commits

Author SHA1 Message Date
cinereal
1309adc7f3 modular-services: only emit ExecReload when there is a reload command
`systemd.mainExecReload` fell back to `""` when `process.reloadCommand` was
unset, while `systemd.services."".serviceConfig.ExecReload` was defined
unconditionally. `serviceConfig` entries use `unitOption`, which concatenates
definitions only when one of them is a list; two plain strings go through
`mergeEqualOption` instead. So any service setting `ExecReload` through the
systemd escape hatch failed to evaluate, as in `nixosTests.php85.fpm-modular`.
The `""` fallback was also rendered as a bare `ExecReload=` line in every unit
without a reload command, since `attrsToSection` does not filter empty strings.

Default `systemd.mainExecReload` to `process.reloadCommand` itself, which makes
its existing `defaultText` accurate, and guard the definition with `lib.mkIf`,
so the framework leaves `ExecReload` undefined unless there really is a reload
command.

Assisted-by: Claude:claude-opus-5
Signed-off-by: cinereal <cinereal@riseup.net>
2026-08-02 00:48:36 +02:00
cinereal
1d387153a7 modular-services: fix description on mainExecReload
the description in question turned out correct for `mainExecStart`, not for
`mainExecReload`

Assisted-by: Claude:claude-opus-5
Signed-off-by: cinereal <cinereal@riseup.net>
2026-08-01 23:55:01 +02:00
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
eveeifyeve
aae4936e07 lib/services: add reload support for service management 2026-07-11 04:21:03 +10:00
eveeifyeve
03deb31b6b lib/services: add service readiness protocol support 2026-07-11 04:21:03 +10:00
Will Fancher
d5fb4a5f56 nixos/filesystems: Remove default = "auto" from fsType (#444829) 2026-04-06 01:46:00 +00:00
Will Fancher
f8ed5f30c0 nixos/filesystems: Remove default = "auto" from fsType
NixOS has traditionally enabled the `ext` family of file systems by
default. Originally, when switching to systemd initrd, we wanted to
transition to making this explicit so that initrds could be made
without `ext`. The problem is that anyone with `fsType = "auto";` for
an `ext` file system in initrd will fail to boot, which is not really
an acceptable regression as we switch to systemd initrd by default.

By removing `default = "auto"` from `fsType`, we rule out the vast
majority of these regressions as eval errors, since most users of
`fsType = "auto"` for ext file systems are using it because of the
default value.

In hindsight, this is probably what #225352 was really about.
2026-04-05 19:06:28 -04:00
cinereal
a338deb8a1 lib/services: move portable service infrastructure out of nixos/
Move the portable modular service base from
nixos/modules/system/service/portable/ to lib/services/, making it
importable by any module system (home-manager, nix-darwin) without
reaching into the nixos/ tree.

Moved files: service.nix, lib.nix, config-data.nix, config-data-item.nix,
test.nix. All external references updated (systemd/system.nix,
doc/manual/default.nix, assertions.nix, README.md).

No functional changes - only import paths differ.
2026-04-04 08:23:23 +02:00
Philip Taron
2d27bddcce nixos/portable: remove unnecessary _file in test
The module system's fallback is sufficient for this standalone test.
2026-03-19 11:45:37 -07:00
Dyego Aurélio
28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03:00
Robert Hensing
7b4d26bf86 nixos/modular-services: add systemd.mainExecStart option
Provide indirection for ExecStart to enable control over systemd
specifier and variable substitution, while escaping process.argv
by default for literal arguments.
2025-12-11 10:38:03 +01:00
Robert Hensing
5bd040e3c3 Modular services: no pkgs (#435092) 2025-08-27 12:21:59 +02:00
Robert Hensing
66697e1bd1 portable/service: Reuse meta-maintainers.nix
Tested with:

    nix repl -f .
    nix-repl> :p nixosTests.php.fpm-modular.config.nodes.machine.system.services.php-fpm.meta.maintainers

    nix-build -A nixosTests.php.fpm-modular
2025-08-21 10:20:28 +02:00
Robert Hensing
8a7e4f589a nixos/portable/test.nix: Fix test 2025-08-20 11:58:12 +02:00
Robert Hensing
90162e8113 nixos/service/portable: Provide an entrypoint function
... and tidy up in various small ways.

This should help a bit to make more clear the separation between
the portable parts and the systemd system service parts.
2025-08-20 11:58:12 +02:00
Robert Hensing
d88b9464b0 system.services: Remove ambiguous, redundant pkgs module argument
Primary reasons: remove implicit dependencies and force uniformity.
See nixos/modules/system/service/README.md for detailed rationale.
2025-08-20 11:44:06 +02:00
Robert Hensing
f576ed6890 Modular services configData (etc subdir) (#435060) 2025-08-20 09:53:23 +02:00
Robert Hensing
950a5f3344 modular services: Add configData option for etc-like files 2025-08-19 20:10:21 +02:00
Robert Hensing
96111a65e2 system.services.(<name>.services)*: Make pkgs available
I don't think we should keep this, but let's make it work for now,
and then we can remove it later.
2025-08-19 19:03:08 +02:00
Robert Hensing
5ff768593e nixos/portable/service: Drop unused parameters 2025-08-19 19:00:43 +02:00
Robert Hensing
0c28d57e02 service/portable: Add meta placeholder
This fixes the evaluation of modules such as those tested by
nix-build -A nixosTests.php.fpm-modular

... ahead of the proper fix that factors meta.maintainers out of
NixOS.
2025-08-19 16:00:59 +02:00
Robert Hensing
b51a6c3531 nixos/system/service: Use copy of escapeSystemdExecArgs
This unblocks modular services while providing opportunity to
improve this when a solution is agreed on.
2025-07-20 03:02:03 +02:00
Robert Hensing
af04a80c76 modular-services: merge process.argv from executable and args 2025-07-20 03:01:06 +02:00
Robert Hensing
b9e4118e6d nixosTests.modularService: adjust quoting expectations 2025-07-20 03:01:06 +02:00
Robert Hensing
109a6a9d1e Add assertions and warnings to modular services 2025-07-20 03:01:05 +02:00
Robert Hensing
1acabeebed Add modular services, system.services 2025-07-20 03:01:05 +02:00