[PATCH] Add wrapper scripts to run make in a Nix shell
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com> --- host/initramfs/run-make.sh | 1 + host/rootfs/run-make.sh | 1 + img/app/run-make.sh | 1 + release/live/run-make.sh | 1 + scripts/run-make.sh | 12 ++++++++++++ tools/lseek/run-make.sh | 1 + vm/sys/net/run-make.sh | 1 + 7 files changed, 18 insertions(+) diff --git a/host/initramfs/run-make.sh b/host/initramfs/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..2142d230828768016cf5a4a59a895448ae3b12d9 --- /dev/null +++ b/host/initramfs/run-make.sh @@ -0,0 +1 @@ +../../scripts/run-make.sh \ No newline at end of file diff --git a/host/rootfs/run-make.sh b/host/rootfs/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..2142d230828768016cf5a4a59a895448ae3b12d9 --- /dev/null +++ b/host/rootfs/run-make.sh @@ -0,0 +1 @@ +../../scripts/run-make.sh \ No newline at end of file diff --git a/img/app/run-make.sh b/img/app/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..2142d230828768016cf5a4a59a895448ae3b12d9 --- /dev/null +++ b/img/app/run-make.sh @@ -0,0 +1 @@ +../../scripts/run-make.sh \ No newline at end of file diff --git a/release/live/run-make.sh b/release/live/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..2142d230828768016cf5a4a59a895448ae3b12d9 --- /dev/null +++ b/release/live/run-make.sh @@ -0,0 +1 @@ +../../scripts/run-make.sh \ No newline at end of file diff --git a/scripts/run-make.sh b/scripts/run-make.sh new file mode 100755 index 0000000000000000000000000000000000000000..b865bb3461b5d3f192598d273cee278a76d0a6b7 --- /dev/null +++ b/scripts/run-make.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env -S bash -- +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com> +set -eu +case $0 in (/*) cd "${0%/*}/";; (*/*) cd "./${0%/*}";; esac +if [ ! -f shell.nix ] || [ ! -f Makefile ]; then + echo "Must have a shell.nix and a Makefile" >&2 + exit 1 +fi +cmd='exec make' +for i; do cmd+=" '"${i//\'/\'\\\'\'}\'; done +exec nix-shell --pure --run "$cmd" diff --git a/tools/lseek/run-make.sh b/tools/lseek/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..2142d230828768016cf5a4a59a895448ae3b12d9 --- /dev/null +++ b/tools/lseek/run-make.sh @@ -0,0 +1 @@ +../../scripts/run-make.sh \ No newline at end of file diff --git a/vm/sys/net/run-make.sh b/vm/sys/net/run-make.sh new file mode 120000 index 0000000000000000000000000000000000000000..38a7b0cf91ebf669e9794d91c6962cbe882de20f --- /dev/null +++ b/vm/sys/net/run-make.sh @@ -0,0 +1 @@ +../../../scripts/run-make.sh \ No newline at end of file --- base-commit: 39baa378367d95fac6ce4d0140b25203b2ee9b53 change-id: 20250807-make-wrapper-scripts-77231ac0c0a7 -- Sincerely, Demi Marie Obenour (she/her/hers)
Demi Marie Obenour <demiobenour@gmail.com> writes:
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you.
I think you'd probably be better setting up nix-direnv or something. It makes it so that you can't forget to be in the shell, but also means you can just run make, rather than having to remember to run some other script. It also comes with caching I think, so if that works you'll probably save quite a bit of time over doing a Nix evaluation for every make invocation.
On 8/8/25 11:00, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you.
I think you'd probably be better setting up nix-direnv or something. It makes it so that you can't forget to be in the shell, but also means you can just run make, rather than having to remember to run some other script. It also comes with caching I think, so if that works you'll probably save quite a bit of time over doing a Nix evaluation for every make invocation.
For general development I agree, but unless nix-direnv always rebuilds when needed I think wrappers like this might be better for scripted use. The big advantage is that they guarantee the environment variables passed to 'make' will always be up-to-date, and I'm not sure how to achieve that in a script otherwise. -- Sincerely, Demi Marie Obenour (she/her/hers)
Demi Marie Obenour <demiobenour@gmail.com> writes:
On 8/8/25 11:00, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you.
I think you'd probably be better setting up nix-direnv or something. It makes it so that you can't forget to be in the shell, but also means you can just run make, rather than having to remember to run some other script. It also comes with caching I think, so if that works you'll probably save quite a bit of time over doing a Nix evaluation for every make invocation.
For general development I agree, but unless nix-direnv always rebuilds when needed I think wrappers like this might be better for scripted use. The big advantage is that they guarantee the environment variables passed to 'make' will always be up-to-date, and I'm not sure how to achieve that in a script otherwise.
I think that's exactly what it does, but do correct me if I'm wrong.
On 8/8/25 14:02, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
On 8/8/25 11:00, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you.
I think you'd probably be better setting up nix-direnv or something. It makes it so that you can't forget to be in the shell, but also means you can just run make, rather than having to remember to run some other script. It also comes with caching I think, so if that works you'll probably save quite a bit of time over doing a Nix evaluation for every make invocation.
For general development I agree, but unless nix-direnv always rebuilds when needed I think wrappers like this might be better for scripted use. The big advantage is that they guarantee the environment variables passed to 'make' will always be up-to-date, and I'm not sure how to achieve that in a script otherwise.
I think that's exactly what it does, but do correct me if I'm wrong.
Is there a way to use nix-direnv from a script? -- Sincerely, Demi Marie Obenour (she/her/hers)
Demi Marie Obenour <demiobenour@gmail.com> writes:
On 8/8/25 14:02, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
On 8/8/25 11:00, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
It is very easy to forget to do this, and the results are confusing at best and wrong at worst. Add wrapper scripts that get it right and also automatically change to the correct directory for you.
I think you'd probably be better setting up nix-direnv or something. It makes it so that you can't forget to be in the shell, but also means you can just run make, rather than having to remember to run some other script. It also comes with caching I think, so if that works you'll probably save quite a bit of time over doing a Nix evaluation for every make invocation.
For general development I agree, but unless nix-direnv always rebuilds when needed I think wrappers like this might be better for scripted use. The big advantage is that they guarantee the environment variables passed to 'make' will always be up-to-date, and I'm not sure how to achieve that in a script otherwise.
I think that's exactly what it does, but do correct me if I'm wrong.
Is there a way to use nix-direnv from a script?
direnv exec? But it's a relatively obscure thing to want to do, because generally it makes it so you don't need to think about it…
participants (2)
-
Alyssa Ross -
Demi Marie Obenour