introduce importDir

avoid repeating myself

to create a new image, create a new folder under ./images that contains
a default.nix. That's it.
This commit is contained in:
zimbatm 2019-03-16 14:53:36 +01:00
parent fd0323f40f
commit 6385004fa8
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
3 changed files with 37 additions and 14 deletions

View file

@ -88,6 +88,15 @@ All images are automatically built and pushed to Docker Hub.
| [nixpkgs/nix](https://hub.docker.com/r/nixpkgs/nix) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix.svg) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix:nixos-18.09.svg) | | [nixpkgs/nix](https://hub.docker.com/r/nixpkgs/nix) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix.svg) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix:nixos-18.09.svg) |
| [nixpkgs/nix-unstable](https://hub.docker.com/r/nixpkgs/nix-unstable) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix-unstable.svg) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix-unstable:nixos-18.09.svg) | | [nixpkgs/nix-unstable](https://hub.docker.com/r/nixpkgs/nix-unstable) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix-unstable.svg) | ![](https://images.microbadger.com/badges/image/nixpkgs/nix-unstable:nixos-18.09.svg) |
## Adding new images
To add a new image to the project, create a new folder under
`./images/<image-name>` with a default.nix that returns the docker image.
Then run `nix-build release.nix -A <image-name>` to test that it builds, and
then use
`docker load -i /nix/store/...<image-name>.tar.gz` to load and test the image.
## Related projects ## Related projects
The [docker-library](https://github.com/docker-library/official-images#readme) The [docker-library](https://github.com/docker-library/official-images#readme)

21
lib/importDir.nix Normal file
View file

@ -0,0 +1,21 @@
{ lib }:
importFn: baseDir:
let
dirEntries =
builtins.attrNames
(lib.filterAttrs
(k: v: v == "directory")
(builtins.readDir baseDir));
absDirs =
builtins.map
(dir: "${toString baseDir}/${dir}")
dirEntries;
imports =
builtins.map
(dir: { name = builtins.baseNameOf dir; value = importFn dir; })
absDirs;
in
builtins.listToAttrs imports

View file

@ -1,18 +1,11 @@
_: pkgs: { _: pkgs: let
# lib stuff can be in the top-level importDir = import ./lib/importDir.nix {
inherit (pkgs) lib;
};
in {
# builder stuff can be in the top-level
buildCLIImage = pkgs.callPackage ./lib/buildCLIImage.nix {}; buildCLIImage = pkgs.callPackage ./lib/buildCLIImage.nix {};
# docker images must be lower-cased # docker images must be lower-cased
docker-nixpkgs = { docker-nixpkgs = importDir (path: pkgs.callPackage path {}) ./images;
bash = pkgs.callPackage ./images/bash {};
busybox = pkgs.callPackage ./images/busybox {};
curl = pkgs.callPackage ./images/curl {};
docker-compose = pkgs.callPackage ./images/docker-compose {};
kubectl = pkgs.callPackage ./images/kubectl {};
kubernetes-helm = pkgs.callPackage ./images/kubernetes-helm {};
nix = pkgs.callPackage ./images/nix {};
nix-unstable = pkgs.callPackage ./images/nix-unstable {};
};
} }