server: add swap
This commit is contained in:
parent
18d471c2ec
commit
04f3546f6e
|
@ -4,19 +4,22 @@
|
|||
# then decompress it back in a derivation (shouldn't there be a better way...)
|
||||
copyToStore = pkgs: name: path:
|
||||
let
|
||||
archive = exec [
|
||||
"/bin/sh" "-c"
|
||||
"echo '\"' && (cd /etc/nixos/private && tar -I ${pkgs.zstd}/bin/zstd -c -- ${pkgs.lib.escapeShellArg path} 2>/dev/null | base64 -w0) && echo '\"'"
|
||||
];
|
||||
in "${pkgs.stdenvNoCC.mkDerivation {
|
||||
archive = exec [ "${pkgs.bash}/bin/bash" "-c" ''
|
||||
cd /etc/nixos/private
|
||||
echo '"'"$(
|
||||
${pkgs.gnutar}/bin/tar -I ${pkgs.zstd}/bin/zstd --exclude-vcs \
|
||||
--transform='s#'${pkgs.lib.escapeShellArg path}'#!#' \
|
||||
-c -- ${pkgs.lib.escapeShellArg path} | base64 -w0
|
||||
)"'"'
|
||||
'' ];
|
||||
in derivation {
|
||||
inherit name;
|
||||
unpackPhase = "true";
|
||||
buildPhase = "true";
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cd $out
|
||||
echo "${archive}" | base64 -d | tar -I ${pkgs.zstd}/bin/zstd -x
|
||||
'';
|
||||
}}/${toString path}";
|
||||
inherit (pkgs) system;
|
||||
builder = "${pkgs.bash}/bin/bash";
|
||||
args = [ "-c" ''
|
||||
echo '${archive}' | ${pkgs.coreutils}/bin/base64 -d |
|
||||
${pkgs.gnutar}/bin/tar -P --transform="s#!#$out#" -I ${pkgs.zstd}/bin/zstd -x
|
||||
'' ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
10
flake.nix
10
flake.nix
|
@ -326,11 +326,11 @@
|
|||
maxSilent = 60 * 60 * 10;
|
||||
};
|
||||
};
|
||||
in {
|
||||
server.${config.server.system} = addMeta nixosConfigurations.server.config.system.build.toplevel;
|
||||
workstation.${config.nixmsi.system} = addMeta nixosConfigurations.nixmsi.config.system.build.toplevel;
|
||||
router.${config.router-emmc.system} = addMeta nixosConfigurations.router-emmc-cross.config.system.build.toplevel;
|
||||
workstation-home.${config.nixmsi.system} = addMeta homeConfigurations."user@nixmsi".activation-script;
|
||||
in builtins.mapAttrs (_: addMeta) {
|
||||
server.${config.server.system} = nixosConfigurations.server.config.system.build.toplevel;
|
||||
workstation.${config.nixmsi.system} = nixosConfigurations.nixmsi.config.system.build.toplevel;
|
||||
router.${config.router-emmc.system} = nixosConfigurations.router-emmc-cross.config.system.build.toplevel;
|
||||
workstation-home.${config.nixmsi.system} = homeConfigurations."user@nixmsi".activation-script;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -59,18 +59,33 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
fileSystems = {
|
||||
"/" = { device = "none"; fsType = "tmpfs"; neededForBoot = true;
|
||||
fileSystems = let
|
||||
device = rootPart;
|
||||
fsType = "btrfs";
|
||||
neededForBoot = true;
|
||||
compress = "compress=zstd";
|
||||
discard = "discard=async";
|
||||
in {
|
||||
"/" = { device = "none"; fsType = "tmpfs"; inherit neededForBoot;
|
||||
options = [ "defaults" "size=2G" "mode=755" ]; };
|
||||
# TODO: switch to bcachefs?
|
||||
# I wanna do it some day, but maybe starting with the next disk I get for this server
|
||||
"/persist" =
|
||||
{ device = rootPart; fsType = "btrfs"; neededForBoot = true;
|
||||
options = [ "subvol=@" "compress=zstd" ]; };
|
||||
"/boot" =
|
||||
{ device = bootPart; fsType = "vfat"; neededForBoot = true; };
|
||||
{ inherit device fsType neededForBoot;
|
||||
options = [ discard compress "subvol=@" ]; };
|
||||
"/swap" = { inherit device fsType neededForBoot;
|
||||
options = [ discard "subvol=@swap" "noatime" ]; };
|
||||
"/boot" = { device = bootPart; fsType = "vfat"; inherit neededForBoot; };
|
||||
};
|
||||
|
||||
swapDevices = [ { device = "/swap/swapfile"; } ];
|
||||
|
||||
boot.kernelParams = [
|
||||
"resume=/@swap/swapfile"
|
||||
# resume_offset = $(btrfs inspect-internal map-swapfile -r path/to/swapfile)
|
||||
"resume_offset=26001976"
|
||||
];
|
||||
|
||||
impermanence = {
|
||||
enable = true;
|
||||
path = /persist;
|
||||
|
|
Loading…
Reference in a new issue