blob: 889e44d2733da3ee132beab241b0f037a0a0ad8e [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 Greyea00ad52023-02-13 06:49:48 +000014 security.auditd.enable = true;
15 services.syslogd.enable = true;
16 services.syslogd.extraConfig = ''
17 *.* -/var/log/syslog
18 '';
19 services.journald.forwardToSyslog = true;
Skyler Greyff3c6a22022-08-21 07:25:02 +010020 security.apparmor = {
21 enable = true;
22 killUnconfinedConfinables = true;
23 };
24
25 boot.initrd.availableKernelModules = [
26 "aesni_intel"
27 "cryptd"
Skyler Greyebd5a8e2023-02-26 12:58:17 +000028 "uas"
29 "xhci_hcd"
Skyler Greyff3c6a22022-08-21 07:25:02 +010030 ];
31
32 boot.initrd.luks.devices = {
Skyler Grey91935932022-09-01 23:43:06 +010033 nix.device = "/dev/disk/by-label/NIX";
34 swap.device = "/dev/disk/by-label/SWAP";
Skyler Greyebd5a8e2023-02-26 12:58:17 +000035 expansion0.device = "/dev/disk/by-label/EXPANSION0";
Skyler Grey0fa154f2022-08-21 07:30:37 +010036 };
Skyler Grey91935932022-09-01 23:43:06 +010037
38 services.physlock = {
39 inherit lockMessage;
Skyler Grey09c14112023-02-19 23:41:20 +000040 enable = false;
Skyler Grey91935932022-09-01 23:43:06 +010041 allowAnyUser = true;
42 };
Skyler Grey09c14112023-02-19 23:41:20 +000043
44 security.wrappers = {
45 lock = {
46 source = ./security/lock.sh;
47 setuid = true;
48 owner = config.users.users.root.name;
49 group = config.users.users.nobody.group;
50 };
51 _onLock = {
52 source = ./security/onLock.sh;
53 setuid = false;
54 owner = config.users.users.root.name;
55 group = config.users.users.nobody.group;
56 };
57 };
Skyler Grey91935932022-09-01 23:43:06 +010058 };
59
Skyler Grey252927a2022-10-18 22:18:15 +010060 home =
61 let
62 lockCommand =
63 lib.pipe ''
Skyler Grey09c14112023-02-19 23:41:20 +000064 ${pkgs.systemd}/bin/systemd-inhibit --why="Already locked" --what=idle --who="lock script" ${config.security.wrapperDir}/lock
Skyler Grey252927a2022-10-18 22:18:15 +010065 '' [
66 (lib.splitString "\n")
67 (lib.filter (line: line != ""))
68 (lib.concatStringsSep " && ")
69 ];
70 in
71 {
72 services.swayidle = {
Skyler Grey09c14112023-02-19 23:41:20 +000073 enable = false;
Skyler Grey252927a2022-10-18 22:18:15 +010074 timeouts = [
75 {
76 timeout = 60;
77 command = lockCommand;
78 }
79 ];
80 };
81 home.packages = [
82 (pkgs.writeScriptBin "lock" lockCommand)
Skyler Grey09c14112023-02-19 23:41:20 +000083 pkgs.kbd
Skyler Grey91935932022-09-01 23:43:06 +010084 ];
85 };
Skyler Grey6aa7c262022-08-20 22:22:03 +010086}