Skip to content

nixos: replace 'text' with structured PAM rules - #420889

Merged
phaer merged 5 commits into
NixOS:staging-nixosfrom
Majiir:pam_use_rules_option
Apr 14, 2026
Merged

phaer merged 5 commits into
NixOS:staging-nixosfrom
Majiir:pam_use_rules_option

Conversation

@Majiir

@Majiir Majiir commented Jun 29, 2025 •

Copy link
Copy Markdown
Contributor

Replaces most of the nixpkgs usages of the text option to define PAM service rules with the new rules option introduced in #255547. (There's one more text usage which is removed in #420885.) See commit descriptions for details.

This incidentally fixes a bug where the gdm-fingerprint and vsftpd PAM services are created with an invalid set of default rules when some (but not all) of the conditions are met to enable them.

How this fits into the PAM refactoring plan:

  1. nixos/pam: assemble rules from modular configuration #255547
  2. nixos: replace 'text' with structured PAM rules #420889 ⬅️ you are here
  3. refine the rules interface, using these in-tree rules as test cases
  4. deprecate the text option
  5. decompose pam.nix into modules that contribute rules

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@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: 1-10 This PR causes between 1 and 10 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 Jun 29, 2025
@Majiir
Majiir force-pushed the pam_use_rules_option branch from a16cbd8 to 44e32d0 Compare June 30, 2025 00:45
@nixpkgs-ci nixpkgs-ci Bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Jul 4, 2025
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 26, 2025
@nyabinary

Copy link
Copy Markdown
Contributor

Merge conflict :p

@Majiir
Majiir force-pushed the pam_use_rules_option branch from 44e32d0 to 7df5623 Compare January 4, 2026 04:50
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Jan 4, 2026
@Majiir
Majiir force-pushed the pam_use_rules_option branch from 7df5623 to 3db2e0b Compare January 4, 2026 05:04
@l0b0

l0b0 commented Jan 4, 2026 •

Copy link
Copy Markdown
Contributor

Thank you, replacing strings with structured data is always welcome. But this is a rather large change, so it's hard to review. Would it be possible to include tests beyond pam-file-contents to verify that there's been no change of any of the rules from the target branch? Or could you provide commands to easily compare the complete before and after?

@Majiir
Majiir force-pushed the pam_use_rules_option branch from 3db2e0b to 43edd00 Compare January 4, 2026 22:26
@Majiir

Majiir commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

I have pushed a second branch (pam_use_rules_option_explained) which breaks apart the last commit into more easily reviewed steps. Some of these steps are performed by regex replacement, so you can inspect the regex or a sample of the diff and have confidence in the whole commit. Other changes were done manually, but these are easier to review by hand. The two branches are identical (diff). The smaller steps are not always valid states, but it should show the transformation clearly.

For comparing the generated files, I often do something like this:

git checkout master
nixos-rebuild build
mv result result-old
git checkout with-pam-patch
nixos-rebuild build
diff -r result-old/etc/pam.d result/etc/pam.d

Some changes are expected, since the structured rules produce PAM files with a different format than the manual text. But aside from whitespace, comments and module paths, the rules should be identical.

@mdaniels5757
mdaniels5757 changed the base branch from master to staging-nixos January 5, 2026 23:58
@nixpkgs-ci nixpkgs-ci Bot closed this Jan 5, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Jan 5, 2026
@mdaniels5757
mdaniels5757 requested review from a team January 7, 2026 23:07
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 14, 2026
@Majiir
Majiir force-pushed the pam_use_rules_option branch from 43edd00 to 4621d3a Compare January 16, 2026 03:09
github-actions[bot]

This comment was marked as outdated.

@Majiir
Majiir force-pushed the pam_use_rules_option branch from 4621d3a to bca9f2e Compare January 16, 2026 03:11
@github-actions
github-actions Bot dismissed their stale review January 16, 2026 03:12

All good now, thank you!

@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 16, 2026
@Majiir

Majiir commented Jan 16, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to resolve merge conflicts. @l0b0 Do you have enough now to give this a review?

@l0b0 l0b0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've only skimmed the rule translations, but this looks good. IIUC the main functional change is pulling autoOrderRules out verbatim.

The autoOrderRules implementation is a bit hard to understand with the combination of flip and pipe, but that was already in the original code.

@l0b0

l0b0 commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

I've taken the liberty to link this in Matrix.

@Majiir
Majiir force-pushed the pam_use_rules_option branch from 4cc528b to 9bbd0dd Compare April 11, 2026 00:51
@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 11, 2026
This function is used to convert an ordered list of rules into an
attrset of rules with reasonable 'order' values. This reduces
boilerplate to define 'order' and makes it simple to switch how ordering
is managed in the future.
@nixpkgs-ci
nixpkgs-ci Bot requested review from Vonfry and zacharyarnaise April 11, 2026 01:00
@Majiir
Majiir force-pushed the pam_use_rules_option branch from 9bbd0dd to 584fe70 Compare April 11, 2026 01:02
Several modules define whole PAM service rule stacks by overwriting the
default value of the 'text' option. Instead, we disable useDefaultRules
for these services and declare a new set of rules using the 'rules'
option. This option is considered experimental and hidden from users,
but it is supported for use within nixpkgs.
@Majiir
Majiir force-pushed the pam_use_rules_option branch from 584fe70 to 4b86499 Compare April 11, 2026 01:47
@Majiir

Majiir commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author
  • Rebased.
  • Re-ran the regex procedure, which added changes for plasma-login-manager.
  • Added some parens so that nix fmt is no longer needed, which should reduce the frequency of merge conflicts.

@zacharyarnaise zacharyarnaise left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels Apr 11, 2026

@phaer phaer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After my code-only review last time, I rebuilt all 3 desktop/laptop and 6 server machines that include gdm, fprintd, and vsftpd at least. Once with nixos-unstable and once with this branch rebased on it and diffed all of /etc/pam.d.

All changes were

  • whitespace
  • using absolute store paths for pam modules.
  • autorder comments.

Except for gdm-fingerprint where the file is now absent if fprintd is disabled, which makes sense. from the diff (gdm-fingerprint vs gdm-fingerprint.text in the mkIf).

Also ran the following pam-related vm-tests for good measure:

nom-build --keep-going \
     -A nixosTests.pam-file-contents \
     -A nixosTests.pam-lastlog \
     -A nixosTests.pam-oath-login \
     -A nixosTests.pam-pgsql \
     -A nixosTests.pam-u2f \
     -A nixosTests.pam-u2f-polkit \
     -A nixosTests.pam-ussh \
     -A nixosTests.pam-zfs-key \
     -A nixosTests.slurm-pam \
     -A nixosTests.ssh-agent-auth \
     -A nixosTests.google-oslogin \
     -A nixosTests.auth-mysql \
     -A nixosTests.sssd-ldap \
     -A nixosTests.sssd-legacy-config \
     -A nixosTests.kanidm \
     -A nixosTests.fscrypt \
     -A nixosTests.systemd-homed \
     -A nixosTests.openssh

google-oslogin and pam-zfs-key failed, but they did so on my merge base (4c1018d) as well.

Looks safe, fingers crossed 🤞

@phaer
phaer added this pull request to the merge queue Apr 14, 2026
Merged via the queue into NixOS:staging-nixos with commit 5aa9012 Apr 14, 2026
28 of 30 checks passed
@catuhana

catuhana commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

The commit 4b86499 (which is a part of this PR) gives an evaluation error when AppArmor is enabled. Should I report here or create an issue?

@phaer

phaer commented Apr 19, 2026 •

Copy link
Copy Markdown
Member

@catuhana Thanks for reporting:
Ideally an issue, referencing this PR

maximousblk added a commit to maximousblk/nyx that referenced this pull request Apr 25, 2026
… service in ly

- Replace manual pam.services.ly-autologin with services.displayManager.autoLogin
- Set defaultSession = "niri" via services.displayManager
- ly v1.3.0 added native auto-login support [1][2]

[1]: NixOS/nixpkgs#473013
[2]: NixOS/nixpkgs#420889
maximousblk added a commit to maximousblk/nyx that referenced this pull request Apr 26, 2026
… service in ly

- Replace manual pam.services.ly-autologin with services.displayManager.autoLogin
- Set defaultSession = "niri" via services.displayManager
- ly v1.3.0 added native auto-login support [1][2]

[1]: NixOS/nixpkgs#473013
[2]: NixOS/nixpkgs#420889
nixos-cuda-channel-updater Bot pushed a commit to nixos-cuda/nixpkgs that referenced this pull request May 25, 2026
Commit 5aa9012 (nixos: replace 'text' with structured PAM rules
(NixOS#420889), 2026-04-14) resulted in the vsftpd module no longer creating
a PAM module, and therefore configurations relying on `cfg.localUsers`
stopped permitting logins unless the PAM module was being set up by
other configuration.

In the absence of a better fix, document this change of behaviour as a
regression. Per the discussion at [0], provide a mechanims to restore
the previous behaviour, but with the caveat that this may be insecure.
I'd prefer more useful advice, but if I had a better understanding of
NixOS's PAM configuration and how it interacts with vsftpd, I'd just be
providing the better fix in the first place.

[0]: NixOS#515531 (comment)
LostAttractor pushed a commit to LostAttractor/nixpkgs that referenced this pull request May 26, 2026
Commit 5aa9012 (nixos: replace 'text' with structured PAM rules
(NixOS#420889), 2026-04-14) resulted in the vsftpd module no longer creating
a PAM module, and therefore configurations relying on `cfg.localUsers`
stopped permitting logins unless the PAM module was being set up by
other configuration.

In the absence of a better fix, document this change of behaviour as a
regression. Per the discussion at [0], provide a mechanims to restore
the previous behaviour, but with the caveat that this may be insecure.
I'd prefer more useful advice, but if I had a better understanding of
NixOS's PAM configuration and how it interacts with vsftpd, I'd just be
providing the better fix in the first place.

[0]: NixOS#515531 (comment)

(cherry picked from commit 93699b8)
GirardR1006 pushed a commit to GirardR1006/nixpkgs that referenced this pull request May 29, 2026
Commit 5aa9012 (nixos: replace 'text' with structured PAM rules
(NixOS#420889), 2026-04-14) resulted in the vsftpd module no longer creating
a PAM module, and therefore configurations relying on `cfg.localUsers`
stopped permitting logins unless the PAM module was being set up by
other configuration.

In the absence of a better fix, document this change of behaviour as a
regression. Per the discussion at [0], provide a mechanims to restore
the previous behaviour, but with the caveat that this may be insecure.
I'd prefer more useful advice, but if I had a better understanding of
NixOS's PAM configuration and how it interacts with vsftpd, I'd just be
providing the better fix in the first place.

[0]: NixOS#515531 (comment)
GirardR1006 pushed a commit to GirardR1006/nixpkgs that referenced this pull request May 29, 2026
Commit 5aa9012 (nixos: replace 'text' with structured PAM rules
(NixOS#420889), 2026-04-14) resulted in the vsftpd module no longer creating
a PAM module, and therefore configurations relying on `cfg.localUsers`
stopped permitting logins unless the PAM module was being set up by
other configuration.

In the absence of a better fix, document this change of behaviour as a
regression. Per the discussion at [0], provide a mechanims to restore
the previous behaviour, but with the caveat that this may be insecure.
I'd prefer more useful advice, but if I had a better understanding of
NixOS's PAM configuration and how it interacts with vsftpd, I'd just be
providing the better fix in the first place.

[0]: NixOS#515531 (comment)
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. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants