lib/builders: init custom Docker image builder

This commit is contained in:
Gabriel Arazas 2025-03-15 16:23:19 +08:00
parent 481edbf9b1
commit cf597149bf
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
3 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,33 @@
{ dockerTools, foodogsquaredLib }:
{ name, contents ? [ ], pathsToLink ? [ ], enableTypicalSetup ? true, ... }@attrs:
dockerTools.buildImage (attrs // {
name = "fds-${name}";
copyToRoot = foodogsquaredLib.buildFDSEnv {
inherit pathsToLink;
name = "fds-${name}-root";
paths =
contents
++ lib.optionals enableTypicalSetup (with dockerTools; [
usrBinEnv
binSh
caCertificates
fakeNss
]);
};
runAsRoot = ''
${lib.optionalString enableTypicalSetup ''
mkdir -p /data
''}
${attrs.runAsRoot}
'';
config = attrs.config // lib.optionalAttrs enableTypicalSetup {
Cmd = [ "/bin/bash" ];
WorkingDir = "/data";
Volumes."/data" = { };
};
})

View File

@ -224,4 +224,50 @@
``` ```
*/ */
buildDconfDb = pkgs.callPackage ./build-dconf-db.nix { }; buildDconfDb = pkgs.callPackage ./build-dconf-db.nix { };
/**
A wrapper for building Docker images.
# Arguments
A sole attribute set with the following attributes:
name
: Name of the container.
contents
: The contents of the FDS environment to be built with.
pathsToLink
: A list of directories to be shared with all of the derivations listed
from `contents`.
enableTypicalSetup
: Enable typical configuration.
The rest of the attributes are considered as part of the
`dockerTools.buildImage` argument.
# Type
```
buildDockerImage :: Attr -> Derivation
```
# Example
```nix
buildDockerImage {
name = "typical-webdev";
contents = with pkgs; [
hello
ruby
npm
pnpm
];
enableTypicalSetup = true;
}
```
*/
buildDockerImage = pkgs.callPackage ./build-docker-image.nix { foodogsquaredLib = self; };
} }

View File

@ -39,7 +39,7 @@ in pkgs.lib.makeExtensible (self:
inherit (self.builders) inherit (self.builders)
makeXDGMimeAssociationList makeXDGPortalConfiguration makeXDGDesktopEntry makeXDGMimeAssociationList makeXDGPortalConfiguration makeXDGDesktopEntry
buildHugoSite buildFDSEnv buildDconfDb; buildHugoSite buildFDSEnv buildDconfDb buildDockerImage;
inherit (self.trivial) countAttrs filterAttrs'; inherit (self.trivial) countAttrs filterAttrs';
inherit (self.data) importYAML renderTeraTemplate renderMustacheTemplate; inherit (self.data) importYAML renderTeraTemplate renderMustacheTemplate;
inherit (self.fetchers) fetchInternetArchive fetchUgeeDriver; inherit (self.fetchers) fetchInternetArchive fetchUgeeDriver;