Skip to content

Conversation

@illdefined
Copy link
Contributor

@illdefined illdefined commented Mar 19, 2025

This module introduces a config option boot.kernel.sysfs, which permits setting of sysfs parameters.

The configuration option accepts a nested attribute set of sysfs path components with arbitrary values, for example:

{
  kernel.mm.transparent_hugepage = {
    enabled = "always";
    defrag = "defer";
    shmem_enabled = "within_size";
  };
}

The options will be applied through systemd path units watching the individual files or glob patterns and writing the configured value through a small service using systemd-tmpfiles once they exist.

The supplied NixOS test checks if configured parameters are actually applied.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (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.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 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/` 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Mar 19, 2025
@illdefined illdefined force-pushed the nixos-config-sysfs branch 3 times, most recently from 09c76cf to c1a036b Compare March 19, 2025 18:04
@illdefined
Copy link
Contributor Author

The NixOS manual build failure appears to be unrelated to this change.

I am able to build the manual locally without any issues:
dpc1yk271wl343axkdy7q3h86jx815m4-nixos-manual-html.tar.gz

@illdefined illdefined force-pushed the nixos-config-sysfs branch 4 times, most recently from 4919977 to cd2a1b7 Compare March 19, 2025 19:17
@github-actions github-actions bot added 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation labels Mar 19, 2025
@illdefined illdefined force-pushed the nixos-config-sysfs branch 3 times, most recently from 15061d8 to 8461f59 Compare March 20, 2025 00:15
@illdefined illdefined marked this pull request as ready for review March 20, 2025 00:38
@illdefined illdefined changed the title nixos/config/sysfs: init nixos/config/sysfs: init module Mar 20, 2025
@illdefined illdefined force-pushed the nixos-config-sysfs branch 2 times, most recently from 4f517c7 to ebfe568 Compare March 20, 2025 04:03
@r-vdp
Copy link
Contributor

r-vdp commented Mar 20, 2025

One issue here, is that a lot of sysfs paths depend on kernel modules being loaded, which may happen at a later time.
On my systems, I use systemd path units to trigger a service whenever a certain path appears (because a module got loaded, e.g. hotplugging a device), and then that service writes a value to the file in sysfs.

I wonder if we'd want to support something like that? Currently the module in this PR will only work for sysfs paths that are present at the time systemd-tmpfiles runs.

Copy link
Member

Choose a reason for hiding this comment

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

types have descriptions? That's new to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description is usually generated automatically, but due to the nesting this would lead to an infinite recursion. I therefore override the description attribute and describe the type manually.

This description is included in the generated option documentation.

@SuperSandro2000
Copy link
Member

One issue here, is that a lot of sysfs paths depend on kernel modules being loaded, which may happen at a later time.

sysctl has the same problem. I usually work around it by loading the kernel module already in the initrd.

@illdefined
Copy link
Contributor Author

One issue here, is that a lot of sysfs paths depend on kernel modules being loaded, which may happen at a later time.

sysctl has the same problem. I usually work around it by loading the kernel module already in the initrd.

Instead of relying on systemd-tmpfiles, I could create individual path units for every entry.

@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 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 Apr 6, 2025
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 17, 2025
This was referenced Apr 28, 2025
@pigsinablanket
Copy link

pigsinablanket commented Apr 28, 2025

I tested enabling zram zswap with boot.kernel.sysfs.module.zswap.parameters.enabled = 1; and it worked and was persistent through a reboot.

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Apr 28, 2025

I tested enabling zram with boot.kernel.sysfs.module.zswap.parameters.enabled = 1; and it worked and was persistent through a reboot.

Did you mean "zswap"? That's a great news!

@ShamrockLee
Copy link
Contributor

It also works well configuring zswap on my system.

Copy link
Member

@jopejoe1 jopejoe1 left a comment

Choose a reason for hiding this comment

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

This looks interesting, would be nice to get this merged.

@illdefined illdefined force-pushed the nixos-config-sysfs branch from b07085f to 1305aee Compare June 17, 2025 19:00
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 17, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. and removed 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels Jun 17, 2025
@illdefined
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 391329 --checkout commit --package nixosTests.sysfs
Commit: 1305aee196b53922abfc0959d03ac90f34c8c4f9


x86_64-linux

✅ 1 test built:
  • nixosTests.sysfs

aarch64-linux

✅ 1 test built:
  • nixosTests.sysfs

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 26, 2025
@JohnRTitor JohnRTitor enabled auto-merge (rebase) August 11, 2025 06:46
@JohnRTitor JohnRTitor disabled auto-merge August 11, 2025 06:46
@JohnRTitor JohnRTitor merged commit 6d98ba9 into NixOS:master Aug 11, 2025
17 checks passed
@wolfgangwalther
Copy link
Contributor

I think this has broken nixfmt formatting, because the treefmt job ran last before the nixfmt 1.0.0 bump. PRs are failing now.

@wolfgangwalther
Copy link
Contributor

I think this has broken nixfmt formatting, because the treefmt job ran last before the nixfmt 1.0.0 bump. PRs are failing now.

Fix in #432729.

JohnRTitor added a commit to JohnRTitor/nix-conf that referenced this pull request Aug 11, 2025
@illdefined illdefined deleted the nixos-config-sysfs branch August 11, 2025 09:54
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: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (new) This PR adds a module in `nixos/` 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: tests This PR has tests 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.