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 {}) + ]; + }; +}