Skip to content

Instantly share code, notes, and snippets.

@callahad
Last active October 8, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callahad/a42d1e7edeaffa68517405e35a173b56 to your computer and use it in GitHub Desktop.
Save callahad/a42d1e7edeaffa68517405e35a173b56 to your computer and use it in GitHub Desktop.
{ config, lib, pkgs, ... }:
{
# Self-encrypting drive (OPAL)
nixpkgs.config.packageOverrides = pkgs: {
sedutil = (pkgs.sedutil.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or []) ++ [
# Add support for enabling unlocking when resuming from sleep
# See: https://github.com/Drive-Trust-Alliance/sedutil/pull/190
(builtins.fetchurl {
url = https://patch-diff.githubusercontent.com/raw/Drive-Trust-Alliance/sedutil/pull/190.patch;
sha256 = "c0618a319eb0c9a6efe9c72db59338232b235079042ccf77b1d690f64f735a42";
})
];
}));
};
environment.systemPackages = [ pkgs.sedutil ];
# NOTE: Generate the password hash with: sudo sedutil-cli --printPasswordHash 'plaintext-password-here' /dev/nvme0n1
systemd.services.sedutil-s3sleep = {
description = "Enable S3 sleep on OPAL self-encrypting drives";
documentation = [ "https://github.com/Drive-Trust-Alliance/sedutil/pull/190" ];
path = [ pkgs.sedutil ];
script = "sedutil-cli -n -x --prepareForS3Sleep 0 ________password_hash_here________ /dev/nvme0n1
wantedBy = [ "multi-user.target" ];
};
# Sleep
# https://www.kernel.org/doc/html/latest/admin-guide/pm/sleep-states.html#basic-sysfs-interfaces-for-system-suspend-and-hibernation
# Force hybrid-sleep on suspend:
# - When suspending, write RAM to disk (hibernate)
# - When done writing hibernation image, suspend.
environment.etc."systemd/sleep.conf".text = pkgs.lib.mkForce ''
[Sleep]
SuspendState=disk
SuspendMode=suspend
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment