about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeder Bergebakken Sundt <pbsds@hotmail.com>2023-11-30 01:28:38 +0100
committerPeder Bergebakken Sundt <pbsds@hotmail.com>2024-04-24 15:26:52 +0200
commitbbb1f25bfb5b8b956caab23e49b705640ea1dc3c (patch)
tree6a03d3158fdea62f6401dde16a12e436c536d252
parentb8100ca5e4d982e642420815331e35720632f353 (diff)
buildFHSEnvBubblewrap: do not infer `pname` from `name`
-rw-r--r--doc/build-helpers/special/fhs-environments.section.md6
-rw-r--r--pkgs/build-support/build-fhsenv-bubblewrap/default.nix21
2 files changed, 14 insertions, 13 deletions
diff --git a/doc/build-helpers/special/fhs-environments.section.md b/doc/build-helpers/special/fhs-environments.section.md
index 8145fbd730f7e..918d1e8c2951d 100644
--- a/doc/build-helpers/special/fhs-environments.section.md
+++ b/doc/build-helpers/special/fhs-environments.section.md
@@ -6,7 +6,11 @@ It uses Linux' namespaces feature to create temporary lightweight environments w
 Accepted arguments are:
 
 - `name`
-        The name of the environment and the wrapper executable.
+        The name of the environment, and the wrapper executable if `pname` is unset.
+- `pname`
+        The pname of the environment and the wrapper executable.
+- `version`
+        The version of the environment.
 - `targetPkgs`
         Packages to be installed for the main host's architecture (i.e. x86_64 on x86_64 installations). Along with libraries binaries are also installed.
 - `multiPkgs`
diff --git a/pkgs/build-support/build-fhsenv-bubblewrap/default.nix b/pkgs/build-support/build-fhsenv-bubblewrap/default.nix
index c30a4dfb7ea37..311212495f64d 100644
--- a/pkgs/build-support/build-fhsenv-bubblewrap/default.nix
+++ b/pkgs/build-support/build-fhsenv-bubblewrap/default.nix
@@ -9,10 +9,7 @@
 , bubblewrap
 }:
 
-{ name ? null
-, pname ? null
-, version ? null
-, runScript ? "bash"
+{ runScript ? "bash"
 , extraInstallCommands ? ""
 , meta ? {}
 , passthru ? {}
@@ -29,7 +26,7 @@
 , ...
 } @ args:
 
-assert (pname != null || version != null) -> (name == null && pname != null); # You must declare either a name or pname + version (preferred).
+assert (!args ? pname || !args ? version) -> (args ? name); # You must provide name if pname or version (preferred) is missing.
 
 let
   inherit (lib)
@@ -43,9 +40,10 @@ let
 
   inherit (lib.attrsets) removeAttrs;
 
-  pname = if args ? name && args.name != null then args.name else args.pname;
-  versionStr = optionalString (version != null) ("-" + version);
-  name = pname + versionStr;
+  name = args.name or "${args.pname}-${args.version}";
+  executableName = args.pname or args.name;
+  # we don't know which have been supplied, and want to avoid defaulting missing attrs to null. Passed into runCommandLocal
+  nameAttrs = lib.filterAttrs (key: value: builtins.elem key [ "name" "pname" "version" ]) args;
 
   buildFHSEnv = callPackage ./buildFHSEnv.nix { };
 
@@ -270,8 +268,7 @@ let
   '';
 
   bin = writeShellScript "${name}-bwrap" (bwrapCmd { initArgs = ''"$@"''; });
-in runCommandLocal name {
-  inherit pname version;
+in runCommandLocal name (nameAttrs // {
   inherit meta;
 
   passthru = passthru // {
@@ -285,9 +282,9 @@ in runCommandLocal name {
     '';
     inherit args fhsenv;
   };
-} ''
+}) ''
   mkdir -p $out/bin
-  ln -s ${bin} $out/bin/${pname}
+  ln -s ${bin} $out/bin/${executableName}
 
   ${extraInstallCommands}
 ''