1 { config, lib, pkgs, ... }:
4 cfg = config.services.sssd;
5 nscd = config.services.nscd;
7 dataDir = "/var/lib/sssd";
8 settingsFile = "${dataDir}/sssd.conf";
9 settingsFileUnsubstituted = pkgs.writeText "${dataDir}/sssd-unsubstituted.conf" cfg.config;
13 enable = mkEnableOption (lib.mdDoc "the System Security Services Daemon");
17 description = lib.mdDoc "Contents of {file}`sssd.conf`.";
20 config_file_version = 2
30 proxy_lib_name = files
32 proxy_pam_target = sssd-shadowutils
33 proxy_fast_alias = True
37 sshAuthorizedKeysIntegration = mkOption {
40 description = lib.mdDoc ''
41 Whether to make sshd look up authorized keys from SSS.
42 For this to work, the `ssh` SSS service must be enabled in the sssd configuration.
49 description = lib.mdDoc ''
50 Whether to use SSS as a Kerberos Cache Manager (KCM).
51 Kerberos will be configured to cache credentials in SSS.
54 environmentFile = mkOption {
55 type = types.nullOr types.path;
57 description = lib.mdDoc ''
58 Environment file as defined in {manpage}`systemd.exec(5)`.
60 Secrets may be passed to the service without adding them to the world-readable
61 Nix store, by specifying placeholder variables as the option value in Nix and
62 setting these variables accordingly in the environment file.
65 # snippet of sssd-related config
67 ldap_default_authtok = $SSSD_LDAP_DEFAULT_AUTHTOK
71 # contents of the environment file
72 SSSD_LDAP_DEFAULT_AUTHTOK=verysecretpassword
80 systemd.services.sssd = {
81 description = "System Security Services Daemon";
82 wantedBy = [ "multi-user.target" ];
83 before = [ "systemd-user-sessions.service" "nss-user-lookup.target" ];
84 after = [ "network-online.target" "nscd.service" ];
85 requires = [ "network-online.target" "nscd.service" ];
86 wants = [ "nss-user-lookup.target" ];
88 config.environment.etc."nscd.conf".source
89 settingsFileUnsubstituted
92 export LDB_MODULES_PATH+="''${LDB_MODULES_PATH+:}${pkgs.ldb}/modules/ldb:${pkgs.sssd}/modules/ldb"
93 mkdir -p /var/lib/sss/{pubconf,db,mc,pipes,gpo_cache,secrets} /var/lib/sss/pipes/private /var/lib/sss/pubconf/krb5.include.d
94 ${pkgs.sssd}/bin/sssd -D -c ${settingsFile}
98 PIDFile = "/run/sssd.pid";
99 StateDirectory = baseNameOf dataDir;
100 # We cannot use LoadCredential here because it's not available in ExecStartPre
101 EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
104 [ -f ${settingsFile} ] && rm -f ${settingsFile}
107 ${pkgs.envsubst}/bin/envsubst \
109 -i ${settingsFileUnsubstituted}
114 system.nssModules = [ pkgs.sssd ];
115 system.nssDatabases = {
118 services = [ "sss" ];
121 services.dbus.packages = [ pkgs.sssd ];
125 systemd.services.sssd-kcm = {
126 description = "SSSD Kerberos Cache Manager";
127 requires = [ "sssd-kcm.socket" ];
129 ExecStartPre = "-${pkgs.sssd}/bin/sssd --genconf-section=kcm";
130 ExecStart = "${pkgs.sssd}/libexec/sssd/sssd_kcm --uid 0 --gid 0";
133 config.environment.etc."sssd/sssd.conf".source
136 systemd.sockets.sssd-kcm = {
137 description = "SSSD Kerberos Cache Manager responder socket";
138 wantedBy = [ "sockets.target" ];
139 # Matches the default in MIT krb5 and Heimdal:
140 # https://github.com/krb5/krb5/blob/krb5-1.19.3-final/src/include/kcm.h#L43
141 listenStreams = [ "/var/run/.heim_org.h5l.kcm-socket" ];
143 krb5.libdefaults.default_ccache_name = "KCM:";
146 (mkIf cfg.sshAuthorizedKeysIntegration {
147 # Ugly: sshd refuses to start if a store path is given because /nix/store is group-writable.
148 # So indirect by a symlink.
149 environment.etc."ssh/authorized_keys_command" = {
153 exec ${pkgs.sssd}/bin/sss_ssh_authorizedkeys "$@"
156 services.openssh.authorizedKeysCommand = "/etc/ssh/authorized_keys_command";
157 services.openssh.authorizedKeysCommandUser = "nobody";
160 meta.maintainers = with maintainers; [ bbigras ];