1{ config, lib, pkgs, ... }:
2with lib;
3let
4 cfg = config.services.sssd;
5 nscd = config.services.nscd;
6in {
7 options = {
8 services.sssd = {
9 enable = mkEnableOption "the System Security Services Daemon";
10
11 config = mkOption {
12 type = types.lines;
13 description = "Contents of <filename>sssd.conf</filename>.";
14 default = ''
15 [sssd]
16 config_file_version = 2
17 services = nss, pam
18 domains = shadowutils
19
20 [nss]
21
22 [pam]
23
24 [domain/shadowutils]
25 id_provider = proxy
26 proxy_lib_name = files
27 auth_provider = proxy
28 proxy_pam_target = sssd-shadowutils
29 proxy_fast_alias = True
30 '';
31 };
32
33 sshAuthorizedKeysIntegration = mkOption {
34 type = types.bool;
35 default = false;
36 description = ''
37 Whether to make sshd look up authorized keys from SSS.
38 For this to work, the <literal>ssh</literal> SSS service must be enabled in the sssd configuration.
39 '';
40 };
41 };
42 };
43 config = mkMerge [
44 (mkIf cfg.enable {
45 systemd.services.sssd = {
46 description = "System Security Services Daemon";
47 wantedBy = [ "multi-user.target" ];
48 before = [ "systemd-user-sessions.service" "nss-user-lookup.target" ];
49 after = [ "network-online.target" "nscd.service" ];
50 requires = [ "network-online.target" "nscd.service" ];
51 wants = [ "nss-user-lookup.target" ];
52 restartTriggers = [
53 config.environment.etc."nscd.conf".source
54 config.environment.etc."sssd/sssd.conf".source
55 ];
56 script = ''
57 export LDB_MODULES_PATH+="''${LDB_MODULES_PATH+:}${pkgs.ldb}/modules/ldb:${pkgs.sssd}/modules/ldb"
58 mkdir -p /var/lib/sss/{pubconf,db,mc,pipes,gpo_cache,secrets} /var/lib/sss/pipes/private /var/lib/sss/pubconf/krb5.include.d
59 ${pkgs.sssd}/bin/sssd -D
60 '';
61 serviceConfig = {
62 Type = "forking";
63 PIDFile = "/run/sssd.pid";
64 };
65 };
66
67 environment.etc."sssd/sssd.conf" = {
68 text = cfg.config;
69 mode = "0400";
70 };
71
72 system.nssModules = [ pkgs.sssd ];
73 system.nssDatabases = {
74 group = [ "sss" ];
75 passwd = [ "sss" ];
76 services = [ "sss" ];
77 shadow = [ "sss" ];
78 };
79 services.dbus.packages = [ pkgs.sssd ];
80 })
81
82 (mkIf cfg.sshAuthorizedKeysIntegration {
83 # Ugly: sshd refuses to start if a store path is given because /nix/store is group-writable.
84 # So indirect by a symlink.
85 environment.etc."ssh/authorized_keys_command" = {
86 mode = "0755";
87 text = ''
88 #!/bin/sh
89 exec ${pkgs.sssd}/bin/sss_ssh_authorizedkeys "$@"
90 '';
91 };
92 services.openssh.authorizedKeysCommand = "/etc/ssh/authorized_keys_command";
93 services.openssh.authorizedKeysCommandUser = "nobody";
94 })];
95
96 meta.maintainers = with maintainers; [ bbigras ];
97}