1 { config, lib, pkgs, ... }:
3 cfg = config.services.sssd;
4 nscd = config.services.nscd;
6 dataDir = "/var/lib/sssd";
7 settingsFile = "${dataDir}/sssd.conf";
8 settingsFileUnsubstituted = pkgs.writeText "${dataDir}/sssd-unsubstituted.conf" cfg.config;
12 enable = lib.mkEnableOption "the System Security Services Daemon";
14 config = lib.mkOption {
15 type = lib.types.lines;
16 description = "Contents of {file}`sssd.conf`.";
19 config_file_version = 2
29 proxy_lib_name = files
31 proxy_pam_target = sssd-shadowutils
32 proxy_fast_alias = True
36 sshAuthorizedKeysIntegration = lib.mkOption {
37 type = lib.types.bool;
40 Whether to make sshd look up authorized keys from SSS.
41 For this to work, the `ssh` SSS service must be enabled in the sssd configuration.
46 type = lib.types.bool;
49 Whether to use SSS as a Kerberos Cache Manager (KCM).
50 Kerberos will be configured to cache credentials in SSS.
53 environmentFile = lib.mkOption {
54 type = lib.types.nullOr lib.types.path;
57 Environment file as defined in {manpage}`systemd.exec(5)`.
59 Secrets may be passed to the service without adding them to the world-readable
60 Nix store, by specifying placeholder variables as the option value in Nix and
61 setting these variables accordingly in the environment file.
64 # snippet of sssd-related config
66 ldap_default_authtok = $SSSD_LDAP_DEFAULT_AUTHTOK
70 # contents of the environment file
71 SSSD_LDAP_DEFAULT_AUTHTOK=verysecretpassword
77 config = lib.mkMerge [
78 (lib.mkIf cfg.enable {
79 # For `sssctl` to work.
80 environment.etc."sssd/sssd.conf".source = settingsFile;
81 environment.etc."sssd/conf.d".source = "${dataDir}/conf.d";
83 systemd.services.sssd = {
84 description = "System Security Services Daemon";
85 wantedBy = [ "multi-user.target" ];
86 before = [ "systemd-user-sessions.service" "nss-user-lookup.target" ];
87 after = [ "network-online.target" "nscd.service" ];
88 requires = [ "network-online.target" "nscd.service" ];
89 wants = [ "nss-user-lookup.target" ];
91 config.environment.etc."nscd.conf".source
92 settingsFileUnsubstituted
95 export LDB_MODULES_PATH+="''${LDB_MODULES_PATH+:}${pkgs.ldb}/modules/ldb:${pkgs.sssd}/modules/ldb"
96 mkdir -p /var/lib/sss/{pubconf,db,mc,pipes,gpo_cache,secrets} /var/lib/sss/pipes/private /var/lib/sss/pubconf/krb5.include.d
97 ${pkgs.sssd}/bin/sssd -D -c ${settingsFile}
101 PIDFile = "/run/sssd.pid";
102 StateDirectory = baseNameOf dataDir;
103 # We cannot use LoadCredential here because it's not available in ExecStartPre
104 EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
107 mkdir -p "${dataDir}/conf.d"
108 [ -f ${settingsFile} ] && rm -f ${settingsFile}
111 ${pkgs.envsubst}/bin/envsubst \
113 -i ${settingsFileUnsubstituted}
118 system.nssModules = [ pkgs.sssd ];
119 system.nssDatabases = {
122 services = [ "sss" ];
125 services.dbus.packages = [ pkgs.sssd ];
129 systemd.services.sssd-kcm = {
130 description = "SSSD Kerberos Cache Manager";
131 requires = [ "sssd-kcm.socket" ];
133 ExecStartPre = "-${pkgs.sssd}/bin/sssd --genconf-section=kcm";
134 ExecStart = "${pkgs.sssd}/libexec/sssd/sssd_kcm --uid 0 --gid 0";
137 settingsFileUnsubstituted
140 systemd.sockets.sssd-kcm = {
141 description = "SSSD Kerberos Cache Manager responder socket";
142 wantedBy = [ "sockets.target" ];
143 # Matches the default in MIT krb5 and Heimdal:
144 # https://github.com/krb5/krb5/blob/krb5-1.19.3-final/src/include/kcm.h#L43
145 listenStreams = [ "/var/run/.heim_org.h5l.kcm-socket" ];
147 security.krb5.settings.libdefaults.default_ccache_name = "KCM:";
150 (lib.mkIf cfg.sshAuthorizedKeysIntegration {
151 # Ugly: sshd refuses to start if a store path is given because /nix/store is group-writable.
152 # So indirect by a symlink.
153 environment.etc."ssh/authorized_keys_command" = {
157 exec ${pkgs.sssd}/bin/sss_ssh_authorizedkeys "$@"
160 services.openssh.authorizedKeysCommand = "/etc/ssh/authorized_keys_command";
161 services.openssh.authorizedKeysCommandUser = "nobody";
164 meta.maintainers = with lib.maintainers; [ bbigras ];