blob: 165ae3feefafd61bc84fdbf659864682d993e006 [file] [log] [blame]
Skyler Grey6aa7c262022-08-20 22:22:03 +01001{
Skyler Grey91935932022-09-01 23:43:06 +01002 lib,
3 pkgs,
4 config,
5 ...
6}: let
7 lockMessage = "This computer has been locked, please enter your password to continue";
8in {
Skyler Greyff3c6a22022-08-21 07:25:02 +01009 config = {
10 security.apparmor = {
11 enable = true;
12 killUnconfinedConfinables = true;
13 };
14
15 boot.initrd.availableKernelModules = [
16 "aesni_intel"
17 "cryptd"
18 ];
19
20 boot.initrd.luks.devices = {
Skyler Grey91935932022-09-01 23:43:06 +010021 nix.device = "/dev/disk/by-label/NIX";
22 swap.device = "/dev/disk/by-label/SWAP";
23 hdd.device = "/dev/disk/by-label/HDD";
Skyler Grey0fa154f2022-08-21 07:30:37 +010024 };
Skyler Grey91935932022-09-01 23:43:06 +010025
26 services.physlock = {
27 inherit lockMessage;
28 enable = true;
29 allowAnyUser = true;
30 };
31 };
32
33 home = let
Skyler Grey1010db92022-09-05 03:21:48 +010034 lockCommand =
35 lib.pipe ''
36 ${pkgs.sway}/bin/swaymsg output "*" dpms off
Skyler Grey9c8c5762022-10-30 23:06:46 +000037 ${pkgs.systemd}/bin/systemd-inhibit --why="Already locked" --what=idle --who="lock script" ${config.security.wrapperDir}/physlock -s -p "${lockMessage}"
Skyler Grey83055d72022-10-30 23:12:35 +000038 while [ $(${pkgs.sway}/bin/swaymsg -t get_outputs | ${pkgs.jq}/bin/jq "[.[] | .dpms] | any") = "false" ]; do ${pkgs.coreutils}/bin/sleep 0.1; ${pkgs.sway}/bin/swaymsg output "*" dpms on; done
Skyler Grey1010db92022-09-05 03:21:48 +010039 '' [
40 (lib.splitString "\n")
41 (lib.filter (line: line != ""))
42 (lib.concatStringsSep " && ")
43 ];
Skyler Grey91935932022-09-01 23:43:06 +010044 in {
45 services.swayidle = {
46 enable = true;
47 timeouts = [
48 {
49 timeout = 60;
50 command = lockCommand;
51 }
52 ];
53 };
54 home.packages = [
55 (pkgs.writeScriptBin "lock" lockCommand)
56 ];
Skyler Grey6aa7c262022-08-20 22:22:03 +010057 };
58}