[PATCH 1/3] scripts: nixify archive-source.sh

Joel Granados posted 3 patches 7 months, 1 week ago
[PATCH 1/3] scripts: nixify archive-source.sh
Posted by Joel Granados 7 months, 1 week ago
Use "#!/usr/bin/env bash" instead of "#!/bin/bash". This is necessary
for nix environments as they only provide /usr/bin/env at the standard
location.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
 scripts/archive-source.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh
index 30677c3ec9032ea01090f74602d839d1c571d012..a469a5e2dec4b05e51474f0a1af190c1ccf23c7e 100755
--- a/scripts/archive-source.sh
+++ b/scripts/archive-source.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 #
 # Author: Fam Zheng <famz@redhat.com>
 #

-- 
2.44.1
Re: [PATCH 1/3] scripts: nixify archive-source.sh
Posted by Paolo Bonzini 7 months, 1 week ago
On 4/8/25 22:14, Joel Granados wrote:
> Use "#!/usr/bin/env bash" instead of "#!/bin/bash". This is necessary
> for nix environments as they only provide /usr/bin/env at the standard
> location.

I am confused, how does this not break everything else?  All the test 
scripts in tests/docker/test-* have "#!/bin/bash", and configure has 
"/bin/sh".  How is the environment that runs scripts/archive-source.sh 
different, and why should it be fixed in scripts/archive-source.sh?

These are genuine questions - it would help if the commit message 
explained those... In fact, what is a nix overlay and why would you use 
scripts/archive-source.sh to prepare one? :)

> 
> Signed-off-by: Joel Granados <joel.granados@kernel.org>
> ---
>   scripts/archive-source.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh
> index 30677c3ec9032ea01090f74602d839d1c571d012..a469a5e2dec4b05e51474f0a1af190c1ccf23c7e 100755
> --- a/scripts/archive-source.sh
> +++ b/scripts/archive-source.sh
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>   #
>   # Author: Fam Zheng <famz@redhat.com>
>   #
>
Re: [PATCH 1/3] scripts: nixify archive-source.sh
Posted by Joel Granados 6 months, 3 weeks ago
On Thu, Apr 10, 2025 at 02:18:01PM +0200, Paolo Bonzini wrote:
> On 4/8/25 22:14, Joel Granados wrote:
> > Use "#!/usr/bin/env bash" instead of "#!/bin/bash". This is necessary
> > for nix environments as they only provide /usr/bin/env at the standard
> > location.
> 
> I am confused, how does this not break everything else?  All the test
> scripts in tests/docker/test-* have "#!/bin/bash", and configure has
> "/bin/sh".
Not sure what "break" means here, but the "env" shebang should just work
in distros that follow (or try to) POSIX. AFAIK, to be POSIX compliant,
you need to provide an "env" for command invocation [1]. The two
previous changes that I know of [2], [3] have not had any adverse
effects that I'm aware of.

> How is the environment that runs scripts/archive-source.sh
> different, and why should it be fixed in scripts/archive-source.sh?
It is different from the other files in that I hit the issue only on
that file. I'm happy to provide a treewide change if it would make more
sense.

> 
> These are genuine questions - it would help if the commit message explained
> those...
I can weave the explanation into the commit for V2.

> In fact, what is a nix overlay and why would you use
> scripts/archive-source.sh to prepare one? :)
I now realize that mentioning a nix overlay in the commit message might
be to far from a general context. How about if I change the commit
message of the second patch to:

```
  The archive-source script appends everything directly on the tar root
  making it unsuitable for cases where a different directory structure
  is expected, like during nix packages customization.

  Add a "-d|--dir" argument that places all files under a custom root.
  Behaviour is unchanged when the argument is not given.
```

To answer the question of what an nix overlay is: It is a way of
customizing nix packages. I use it to override specific elements from a
nix package and replace them with my stuff [4]. I am working with the qemu
package and am overriding the qemu tarbal.

Best

[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/env.html
[2] https://lore.kernel.org/all/20250122-jag-nix-ify-v1-1-addb3170f93c@kernel.org/
[3] https://lore.kernel.org/all/20240817215025.161628-1-kent.overstreet@linux.dev/
[4] https://nixos.wiki/wiki/Overlays
-- 

Joel Granados
Re: [PATCH 1/3] scripts: nixify archive-source.sh
Posted by Thomas Huth 7 months, 1 week ago
On 08/04/2025 22.14, Joel Granados wrote:
> Use "#!/usr/bin/env bash" instead of "#!/bin/bash". This is necessary
> for nix environments as they only provide /usr/bin/env at the standard
> location.
> 
> Signed-off-by: Joel Granados <joel.granados@kernel.org>
> ---
>   scripts/archive-source.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh
> index 30677c3ec9032ea01090f74602d839d1c571d012..a469a5e2dec4b05e51474f0a1af190c1ccf23c7e 100755
> --- a/scripts/archive-source.sh
> +++ b/scripts/archive-source.sh
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>   #
>   # Author: Fam Zheng <famz@redhat.com>
>   #
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>