Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapspace: dynamically manage swapspace on NixOS #88093

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wmertens
Copy link
Contributor

Motivation for this change

Using NixOS with dynamic swap size management, the way macOS does it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

nixos/modules/services/system/swapspace.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
###### implementation

config = mkIf cfg.enable {
systemd.services.swapspace = with pkgs; {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
systemd.services.swapspace = with pkgs; {
systemd.services.swapspace = {

you don't refer to things inside pkgs anywhere.

@flokli
Copy link
Contributor

flokli commented Aug 7, 2020

@wmertens can you address the changes requested?

@flokli flokli added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 7, 2020
@wmertens
Copy link
Contributor Author

wmertens commented Aug 7, 2020

@flokli yes sorry, they were very helpful, but this dropped off my radar. I'll address them this weekend

@flokli
Copy link
Contributor

flokli commented Aug 15, 2020

@wmertens another poke ;-)

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 15, 2020
@wmertens
Copy link
Contributor Author

@peterhoeg thanks for the thorough review, much appreciated. I'll update this this week.

@xaverdh
Copy link
Contributor

xaverdh commented Jun 5, 2021

is this still worked on?

@wmertens wmertens force-pushed the swapspace branch 2 times, most recently from fe078cb to ef928e6 Compare June 5, 2021 10:19
@wmertens
Copy link
Contributor Author

wmertens commented Jun 5, 2021

Ok, updated and rebased. Thank you all for your comments, is this good for merging?

nixos/modules/services/system/swapspace.nix Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/linux/swapspace/default.nix Show resolved Hide resolved
@stale
Copy link

stale bot commented Jan 9, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 9, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 26, 2022
based on reviews from langston-barrett, flokli and peterhoeg, thanks!

nativeBuildInputs = [ autoreconfHook ];

patchPhase = ''
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
patchPhase = ''
postPatch = ''

Comment on lines +33 to +34
nativeBuildInputs = [ autoreconfHook ];

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nativeBuildInputs = [ autoreconfHook ];

duped with line 14

type = types.nullOr types.int;
default = null;
description = ''
Maximum size of a swapfile.
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be great to explain what happens when this is set to null. Same for minSwapSize.

description = ''
Cooldown period between changes.
SwapSpace will wait at least this many seconds before an action,
like removing a swapfile after adding one.
Copy link
Member

Choose a reason for hiding this comment

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

Is null then the same as 0 or how does it interact?

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 31, 2022
@ghost
Copy link

ghost commented Oct 5, 2022

Why is this staled out ? Does no one use dynamic swap on Nix?

@wmertens
Copy link
Contributor Author

wmertens commented Oct 5, 2022 via email

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 5, 2022
+ optionalString (cfg.cooldown != null)
" --cooldown=${toString cfg.cooldown}"
+ optionalString (cfg.minSwapSize != null)
" --min_swapsize=${toString cfg.minSwapSize}"
Copy link
Contributor

Choose a reason for hiding this comment

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

From the documentation:

Never bother to allocate any swapfiles smaller than size bytes. There should be no need to change this variable except for testing.

I suggest removing this argument and the option. For testing, one can just use extraArgs.

@Luflosi
Copy link
Contributor

Luflosi commented Oct 30, 2022

You should reuse the upstream systemd unit file by copying it to the package output and then using it in the NixOS module. Let me know if you need help with that. I'll be happy to help you on this.

@ghost
Copy link

ghost commented Dec 30, 2022

having dynamic swap on my laptop (and I bet many other systems) would be so nice... Zswap seems to work better than zram and being able to have a dynamic swap system would help with not having to sacrifice a definite storage space

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants