9 cfg = config.programs.singularity;
13 options.programs.singularity = {
14 enable = lib.mkEnableOption "singularity" // {
16 Whether to install Singularity/Apptainer with system-level overriding such as SUID support.
19 package = lib.mkPackageOption pkgs "singularity" { example = "apptainer"; };
20 packageOverriden = lib.mkOption {
21 type = lib.types.nullOr lib.types.package;
24 This option provides access to the overridden result of `programs.singularity.package`.
26 For example, the following configuration makes all the Nixpkgs packages use the overridden `singularity`:
28 { config, lib, pkgs, ... }:
32 _singularity-orig = prev.singularity;
33 singularity = config.programs.singularity.packageOverriden;
36 programs.singularity.enable = true;
37 programs.singularity.package = pkgs._singularity-orig;
41 Use `lib.mkForce` to forcefully specify the overridden package.
44 enableExternalLocalStateDir = lib.mkOption {
45 type = lib.types.bool;
49 Whether to use top-level directories as LOCALSTATEDIR
50 instead of the store path ones.
51 This affects the SESSIONDIR of Apptainer/Singularity.
52 If set to true, the SESSIONDIR will become
53 `/var/lib/''${projectName}/mnt/session`.
56 enableFakeroot = lib.mkOption {
57 type = lib.types.bool;
60 Whether to enable the `--fakeroot` support of Singularity/Apptainer.
62 This option is deprecated and has no effect.
63 `--fakeroot` support is enabled automatically,
64 as `systemBinPaths = [ "/run/wrappers/bin" ]` is always specified.
67 enableSuid = lib.mkOption {
68 type = lib.types.bool;
69 # SingularityCE requires SETUID for most things. Apptainer prefers user
70 # namespaces, e.g. `apptainer exec --nv` would fail if built
72 # > `FATAL: nvidia-container-cli not allowed in setuid mode`
73 default = cfg.package.projectName != "apptainer";
74 defaultText = lib.literalExpression ''config.services.singularity.package.projectName != "apptainer"'';
77 Whether to enable the SUID support of Singularity/Apptainer.
80 systemBinPaths = lib.mkOption {
81 type = lib.types.listOf lib.types.path;
84 (Extra) system-wide /**/bin paths
85 for Apptainer/Singularity to find command-line utilities in.
87 `"/run/wrappers/bin"` is included by default to make
88 utilities with SUID bit set available to Apptainer/Singularity.
89 Use `lib.mkForce` to shadow the default values.
94 config = lib.mkIf cfg.enable {
95 programs.singularity.packageOverriden = (
96 cfg.package.override (
98 systemBinPaths = cfg.systemBinPaths;
100 // lib.optionalAttrs cfg.enableExternalLocalStateDir { externalLocalStateDir = "/var/lib"; }
101 // lib.optionalAttrs cfg.enableSuid {
103 starterSuidPath = "/run/wrappers/bin/${cfg.package.projectName}-suid";
107 programs.singularity.systemBinPaths = [ "/run/wrappers/bin" ];
108 environment.systemPackages = [ cfg.packageOverriden ];
109 security.wrappers."${cfg.packageOverriden.projectName}-suid" = lib.mkIf cfg.enableSuid {
113 source = "${cfg.packageOverriden}/libexec/${cfg.packageOverriden.projectName}/bin/starter-suid.orig";
115 systemd.tmpfiles.rules = lib.mkIf cfg.enableExternalLocalStateDir [
116 "d /var/lib/${cfg.packageOverriden.projectName}/mnt/session 0770 root root -"