Skip to content

Commit 8978022

Browse files
committed
windows-hello module
1 parent c4b7e5f commit 8978022

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

configuration.nix

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ in
1919

2020
# Enable integration with Docker Desktop (needs to be installed)
2121
# docker.enable = true;
22+
23+
# Enable authenticating sudo prompts with Windows Hello
24+
# windowsHello.enable = true;
2225
};
2326

2427
# Enable nix flakes

flake.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
nixosModules.wsl = {
1818
imports = [
1919
./modules/build-tarball.nix
20-
./modules/wsl-distro.nix
2120
./modules/docker-desktop.nix
2221
./modules/installer.nix
22+
./modules/windows-hello.nix
23+
./modules/wsl-distro.nix
2324
];
2425
};
2526

modules/windows-hello.nix

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{ lib, pkgs, config, ... }:
2+
3+
with builtins; with lib;
4+
{
5+
6+
options.wsl.windowsHello = {
7+
enable = mkEnableOption "Authentication using Windows Hello";
8+
};
9+
10+
config =
11+
let
12+
cfg = config.wsl.windowsHello;
13+
in
14+
mkIf (config.wsl.enable && cfg.enable) {
15+
16+
security.sudo.wheelNeedsPassword = true;
17+
security.sudo.extraConfig = ''
18+
Defaults rootpw
19+
'';
20+
21+
# Hijack the pam_usb module, because NixOS does not allow for adding custom PAM modules at the moment
22+
security.pam.usb.enable = true;
23+
nixpkgs.overlays = [
24+
(self: super: {
25+
pam_usb =
26+
let
27+
authenticator = pkgs.stdenv.mkDerivation {
28+
name = "WindowsHelloAuthenticator.exe";
29+
src = pkgs.fetchurl {
30+
url = "https://github.com/nzbr/PAM-WindowsHello/releases/download/v1/WindowsHelloAuthenticator.exe";
31+
sha256 = "4856a1fefa5c869b78890f9313a560d310e9c11f2a2a212c2868cf292792ff7f";
32+
};
33+
dontUnpack = true;
34+
buildCommand = ''
35+
install -m 0755 $src $out
36+
'';
37+
};
38+
wrapper = pkgs.writeShellScript "wrapper" ''
39+
export PATH=${pkgs.coreutils}/bin # The PAM environment does not include the default PATH
40+
export WSL_INTEROP="/run/WSL/$(ls -tr /run/WSL | tail -n1)" # Find the correct WSL_INTEROP socket to be able to start the EXE
41+
env > /tmp/env
42+
exec ${authenticator} [$PAM_SERVICE] $PAM_RUSER wants to authenticate as $PAM_USER
43+
'';
44+
in
45+
"${pkgs.pam}/lib/security/pam_exec.so ${wrapper} \n# ";
46+
})
47+
];
48+
49+
};
50+
51+
}

0 commit comments

Comments
 (0)