From e0e7531f7dee948eefb7b8af925c6cd26411c70a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 25 May 2021 19:28:08 +0200 Subject: [PATCH] Add image.enableRecommendedContents for /bin/sh and such --- docs/modules/ROOT/partials/NixOSOptions.adoc | 19 ++++++++++ examples/minimal/arion-compose.nix | 1 + src/nix/modules/service/all-modules.nix | 1 + src/nix/modules/service/image-recommended.nix | 36 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/nix/modules/service/image-recommended.nix diff --git a/docs/modules/ROOT/partials/NixOSOptions.adoc b/docs/modules/ROOT/partials/NixOSOptions.adoc index 7709010..63f83d6 100644 --- a/docs/modules/ROOT/partials/NixOSOptions.adoc +++ b/docs/modules/ROOT/partials/NixOSOptions.adoc @@ -197,6 +197,25 @@ Default:: ---- +No Example:: {blank} + +== services..image.enableRecommendedContents + +Add the `/bin/sh` and `/usr/bin/env` symlinks and some lightweight +files. + + +[discrete] +=== details + +Type:: boolean +Default:: ++ +---- +false +---- + + No Example:: {blank} == services..image.name diff --git a/examples/minimal/arion-compose.nix b/examples/minimal/arion-compose.nix index 9531a9f..54a593a 100644 --- a/examples/minimal/arion-compose.nix +++ b/examples/minimal/arion-compose.nix @@ -4,6 +4,7 @@ config.services = { webserver = { + image.enableRecommendedContents = true; service.useHostStore = true; service.command = [ "sh" "-c" '' cd "$$WEB_ROOT" diff --git a/src/nix/modules/service/all-modules.nix b/src/nix/modules/service/all-modules.nix index 18c0432..085f1aa 100644 --- a/src/nix/modules/service/all-modules.nix +++ b/src/nix/modules/service/all-modules.nix @@ -5,6 +5,7 @@ ./host-store.nix ./context.nix ./image.nix + ./image-recommended.nix ./nixos.nix ./nixos-init.nix ../lib/assert.nix diff --git a/src/nix/modules/service/image-recommended.nix b/src/nix/modules/service/image-recommended.nix new file mode 100644 index 0000000..a4c5eac --- /dev/null +++ b/src/nix/modules/service/image-recommended.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: +let + inherit (lib) + mkIf + mkOption + types + ; + inherit (types) + bool + ; + + recommendedContents = { runCommand, bash, coreutils }: + runCommand "recommended-contents" {} '' + mkdir -p $out/bin $out/usr/bin $out/var/empty + ln -s ${bash}/bin/sh $out/bin/sh + ln -s ${coreutils}/bin/env $out/usr/bin/env + ''; +in +{ + options = { + image.enableRecommendedContents = mkOption { + type = bool; + default = false; + description = '' + Add the `/bin/sh` and `/usr/bin/env` symlinks and some lightweight + files. + ''; + }; + }; + + config = { + image.contents = mkIf config.image.enableRecommendedContents [ + (pkgs.callPackage recommendedContents {}) + ]; + }; +}