From bbb1f25bfb5b8b956caab23e49b705640ea1dc3c Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Thu, 30 Nov 2023 01:28:38 +0100 Subject: [PATCH] buildFHSEnvBubblewrap: do not infer `pname` from `name` --- .../special/fhs-environments.section.md | 6 +++++- .../build-fhsenv-bubblewrap/default.nix | 21 ++++++++----------- 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 8145fbd730f7..918d1e8c2951 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 c30a4dfb7ea3..311212495f64 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} ''