Skip to content

modules: fix modular services with strict nixpkgs modules - #9708

Closed
DaVinci42 wants to merge 1 commit into
nix-community:masterfrom
DaVinci42:fix/modular-services-nixpkgs-args
Closed

modules: fix modular services with strict nixpkgs modules#9708
DaVinci42 wants to merge 1 commit into
nix-community:masterfrom
DaVinci42:fix/modular-services-nixpkgs-args

Conversation

@DaVinci42

Copy link
Copy Markdown
Contributor

Description

Fixes evaluation of modular services when the imported nixpkgs systemd service module does not accept every argument passed by the Home Manager module system.

Minimal reproducer:

{
  inputs = {
    # Nixpkgs master as of 2026-07-25 06:57:37 UTC.
    nixpkgs.url = "github:NixOS/nixpkgs/9e3461d3ed9792395b1ebb8e99a9bb7f866cda7b";
    # Home Manager master as of 2026-07-24 17:12:39 UTC.
    home-manager.url = "github:nix-community/home-manager/079a3b5d1aa6a719920a51316253b7d6dd22738d";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs =
    {
      nixpkgs,
      home-manager,
      ...
    }:
    let
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
    in
    {
      homeConfigurations.repro = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [
          {
            home.username = "me";
            home.homeDirectory = "/home/me";
            home.stateVersion = "25.11";
            programs.home-manager.enable = true;
          }
        ];
      };
    };
}

Build command:

nix build .#homeConfigurations.repro.activationPackage --show-trace

This currently fails while generating the Home Manager manpage/options:

error: function 'anonymous lambda' called with unexpected argument 'lib'
at .../nixos/modules/system/service/systemd/service.nix:4:1:
     3| # This makes service modules self-contained, allowing mixing of Nixpkgs versions.
     4| { pkgs }:
       | ^

This happens because modules/services-modular/service.nix imports the nixpkgs systemd service module as a module path. The module system then calls it with the full Home Manager argument set. Some nixpkgs revisions expose that file as a stricter function and reject extra arguments such as lib or specialArgs.

The fix imports the nixpkgs module function explicitly and calls it with only the arguments declared by that function. This preserves compatibility with different nixpkgs signatures while avoiding accidental argument injection by the module system.

Checklist

  • Change is backwards compatible.
  • Code formatted with nix fmt or
    nix-shell -A dev --run treefmt.
  • Code tested through nix build .#test-all
    or a targeted nix run .#tests -- <pattern>.
  • Test cases updated/added.

@home-manager-ci
home-manager-ci Bot requested a review from KiaraGrouwstra July 25, 2026 08:05
Call the imported systemd service module with only the arguments it
accepts so Home Manager does not fail when nixpkgs rejects extra module
arguments.
@DaVinci42
DaVinci42 force-pushed the fix/modular-services-nixpkgs-args branch from f54bcc8 to e70de1e Compare July 25, 2026 08:07
@DaVinci42 DaVinci42 changed the title modules: keep modular services compatible with nixpkgs modules: fix modular services with strict nixpkgs modules Jul 25, 2026
@KiaraGrouwstra

KiaraGrouwstra commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

hey there, sorry again for NixOS/nixpkgs#518860 having broken downstream consumption like here.

for what it's worth, the underlying breaking change was reverted at NixOS/nixpkgs#545519, and the refile at NixOS/nixpkgs#545521 would lack the breaking change.

i think the underlying issue here is in file-based imports being fragile, hence i'd filed a few PRs to shift toward going thru root-level entrypoints instead:

on the approach proposed in the current PR, i think the tough part is that the breaking change in this particular case was maybe less about adding or removing an argument, more about the module there getting wrapped in a closure, which then maybe raises the question for me on whether the approach here wouldn't like break again with the (now-landed) revert at NixOS/nixpkgs#545519 - or, for that matter, with the refile at NixOS/nixpkgs#545521.

in that sense, i wonder if the fix here would help more than just that revert upstream.

@DaVinci42

Copy link
Copy Markdown
Contributor Author

hey there, sorry again for NixOS/nixpkgs#518860 having broken downstream consumption like here.

for what it's worth, the underlying breaking change was reverted at NixOS/nixpkgs#545519, and the refile at NixOS/nixpkgs#545521 would lack the breaking change.

i think the underlying issue here is in file-based imports being fragile, hence i'd filed a few PRs to shift toward going thru root-level entrypoints instead:

* `lib` side: [lib/services: expose portable service lib as `lib.services` NixOS/nixpkgs#507052](https://github.com/NixOS/nixpkgs/pull/507052)

* nixos side: [nixos/modular-services: split system-specific config out of `pkgs.<pkg>.services.<service>` NixOS/nixpkgs#540863](https://github.com/NixOS/nixpkgs/pull/540863)

on the approach proposed in the current PR, i think the tough part is that the breaking change in this particular case was maybe less about adding or removing an argument, more about the module there getting wrapped in a closure, which then maybe raises the question for me on whether the approach here wouldn't like break again with the (now-landed) revert at NixOS/nixpkgs#545519 - or, for that matter, with the refile at NixOS/nixpkgs#545521.

in that sense, i wonder if the fix here would help more than just that revert upstream.

Thanks for the context! Since the follow up PRs are still pending, I’ll hold off for now.
Once those merged, I’ll test again and see whether this workaround is still needed.

@DaVinci42
DaVinci42 marked this pull request as draft July 25, 2026 08:49
@DaVinci42

Copy link
Copy Markdown
Contributor Author

Tested again with the latest nixpkgs, and the build works fine now.
Close this one.

@DaVinci42 DaVinci42 closed this Jul 25, 2026
@pyrox0

pyrox0 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

hey there, sorry again for NixOS/nixpkgs#518860 having broken downstream consumption like here.

for what it's worth, the underlying breaking change was reverted at NixOS/nixpkgs#545519, and the refile at NixOS/nixpkgs#545521 would lack the breaking change.

i think the underlying issue here is in file-based imports being fragile, hence i'd filed a few PRs to shift toward going thru root-level entrypoints instead:

* `lib` side: [lib/services: expose portable service lib as `lib.services` NixOS/nixpkgs#507052](https://github.com/NixOS/nixpkgs/pull/507052)

* nixos side: [nixos/modular-services: split system-specific config out of `pkgs.<pkg>.services.<service>` NixOS/nixpkgs#540863](https://github.com/NixOS/nixpkgs/pull/540863)

on the approach proposed in the current PR, i think the tough part is that the breaking change in this particular case was maybe less about adding or removing an argument, more about the module there getting wrapped in a closure, which then maybe raises the question for me on whether the approach here wouldn't like break again with the (now-landed) revert at NixOS/nixpkgs#545519 - or, for that matter, with the refile at NixOS/nixpkgs#545521.

in that sense, i wonder if the fix here would help more than just that revert upstream.

Just FYI, neither the revert or refile landed in the latest nixpkgs-unstable, breaking evaluation in a very significant way. Is there a way to avoid this with home-manager right now?

@KiaraGrouwstra

Copy link
Copy Markdown
Contributor

@pyrox0 thanks for notifying me! i filed a fix now at #9714.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants