Skip to content

Commit

Permalink
Merge pull request #158486 from ShamrockLee/singularity-apptainer
Browse files Browse the repository at this point in the history
singularity: fix defaultPath and reflect upstream changes
  • Loading branch information
jbedo authored Feb 8, 2023
2 parents 806cb7f + d35f5c2 commit f2ab8c7
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 131 deletions.
46 changes: 46 additions & 0 deletions nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,52 @@
as general purpose ephemeral block devices has been removed.
</para>
</listitem>
<listitem>
<para>
As Singularity has renamed to
<link xlink:href="https://apptainer.org/news/community-announcement-20211130">Apptainer</link>
to distinguish from
<link xlink:href="https://sylabs.io/2021/05/singularity-community-edition">an
un-renamed fork by Sylabs Inc.</link>, there are now two
packages of Singularity/Apptainer:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>apptainer</literal>: From
<literal>github.com/apptainer/apptainer</literal>, which
is the new repo after renaming.
</para>
</listitem>
<listitem>
<para>
<literal>singularity</literal>: From
<literal>github.com/sylabs/singularity</literal>, which is
the fork by Sylabs Inc..
</para>
</listitem>
</itemizedlist>
<para>
<literal>programs.singularity</literal> got a new
<literal>package</literal> option to specify which package to
use.
</para>
<para>
<literal>singularity-tools.buildImage</literal> got a new
input argument <literal>singularity</literal> to specify which
package to use.
</para>
</listitem>
<listitem>
<para>
The new option
<literal>programs.singularity.enableFakeroot</literal>, if set
to <literal>true</literal>, provides
<literal>--fakeroot</literal> support for
<literal>apptainer</literal> and
<literal>singularity</literal>.
</para>
</listitem>
<listitem>
<para>
The <literal>unifi-poller</literal> package and corresponding
Expand Down
12 changes: 12 additions & 0 deletions nixos/doc/manual/release-notes/rl-2305.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ In addition to numerous new and upgraded packages, this release has the followin

- The `zramSwap` is now implemented with `zram-generator`, and the option `zramSwap.numDevices` for using ZRAM devices as general purpose ephemeral block devices has been removed.

- As Singularity has renamed to [Apptainer](https://apptainer.org/news/community-announcement-20211130)
to distinguish from [an un-renamed fork by Sylabs Inc.](https://sylabs.io/2021/05/singularity-community-edition),
there are now two packages of Singularity/Apptainer:
* `apptainer`: From `github.com/apptainer/apptainer`, which is the new repo after renaming.
* `singularity`: From `github.com/sylabs/singularity`, which is the fork by Sylabs Inc..

`programs.singularity` got a new `package` option to specify which package to use.

`singularity-tools.buildImage` got a new input argument `singularity` to specify which package to use.

- The new option `programs.singularity.enableFakeroot`, if set to `true`, provides `--fakeroot` support for `apptainer` and `singularity`.

- The `unifi-poller` package and corresponding NixOS module have been renamed to `unpoller` to match upstream.

- The new option `services.tailscale.useRoutingFeatures` controls various settings for using Tailscale features like exit nodes and subnet routers. If you wish to use your machine as an exit node, you can set this setting to `server`, otherwise if you wish to use an exit node you can set this setting to `client`. The strict RPF warning has been removed as the RPF will be loosened automatically based on the value of this setting.
Expand Down
102 changes: 80 additions & 22 deletions nixos/modules/programs/singularity.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,90 @@
with lib;
let
cfg = config.programs.singularity;
singularity = pkgs.singularity.overrideAttrs (attrs : {
installPhase = attrs.installPhase + ''
mv $out/libexec/singularity/bin/starter-suid $out/libexec/singularity/bin/starter-suid.orig
ln -s /run/wrappers/bin/singularity-suid $out/libexec/singularity/bin/starter-suid
'';
});
in {
in
{

options.programs.singularity = {
enable = mkEnableOption (lib.mdDoc "Singularity");
enable = mkEnableOption (mdDoc "singularity") // {
description = mdDoc ''
Whether to install Singularity/Apptainer with system-level overriding such as SUID support.
'';
};
package = mkOption {
type = types.package;
default = pkgs.singularity;
defaultText = literalExpression "pkgs.singularity";
example = literalExpression "pkgs.apptainer";
description = mdDoc ''
Singularity/Apptainer package to override and install.
'';
};
packageOverriden = mkOption {
type = types.nullOr types.package;
default = null;
description = mdDoc ''
This option provides access to the overriden result of `programs.singularity.package`.
For example, the following configuration makes all the Nixpkgs packages use the overriden `singularity`:
```Nix
{ config, lib, pkgs, ... }:
{
nixpkgs.overlays = [
(final: prev: {
_singularity-orig = prev.singularity;
singularity = config.programs.singularity.packageOverriden;
})
];
programs.singularity.enable = true;
programs.singularity.package = pkgs._singularity-orig;
}
```
Use `lib.mkForce` to forcefully specify the overriden package.
'';
};
enableFakeroot = mkOption {
type = types.bool;
default = true;
example = false;
description = mdDoc ''
Whether to enable the `--fakeroot` support of Singularity/Apptainer.
'';
};
enableSuid = mkOption {
type = types.bool;
default = true;
example = false;
description = mdDoc ''
Whether to enable the SUID support of Singularity/Apptainer.
'';
};
};

config = mkIf cfg.enable {
environment.systemPackages = [ singularity ];
security.wrappers.singularity-suid =
{ setuid = true;
owner = "root";
group = "root";
source = "${singularity}/libexec/singularity/bin/starter-suid.orig";
};
systemd.tmpfiles.rules = [
"d /var/singularity/mnt/session 0770 root root -"
"d /var/singularity/mnt/final 0770 root root -"
"d /var/singularity/mnt/overlay 0770 root root -"
"d /var/singularity/mnt/container 0770 root root -"
"d /var/singularity/mnt/source 0770 root root -"
];
programs.singularity.packageOverriden = (cfg.package.override (
optionalAttrs cfg.enableFakeroot {
newuidmapPath = "/run/wrappers/bin/newuidmap";
newgidmapPath = "/run/wrappers/bin/newgidmap";
} // optionalAttrs cfg.enableSuid {
enableSuid = true;
starterSuidPath = "/run/wrappers/bin/${cfg.package.projectName}-suid";
}
));
environment.systemPackages = [ cfg.packageOverriden ];
security.wrappers."${cfg.packageOverriden.projectName}-suid" = mkIf cfg.enableSuid {
setuid = true;
owner = "root";
group = "root";
source = "${cfg.packageOverriden}/libexec/${cfg.packageOverriden.projectName}/bin/starter-suid.orig";
};
systemd.tmpfiles.rules = [
"d /var/lib/${cfg.packageOverriden.projectName}/mnt/session 0770 root root -"
"d /var/lib/${cfg.packageOverriden.projectName}/mnt/final 0770 root root -"
"d /var/lib/${cfg.packageOverriden.projectName}/mnt/overlay 0770 root root -"
"d /var/lib/${cfg.packageOverriden.projectName}/mnt/container 0770 root root -"
"d /var/lib/${cfg.packageOverriden.projectName}/mnt/source 0770 root root -"
];
};

}
73 changes: 0 additions & 73 deletions pkgs/applications/virtualization/singularity/default.nix

This file was deleted.

Loading

0 comments on commit f2ab8c7

Please sign in to comment.