blob: fe3b3333b4b2efd89ef41ee5e35a273ebc7cfc04 [file] [log] [blame]
Skyler Grey252927a2022-10-18 22:18:15 +01001{ lib
2, pkgs
3, config
4, ...
5}:
6let
Skyler Greya2dabd72022-10-31 00:36:05 +00007 lockMessage = "This computer has been locked, please authenticate to continue";
Skyler Grey252927a2022-10-18 22:18:15 +01008in
9{
Skyler Greyff3c6a22022-08-21 07:25:02 +010010 config = {
Skyler Greyebd5a8e2023-02-26 12:58:17 +000011 services.fprintd.enable = true;
Skyler Grey3a504fa2023-02-26 13:04:06 +000012 environment.persistence."/nix/persist".directories = [ "/var/lib/fprint" ];
Skyler Greyd2642a22023-02-26 12:47:10 +000013
Skyler Greyff3c6a22022-08-21 07:25:02 +010014 security.apparmor = {
15 enable = true;
16 killUnconfinedConfinables = true;
17 };
18
19 boot.initrd.availableKernelModules = [
20 "aesni_intel"
21 "cryptd"
Skyler Greyebd5a8e2023-02-26 12:58:17 +000022 "uas"
23 "xhci_hcd"
Skyler Greyff3c6a22022-08-21 07:25:02 +010024 ];
25
26 boot.initrd.luks.devices = {
Skyler Grey91935932022-09-01 23:43:06 +010027 nix.device = "/dev/disk/by-label/NIX";
28 swap.device = "/dev/disk/by-label/SWAP";
Skyler Greyebd5a8e2023-02-26 12:58:17 +000029 expansion0.device = "/dev/disk/by-label/EXPANSION0";
Skyler Grey0fa154f2022-08-21 07:30:37 +010030 };
Skyler Grey91935932022-09-01 23:43:06 +010031
32 services.physlock = {
33 inherit lockMessage;
Skyler Grey09c14112023-02-19 23:41:20 +000034 enable = false;
Skyler Grey91935932022-09-01 23:43:06 +010035 allowAnyUser = true;
36 };
Skyler Grey09c14112023-02-19 23:41:20 +000037
38 security.wrappers = {
39 lock = {
40 source = ./security/lock.sh;
41 setuid = true;
42 owner = config.users.users.root.name;
43 group = config.users.users.nobody.group;
44 };
45 _onLock = {
46 source = ./security/onLock.sh;
47 setuid = false;
48 owner = config.users.users.root.name;
49 group = config.users.users.nobody.group;
50 };
51 };
Skyler Grey91935932022-09-01 23:43:06 +010052 };
53
Skyler Grey252927a2022-10-18 22:18:15 +010054 home =
55 let
56 lockCommand =
57 lib.pipe ''
Skyler Grey09c14112023-02-19 23:41:20 +000058 ${pkgs.systemd}/bin/systemd-inhibit --why="Already locked" --what=idle --who="lock script" ${config.security.wrapperDir}/lock
Skyler Grey252927a2022-10-18 22:18:15 +010059 '' [
60 (lib.splitString "\n")
61 (lib.filter (line: line != ""))
62 (lib.concatStringsSep " && ")
63 ];
64 in
65 {
66 services.swayidle = {
Skyler Grey09c14112023-02-19 23:41:20 +000067 enable = false;
Skyler Grey252927a2022-10-18 22:18:15 +010068 timeouts = [
69 {
70 timeout = 60;
71 command = lockCommand;
72 }
73 ];
74 };
75 home.packages = [
76 (pkgs.writeScriptBin "lock" lockCommand)
Skyler Grey09c14112023-02-19 23:41:20 +000077 pkgs.kbd
Skyler Grey91935932022-09-01 23:43:06 +010078 ];
79 };
Skyler Grey6aa7c262022-08-20 22:22:03 +010080}