2023-01-28 18:02:47 +01:00
|
|
|
# Configurations that should only be overrided by
|
|
|
|
# overrideAttrs
|
2024-04-25 00:08:38 +02:00
|
|
|
{
|
|
|
|
pname,
|
|
|
|
version,
|
|
|
|
src,
|
|
|
|
projectName, # "apptainer" or "singularity"
|
|
|
|
vendorHash ? null,
|
|
|
|
deleteVendor ? false,
|
|
|
|
proxyVendor ? false,
|
|
|
|
extraConfigureFlags ? [ ],
|
|
|
|
extraDescription ? "",
|
|
|
|
extraMeta ? { },
|
2023-01-28 18:02:47 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
# Workaround for vendor-related attributes not overridable (#86349)
|
|
|
|
# should be removed when the issue is resolved
|
|
|
|
_defaultGoVendorArgs = {
|
2024-04-25 00:08:38 +02:00
|
|
|
inherit vendorHash deleteVendor proxyVendor;
|
2023-01-28 18:02:47 +01:00
|
|
|
};
|
|
|
|
in
|
2024-04-25 00:08:38 +02:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
buildGoModule,
|
|
|
|
runCommandLocal,
|
|
|
|
substituteAll,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Native build inputs
|
2024-04-25 00:08:38 +02:00
|
|
|
addDriverRunpath,
|
|
|
|
makeWrapper,
|
|
|
|
pkg-config,
|
|
|
|
util-linux,
|
|
|
|
which,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Build inputs
|
2024-04-25 00:08:38 +02:00
|
|
|
bash,
|
|
|
|
callPackage,
|
|
|
|
conmon,
|
|
|
|
coreutils,
|
|
|
|
cryptsetup,
|
|
|
|
e2fsprogs,
|
|
|
|
fakeroot,
|
|
|
|
fuse2fs ? e2fsprogs.fuse2fs,
|
|
|
|
go,
|
|
|
|
gpgme,
|
|
|
|
libseccomp,
|
|
|
|
libuuid,
|
2023-01-28 18:02:47 +01:00
|
|
|
# This is for nvidia-container-cli
|
2024-04-25 00:08:38 +02:00
|
|
|
nvidia-docker,
|
|
|
|
openssl,
|
|
|
|
squashfsTools,
|
|
|
|
squashfuse,
|
2023-04-04 20:33:52 +02:00
|
|
|
# Test dependencies
|
2024-04-25 00:08:38 +02:00
|
|
|
singularity-tools,
|
|
|
|
cowsay,
|
|
|
|
hello,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Overridable configurations
|
2024-04-25 00:08:38 +02:00
|
|
|
enableNvidiaContainerCli ? true,
|
2024-01-08 18:03:15 +01:00
|
|
|
# --nvccli currently requires extra privileges:
|
|
|
|
# https://github.com/apptainer/apptainer/issues/1893#issuecomment-1881240800
|
2024-04-25 00:08:38 +02:00
|
|
|
forceNvcCli ? false,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Compile with seccomp support
|
|
|
|
# SingularityCE 3.10.0 and above requires explicit --without-seccomp when libseccomp is not available.
|
2024-04-25 00:08:38 +02:00
|
|
|
enableSeccomp ? true,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Whether the configure script treat SUID support as default
|
2023-02-14 10:22:39 +01:00
|
|
|
# When equal to enableSuid, it supress the --with-suid / --without-suid build flag
|
|
|
|
# It can be set to `null` to always pass either --with-suid or --without-suided
|
|
|
|
# Type: null or boolean
|
2024-04-25 00:08:38 +02:00
|
|
|
defaultToSuid ? true,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Whether to compile with SUID support
|
2024-04-25 00:08:38 +02:00
|
|
|
enableSuid ? false,
|
|
|
|
starterSuidPath ? null,
|
2023-01-28 18:02:48 +01:00
|
|
|
# newuidmapPath and newgidmapPath are to support --fakeroot
|
|
|
|
# where those SUID-ed executables are unavailable from the FHS system PATH.
|
|
|
|
# Path to SUID-ed newuidmap executable
|
2024-04-25 00:08:38 +02:00
|
|
|
newuidmapPath ? null,
|
2023-01-28 18:02:48 +01:00
|
|
|
# Path to SUID-ed newgidmap executable
|
2024-04-25 00:08:38 +02:00
|
|
|
newgidmapPath ? null,
|
2023-08-22 12:05:31 +02:00
|
|
|
# External LOCALSTATEDIR
|
2024-04-25 00:08:38 +02:00
|
|
|
externalLocalStateDir ? null,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Remove the symlinks to `singularity*` when projectName != "singularity"
|
2024-04-25 00:08:38 +02:00
|
|
|
removeCompat ? false,
|
2023-01-28 18:02:47 +01:00
|
|
|
# Workaround #86349
|
|
|
|
# should be removed when the issue is resolved
|
2024-04-25 00:08:38 +02:00
|
|
|
vendorHash ? _defaultGoVendorArgs.vendorHash,
|
|
|
|
deleteVendor ? _defaultGoVendorArgs.deleteVendor,
|
|
|
|
proxyVendor ? _defaultGoVendorArgs.proxyVendor,
|
2023-01-28 18:02:47 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
defaultPathOriginal = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
|
2024-04-25 00:08:38 +02:00
|
|
|
privileged-un-utils =
|
|
|
|
if ((newuidmapPath == null) && (newgidmapPath == null)) then
|
|
|
|
null
|
|
|
|
else
|
|
|
|
(runCommandLocal "privileged-un-utils" { } ''
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
ln -s ${lib.escapeShellArg newuidmapPath} "$out/bin/newuidmap"
|
|
|
|
ln -s ${lib.escapeShellArg newgidmapPath} "$out/bin/newgidmap"
|
|
|
|
'');
|
2023-01-28 18:02:47 +01:00
|
|
|
in
|
2023-04-04 20:33:52 +02:00
|
|
|
(buildGoModule {
|
2023-01-28 18:02:47 +01:00
|
|
|
inherit pname version src;
|
|
|
|
|
2024-01-08 18:03:15 +01:00
|
|
|
patches = lib.optionals (projectName == "apptainer") [
|
2024-04-25 00:08:38 +02:00
|
|
|
(substituteAll {
|
|
|
|
src = ./apptainer/0001-ldCache-patch-for-driverLink.patch;
|
|
|
|
inherit (addDriverRunpath) driverLink;
|
|
|
|
})
|
2024-01-08 18:03:15 +01:00
|
|
|
];
|
|
|
|
|
2023-01-28 18:02:47 +01:00
|
|
|
# Override vendorHash with the output got from
|
2023-07-11 20:16:30 +02:00
|
|
|
# nix-prefetch -E "{ sha256 }: ((import ./. { }).apptainer.override { vendorHash = sha256; }).goModules"
|
2023-01-28 18:02:47 +01:00
|
|
|
# or with `null` when using vendored source tarball.
|
|
|
|
inherit vendorHash deleteVendor proxyVendor;
|
|
|
|
|
|
|
|
# go is used to compile extensions when building container images
|
|
|
|
allowGoReference = true;
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit
|
|
|
|
enableSeccomp
|
|
|
|
enableSuid
|
2023-08-22 12:05:31 +02:00
|
|
|
externalLocalStateDir
|
2023-01-28 18:02:47 +01:00
|
|
|
projectName
|
|
|
|
removeCompat
|
|
|
|
starterSuidPath
|
|
|
|
;
|
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper
|
|
|
|
pkg-config
|
|
|
|
util-linux
|
|
|
|
which
|
|
|
|
];
|
|
|
|
|
2023-04-04 22:09:39 +02:00
|
|
|
# Search inside the project sources
|
|
|
|
# and see the `control` file of the Debian package from upstream repos
|
|
|
|
# for build-time dependencies and run-time utilities
|
|
|
|
# apptainer/apptainer: https://github.com/apptainer/apptainer/blob/main/dist/debian/control
|
|
|
|
# sylabs/singularity: https://github.com/sylabs/singularity/blob/main/debian/control
|
|
|
|
|
2024-04-25 00:11:20 +02:00
|
|
|
buildInputs =
|
|
|
|
[
|
|
|
|
bash # To patch /bin/sh shebangs.
|
|
|
|
conmon
|
|
|
|
cryptsetup
|
|
|
|
gpgme
|
|
|
|
libuuid
|
|
|
|
openssl
|
|
|
|
squashfsTools # Required at build time by SingularityCE
|
|
|
|
]
|
|
|
|
# Optional dependencies.
|
|
|
|
# Formatting: Optional dependencies are likely to increase.
|
|
|
|
# Don't squash them into the same line.
|
|
|
|
++ lib.optional enableNvidiaContainerCli nvidia-docker
|
|
|
|
++ lib.optional enableSeccomp libseccomp;
|
2023-01-28 18:02:47 +01:00
|
|
|
|
|
|
|
configureScript = "./mconfig";
|
|
|
|
|
2024-04-25 00:08:38 +02:00
|
|
|
configureFlags =
|
|
|
|
[
|
|
|
|
"--localstatedir=${
|
|
|
|
if externalLocalStateDir != null then externalLocalStateDir else "${placeholder "out"}/var/lib"
|
|
|
|
}"
|
|
|
|
"--runstatedir=/var/run"
|
|
|
|
]
|
|
|
|
++ lib.optional (!enableSeccomp) "--without-seccomp"
|
|
|
|
++ lib.optional (enableSuid != defaultToSuid) (
|
|
|
|
if enableSuid then "--with-suid" else "--without-suid"
|
|
|
|
)
|
|
|
|
++ extraConfigureFlags;
|
2023-01-28 18:02:47 +01:00
|
|
|
|
2023-07-09 12:51:26 +02:00
|
|
|
# causes redefinition of _FORTIFY_SOURCE
|
|
|
|
hardeningDisable = [ "fortify3" ];
|
|
|
|
|
2023-01-28 18:02:47 +01:00
|
|
|
# Packages to prefix to the Apptainer/Singularity container runtime default PATH
|
|
|
|
# Use overrideAttrs to override
|
|
|
|
defaultPathInputs = [
|
|
|
|
bash
|
|
|
|
coreutils
|
|
|
|
cryptsetup # cryptsetup
|
2023-04-06 06:37:08 +02:00
|
|
|
fakeroot
|
2023-04-04 22:09:39 +02:00
|
|
|
fuse2fs # Mount ext3 filesystems
|
2023-01-28 18:02:47 +01:00
|
|
|
go
|
2023-01-28 18:02:48 +01:00
|
|
|
privileged-un-utils
|
2023-01-28 18:02:47 +01:00
|
|
|
squashfsTools # mksquashfs unsquashfs # Make / unpack squashfs image
|
|
|
|
squashfuse # squashfuse_ll squashfuse # Mount (without unpacking) a squashfs image without privileges
|
2024-04-25 00:08:38 +02:00
|
|
|
] ++ lib.optional enableNvidiaContainerCli nvidia-docker;
|
2023-01-28 18:02:47 +01:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
if [[ ! -e .git || ! -e VERSION ]]; then
|
|
|
|
echo "${version}" > VERSION
|
|
|
|
fi
|
2024-01-06 22:08:15 +01:00
|
|
|
|
2023-01-28 18:02:47 +01:00
|
|
|
# Patch shebangs for script run during build
|
|
|
|
patchShebangs --build "$configureScript" makeit e2e scripts mlocal/scripts
|
2024-01-06 22:08:15 +01:00
|
|
|
|
2023-01-28 18:02:47 +01:00
|
|
|
# Patching the hard-coded defaultPath by prefixing the packages in defaultPathInputs
|
|
|
|
substituteInPlace cmd/internal/cli/actions.go \
|
|
|
|
--replace "defaultPath = \"${defaultPathOriginal}\"" "defaultPath = \"''${defaultPathInputs// /\/bin:}''${defaultPathInputs:+/bin:}${defaultPathOriginal}\""
|
2024-01-06 22:08:15 +01:00
|
|
|
|
|
|
|
substituteInPlace internal/pkg/util/gpu/nvidia.go \
|
|
|
|
--replace \
|
|
|
|
'return fmt.Errorf("/usr/bin not writable in the container")' \
|
|
|
|
""
|
2023-01-28 18:02:47 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
postConfigure = ''
|
|
|
|
# Code borrowed from pkgs/stdenv/generic/setup.sh configurePhase()
|
|
|
|
|
|
|
|
# set to empty if unset
|
|
|
|
: ''${configureFlags=}
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
$configureScript -V ${version} "''${prefixKey:---prefix=}$prefix" $configureFlags "''${configureFlagsArray[@]}"
|
|
|
|
|
|
|
|
# End of the code from pkgs/stdenv/generic/setup.sh configurPhase()
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
make -C builddir -j"$NIX_BUILD_CORES"
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
make -C builddir install LOCALSTATEDIR="$out/var/lib"
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = ''
|
|
|
|
substituteInPlace "$out/bin/run-singularity" \
|
|
|
|
--replace "/usr/bin/env ${projectName}" "$out/bin/${projectName}"
|
|
|
|
wrapProgram "$out/bin/${projectName}" \
|
2023-05-18 02:30:40 +02:00
|
|
|
--prefix PATH : "''${defaultPathInputs// /\/bin:}''${defaultPathInputs:+/bin:}"
|
2023-01-28 18:02:47 +01:00
|
|
|
# Make changes in the config file
|
2024-01-08 18:03:15 +01:00
|
|
|
${lib.optionalString forceNvcCli ''
|
2023-01-28 18:02:47 +01:00
|
|
|
substituteInPlace "$out/etc/${projectName}/${projectName}.conf" \
|
|
|
|
--replace "use nvidia-container-cli = no" "use nvidia-container-cli = yes"
|
|
|
|
''}
|
2023-05-19 08:57:18 +02:00
|
|
|
${lib.optionalString (enableNvidiaContainerCli && projectName == "singularity") ''
|
|
|
|
substituteInPlace "$out/etc/${projectName}/${projectName}.conf" \
|
|
|
|
--replace "# nvidia-container-cli path =" "nvidia-container-cli path = ${nvidia-docker}/bin/nvidia-container-cli"
|
|
|
|
''}
|
2023-01-28 18:02:47 +01:00
|
|
|
${lib.optionalString (removeCompat && (projectName != "singularity")) ''
|
|
|
|
unlink "$out/bin/singularity"
|
|
|
|
for file in "$out"/share/man/man?/singularity*.gz; do
|
|
|
|
if [[ -L "$file" ]]; then
|
|
|
|
unlink "$file"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for file in "$out"/share/*-completion/completions/singularity; do
|
|
|
|
if [[ -e "$file" ]]
|
|
|
|
rm "$file"
|
|
|
|
done
|
|
|
|
''}
|
2024-04-25 00:08:38 +02:00
|
|
|
${lib.optionalString enableSuid (
|
|
|
|
lib.warnIf (starterSuidPath == null)
|
|
|
|
"${projectName}: Null starterSuidPath when enableSuid produces non-SUID-ed starter-suid and run-time permission denial."
|
|
|
|
''
|
|
|
|
chmod +x $out/libexec/${projectName}/bin/starter-suid
|
|
|
|
''
|
|
|
|
)}
|
2023-03-05 22:08:45 +01:00
|
|
|
${lib.optionalString (enableSuid && (starterSuidPath != null)) ''
|
2023-01-28 18:02:47 +01:00
|
|
|
mv "$out"/libexec/${projectName}/bin/starter-suid{,.orig}
|
|
|
|
ln -s ${lib.escapeShellArg starterSuidPath} "$out/libexec/${projectName}/bin/starter-suid"
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
2024-04-25 00:08:38 +02:00
|
|
|
meta =
|
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
description = "Application containers for linux" + extraDescription;
|
|
|
|
longDescription = ''
|
|
|
|
Singularity (the upstream) renamed themselves to Apptainer
|
|
|
|
to distinguish themselves from a fork made by Sylabs Inc.. See
|
2023-01-28 18:02:47 +01:00
|
|
|
|
2024-04-25 00:08:38 +02:00
|
|
|
https://sylabs.io/2021/05/singularity-community-edition
|
|
|
|
https://apptainer.org/news/community-announcement-20211130
|
|
|
|
'';
|
|
|
|
license = licenses.bsd3;
|
|
|
|
platforms = platforms.linux;
|
|
|
|
maintainers = with maintainers; [
|
|
|
|
jbedo
|
|
|
|
ShamrockLee
|
|
|
|
];
|
|
|
|
mainProgram = projectName;
|
|
|
|
}
|
|
|
|
// extraMeta;
|
|
|
|
}).overrideAttrs
|
|
|
|
(
|
|
|
|
finalAttrs: prevAttrs: {
|
|
|
|
passthru = prevAttrs.passthru or { } // {
|
|
|
|
tests = {
|
|
|
|
image-hello-cowsay = singularity-tools.buildImage {
|
|
|
|
name = "hello-cowsay";
|
|
|
|
contents = [
|
|
|
|
hello
|
|
|
|
cowsay
|
|
|
|
];
|
2024-01-06 23:50:52 +01:00
|
|
|
singularity = finalAttrs.finalPackage;
|
2024-04-25 00:08:38 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
gpuChecks = lib.optionalAttrs (projectName == "apptainer") {
|
|
|
|
# Should be in tests, but Ofborg would skip image-hello-cowsay because
|
|
|
|
# saxpy is unfree.
|
|
|
|
image-saxpy = callPackage (
|
|
|
|
{ singularity-tools, cudaPackages }:
|
|
|
|
singularity-tools.buildImage {
|
|
|
|
name = "saxpy";
|
|
|
|
contents = [ cudaPackages.saxpy ];
|
|
|
|
memSize = 2048;
|
|
|
|
diskSize = 2048;
|
|
|
|
singularity = finalAttrs.finalPackage;
|
|
|
|
}
|
|
|
|
) { };
|
|
|
|
saxpy = callPackage (
|
|
|
|
{ runCommand, writeShellScriptBin }:
|
2024-01-06 23:50:52 +01:00
|
|
|
let
|
2024-04-25 00:08:38 +02:00
|
|
|
unwrapped = writeShellScriptBin "apptainer-cuda-saxpy" ''
|
|
|
|
${lib.getExe finalAttrs.finalPackage} exec --nv $@ ${finalAttrs.passthru.gpuChecks.image-saxpy} saxpy
|
|
|
|
'';
|
2024-01-06 23:50:52 +01:00
|
|
|
in
|
|
|
|
runCommand "run-apptainer-cuda-saxpy"
|
|
|
|
{
|
|
|
|
requiredSystemFeatures = [ "cuda" ];
|
|
|
|
nativeBuildInputs = [ unwrapped ];
|
2024-04-25 00:08:38 +02:00
|
|
|
passthru = {
|
|
|
|
inherit unwrapped;
|
|
|
|
};
|
2024-01-06 23:50:52 +01:00
|
|
|
}
|
|
|
|
''
|
|
|
|
apptainer-cuda-saxpy
|
2024-04-25 00:08:38 +02:00
|
|
|
''
|
|
|
|
) { };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|