Skip to content

nixos/pam: enable lastlog2 import service if any pam service uses lastlog#432567

Merged
K900 merged 3 commits intoNixOS:staging-nextfrom
LordGrimmauld:lastlog-improvements
Aug 11, 2025
Merged

nixos/pam: enable lastlog2 import service if any pam service uses lastlog#432567
K900 merged 3 commits intoNixOS:staging-nextfrom
LordGrimmauld:lastlog-improvements

Conversation

@LordGrimmauld
Copy link
Contributor

@LordGrimmauld LordGrimmauld commented Aug 10, 2025

As described in util-linux/util-linux#2508 (comment), lastlog2-import.service is used for compatibility to import old lastlog databases. It is possible someone used updateWtmp on some PAM service while disabling it on login, which would currently make the import of the old database fail.

Fixes #429203 (comment)

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@LordGrimmauld LordGrimmauld mentioned this pull request Aug 10, 2025
13 tasks
@LordGrimmauld LordGrimmauld requested a review from Majiir August 10, 2025 16:57
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Aug 10, 2025
@LordGrimmauld LordGrimmauld marked this pull request as ready for review August 11, 2025 08:33
@LordGrimmauld LordGrimmauld requested a review from K900 August 11, 2025 08:33
@LordGrimmauld
Copy link
Contributor Author

While writing a test for the lastlog2-import.service, i noticed the ExecPostStart was broken. The service loaded successfully, but it never actually ran due to the condition in https://github.com/util-linux/util-linux/blob/ec46779106a2573082b14dfda679471a42dcba97/misc-utils/lastlog2-import.service.in#L5.

This is fixed in a drop-in now, i will draft a PR to the next staging to fix it in util-linux instead. Rebuilding util-linux now is likely too expensive, and it can be fixed with basically no rebuilds so that is the route i went with.

Now the lastlog importer gets enabled whenever anything uses lastlog, and it actually works.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels Aug 11, 2025
@K900 K900 merged commit a6809ff into NixOS:staging-next Aug 11, 2025
26 of 28 checks passed
};
systemd =
lib.optionalAttrs
(lib.any (service: service.updateWtmp) (lib.attrValues config.security.pam.services))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of config.security.pam.services, this should be enabledServices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure i agree. the lastlog importer service is gated behind the old lastlog db existing via a systemd condition. I did even consider just enabling the service unconditionally. Arguably, if someone has an old lastlog db but currently no pam service that updates lastlog, they might still want to be able to read that old db using the new tools, which requires the import. And having the impoorter around doesn't really hurt anything, because if there is nothing to import it just won't do anything.

That said, maybe this scenario is a bit niche, so i am willing to switch to enabledServices. I assume your point is to make the installed services as minimal as possible, in which case you do have a point.

Sorry for the mess, i now realize #429203 should have been split into two PRs: the util-linux output split and the PAM changes, with the pam changes waiting for a proper thorough review. If i had to do this again i'd do it differently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave it to you to figure out whether the lastlog import should be conditional or unconditional - I have no idea!

But if you choose to make it conditional on whether any PAM service has updateWtmp, the correct way to do it is with enabledServices. Otherwise, we could be in a situation where an explicitly disabled PAM service (with no PAM rules file) is somehow influencing the system configuration.

I don't like that doing the obvious thing (reading config.security.pam.services) is the wrong thing, so I'm considering this a pam.nix rough edge that needs fixing. Using enabledServices in the meantime helps keep usage consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough. I'll draft a change to enabledServices, your reasoning is valid. But i don't think the current state is catastrophically broken, so this time we can wait for you to thoroughly review and discuss the changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Agreed, it's more of a nitpick.

drupol added a commit to drupol/nixpkgs that referenced this pull request Sep 2, 2025
See TODO in NixOS#432567 for context

Co-authored-by: Grimmauld <[email protected]>
qweered pushed a commit to qweered/nixpkgs that referenced this pull request Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants