9 cfg = config.boot.initrd.unl0kr;
10 settingsFormat = pkgs.formats.ini { };
13 options.boot.initrd.unl0kr = {
14 enable = lib.mkEnableOption "unl0kr in initrd" // {
15 description = ''Whether to enable the unl0kr on-screen keyboard in initrd to unlock LUKS.'';
18 allowVendorDrivers = lib.mkEnableOption "load optional drivers" // {
19 description = ''Whether to load additional drivers for certain vendors (I.E: Wacom, Intel, etc.)'';
22 settings = lib.mkOption {
24 Configuration for `unl0kr`.
26 See `unl0kr.conf(5)` for supported values.
28 Alternatively, visit `https://gitlab.com/postmarketOS/buffybox/-/blob/unl0kr-2.0.0/unl0kr.conf`
31 example = lib.literalExpression ''
33 general.animations = true;
35 default = "pmos-dark";
36 alternate = "pmos-light";
41 type = lib.types.submodule { freeformType = settingsFormat.type; };
45 config = lib.mkIf cfg.enable {
46 meta.maintainers = with lib.maintainers; [ hustlerone ];
49 assertion = cfg.enable -> config.boot.initrd.systemd.enable;
50 message = "boot.initrd.unl0kr is only supported with boot.initrd.systemd.";
53 assertion = !config.boot.plymouth.enable;
54 message = "unl0kr will not work if plymouth is enabled.";
57 assertion = !config.hardware.amdgpu.initrd.enable;
58 message = "unl0kr has issues with video drivers that are loaded on stage 1.";
62 boot.initrd.availableKernelModules =
63 lib.optionals cfg.enable [
69 "i2c-designware-platform"
75 ++ lib.optionals cfg.allowVendorDrivers [
81 boot.initrd.systemd = {
82 contents."/etc/unl0kr.conf".source = settingsFormat.generate "unl0kr.conf" cfg.settings;
83 storePaths = with pkgs; [
84 "${pkgs.gnugrep}/bin/grep"
87 "${config.boot.initrd.systemd.package}/lib/systemd/systemd-reply-password"
88 "${pkgs.unl0kr}/bin/unl0kr"
91 unl0kr-ask-password = {
92 description = "Forward Password Requests to unl0kr";
95 "initrd-switch-root.target"
98 unitConfig.DefaultDependencies = false;
100 "systemd-vconsole-setup.service"
103 before = [ "shutdown.target" ];
105 # This script acts as a Password Agent: https://systemd.io/PASSWORD_AGENTS/
107 DIR=/run/systemd/ask-password/
108 # If a user has multiple encrypted disks, the requests might come in different times,
109 # so make sure to answer as many requests as we can. Once boot succeeds, other
110 # password agents will be responsible for watching for requests.
111 while [ -d $DIR ] && [ "$(ls -A $DIR/ask.*)" ];
113 for file in `ls $DIR/ask.*`; do
114 socket="$(cat "$file" | ${pkgs.gnugrep}/bin/grep "Socket=" | cut -d= -f2)"
115 ${pkgs.unl0kr}/bin/unl0kr -v -C "/etc/unl0kr.conf" | ${config.boot.initrd.systemd.package}/lib/systemd/systemd-reply-password 1 "$socket"
123 unl0kr-ask-password = {
124 description = "Forward Password Requests to unl0kr";
127 "initrd-switch-root.target"
130 unitConfig.DefaultDependencies = false;
136 wantedBy = [ "sysinit.target" ];
138 DirectoryNotEmpty = "/run/systemd/ask-password";
139 MakeDirectory = true;