Last active
August 21, 2021 21:35
-
-
Save Xophmeister/40d3533502ed347628d6b137eeaf7f36 to your computer and use it in GitHub Desktop.
Proof-of-concept Docker image building of multiple packages, with Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {}, name, packages ? {}}: | |
with pkgs; | |
let | |
# We need bash and coreutils to display the container "run" message; | |
# dockerTools.buildImage expects a list of derivations, not a set | |
required = { inherit bash coreutils; }; | |
contents = builtins.attrValues (required // packages); | |
prettyPrint = import ./prettyPrint.nix {}; | |
in dockerTools.buildImage { | |
inherit name contents; | |
config = { | |
Cmd = [ "${bash}/bin/bash" "-c" '' | |
( ${coreutils}/bin/cat | ${coreutils}/bin/fmt -s ) >&2 <<EOF | |
This is the "${name}" container, containing the following software: | |
${prettyPrint packages} | |
Execute these tools explicitly from within the container, rather than running the container itself. | |
EOF | |
'' ]; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
pkgs = import <nixpkgs> {}; | |
buildContainer = import ./buildContainer.nix; | |
in buildContainer { | |
name = "bionix-poc"; | |
packages = with pkgs; { inherit samtools bwa; }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pretty printer for package/derivation sets | |
{ bullet ? "*", recSep ? "\n", emptyText ? "<No packages installed>" }: | |
packageSet: | |
with builtins; | |
let | |
# Pretty printer for derivations | |
ppDrv = drv: | |
let parsed = parseDrvName drv.name; | |
in "${bullet} ${parsed.name} v${parsed.version}"; | |
# Extract derivations from set | |
packages = attrValues packageSet; | |
isEmpty = length packages == 0; | |
in if isEmpty | |
then emptyText | |
else concatStringsSep recSep (map ppDrv packages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rather than using
ociTools
, we can create Singularity images with: