modules/builder: gc by percent used
This commit is contained in:
parent
a7dfa3d0ce
commit
db3e6fc921
8 changed files with 48 additions and 32 deletions
hosts
modules
|
@ -7,8 +7,6 @@
|
|||
inputs.self.nixosModules.community-builder
|
||||
];
|
||||
|
||||
nixCommunity.gc.gbFree = 500;
|
||||
|
||||
# Emulate riscv64 until we have proper builders
|
||||
boot.binfmt.emulatedSystems = [ "riscv64-linux" ];
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# set in srvos, remove when reinstalling
|
||||
networking.hostId = "deadbeef";
|
||||
|
||||
nixCommunity.gc.gbFree = 500;
|
||||
|
||||
boot.kernelParams = [ "zfs.zfs_arc_max=${toString (24 * 1024 * 1024 * 1024)}" ]; # 24GB, try to limit OOM kills / reboots
|
||||
|
||||
networking.nameservers = [
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
./postgresql.nix
|
||||
];
|
||||
|
||||
nixCommunity.gc.gbFree = 500;
|
||||
|
||||
systemd.network.networks."10-uplink".networkConfig.Address = "2a01:4f8:2190:2698::2";
|
||||
|
||||
system.stateVersion = "23.11";
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
{
|
||||
imports = [ ../shared/builder.nix ];
|
||||
config,
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nix.gc.automatic = false;
|
||||
|
||||
launchd.daemons.free-space = {
|
||||
serviceConfig = {
|
||||
StartCalendarInterval = [ { Minute = 15; } ];
|
||||
};
|
||||
path = [
|
||||
config.nix.package
|
||||
pkgs.coreutils
|
||||
];
|
||||
script = import "${inputs.self}/modules/shared/free-space.nix";
|
||||
};
|
||||
|
||||
# https://github.com/LnL7/nix-darwin/blob/230a197063de9287128e2c68a7a4b0cd7d0b50a7/modules/nix/default.nix#L201
|
||||
nix.daemonProcessType = "Interactive";
|
||||
|
||||
nix.gc.interval = {
|
||||
Minute = 15;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
{
|
||||
imports = [ ../shared/builder.nix ];
|
||||
config,
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nix.gc.automatic = false;
|
||||
|
||||
nix.gc.dates = "hourly";
|
||||
systemd.services.free-space = {
|
||||
serviceConfig.Type = "oneshot";
|
||||
startAt = "hourly";
|
||||
path = [
|
||||
config.nix.package
|
||||
pkgs.coreutils
|
||||
];
|
||||
script = import "${inputs.self}/modules/shared/free-space.nix";
|
||||
};
|
||||
|
||||
# Bump the open files limit so that non-root users can run NixOS VM tests
|
||||
security.pam.loginLimits = [
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options.nixCommunity.gc.gbFree = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 150;
|
||||
description = "Amount of free space in GB to keep on disk.";
|
||||
};
|
||||
|
||||
config.nix.gc.options = ''
|
||||
--max-freed "$((${toString config.nixCommunity.gc.gbFree} * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $4 }')))"
|
||||
'';
|
||||
}
|
12
modules/shared/free-space.nix
Normal file
12
modules/shared/free-space.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
# https://git.lix.systems/the-distro/infra/commit/15a684c5d7e1ee25cdd6f2941ed17c01aa107781
|
||||
''
|
||||
nix-env --delete-generations 1d --profile /nix/var/nix/profiles/system
|
||||
while : ; do
|
||||
used=$(($(stat -f --format="100-(100*%a/%b)" /)))
|
||||
if [[ $used -gt "85" ]]; then
|
||||
nix-store --gc --max-freed 100G
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
''
|
|
@ -12,14 +12,14 @@ in
|
|||
settings.substituters = [ "https://nix-community.cachix.org" ];
|
||||
|
||||
# auto-free the /nix/store
|
||||
settings.min-free = asGB 10;
|
||||
settings.min-free = asGB 1;
|
||||
settings.max-free = asGB 50;
|
||||
|
||||
# useful for ad-hoc nix-shell's for debugging
|
||||
# use mkForce to avoid search path warnings with nix-darwin
|
||||
nixPath = pkgs.lib.mkForce [ "nixpkgs=${pkgs.path}" ];
|
||||
|
||||
gc.automatic = true;
|
||||
gc.automatic = pkgs.lib.mkDefault true;
|
||||
gc.options = pkgs.lib.mkDefault "--delete-older-than 14d";
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue