[PATCH 0/3] *** Fixes for nixos and other systems where dependencies not installed system wide ***

24 views
Skip to first unread message

Raymond Gauthier

unread,
Mar 3, 2023, 2:50:33 PM3/3/23
to kas-...@googlegroups.com, adl...@mailbox.org, Raymond Gauthier
Allow this tool to run on nixos systems and fixes issue when git is not installed system wide on other systems.

Original submitted via the following github PR:

<https://github.com/siemens/kas/pull/93>

Raymond Gauthier (3):
context: add support for nixos distro
context: take minimal dependencies from `PATH`
build-env: portable shebang + deps from `PATH`

kas/context.py | 13 ++++++++++++-
kas/libkas.py | 16 ++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)

--
2.36.2

Raymond Gauthier

unread,
Mar 3, 2023, 2:50:34 PM3/3/23
to kas-...@googlegroups.com, adl...@mailbox.org, Raymond Gauthier
Avoid an annoying warning and properly sets
appropriate environment variables for locale.

Signed-off-by: Raymond Gauthier <jrayga...@gmail.com>
---
kas/context.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kas/context.py b/kas/context.py
index 6ca5291..d215c0a 100644
--- a/kas/context.py
+++ b/kas/context.py
@@ -95,7 +95,7 @@ class Context:
'LANG': 'en_US.utf8',
'LANGUAGE': 'en_US'}
break
- elif distro_base in ['debian', 'ubuntu', 'gentoo']:
+ elif distro_base in ['debian', 'ubuntu', 'gentoo', 'nixos']:
self.environ = {'LC_ALL': 'en_US.UTF-8',
'LANG': 'en_US.UTF-8',
'LANGUAGE': 'en_US:en'}
--
2.36.2

Raymond Gauthier

unread,
Mar 3, 2023, 2:50:35 PM3/3/23
to kas-...@googlegroups.com, adl...@mailbox.org, Raymond Gauthier
Fixes nasty

```bash
$ kas checkout # ..
FileNotFoundError: [Errno 2] No such file or directory: 'git'
```

error when run from a nixos system or a system for which the `git`
command (or the `hg` command) is not installed system wide or is
installed from a developer environment.

Also allow us to provide `git` via a developer environment such
as `nix-env`.

Signed-off-by: Raymond Gauthier <jrayga...@gmail.com>
---
kas/context.py | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/kas/context.py b/kas/context.py
index d215c0a..397e138 100644
--- a/kas/context.py
+++ b/kas/context.py
@@ -111,6 +111,17 @@ class Context:
if val:
self.environ[key] = val

+ import shutil
+ dep_cmds = ['git', 'hg']
+ path_for_deps = ':'.join(sorted({
+ os.path.dirname(cmd_path) for cmd_path in (
+ shutil.which(cmd) for cmd in dep_cmds
+ )
+ if cmd_path is not None})
+ )
+ if path_for_deps:
+ self.environ['PATH'] = path_for_deps
+
@property
def build_dir(self):
"""
--
2.36.2

Raymond Gauthier

unread,
Mar 3, 2023, 2:50:36 PM3/3/23
to kas-...@googlegroups.com, adl...@mailbox.org, Raymond Gauthier
Replace non portable `bash` shebang by a portable one (that can be run
from `nixos` distro or any other system where `bash` is not under
`/bin/bash`).

When running the `get_bb_env` generated script, make sure that the
`PATH` environment variable includes a select set of minimal
dependencies extracted from the caller's `PATH`. This minimal
set is expected to be just enough for `get_bb_env` to run
(including the sourced `oe-init-build-env` from the `poky` repository).

Signed-off-by: Raymond Gauthier <jrayga...@gmail.com>
---
kas/libkas.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kas/libkas.py b/kas/libkas.py
index 96ba946..ed15710 100644
--- a/kas/libkas.py
+++ b/kas/libkas.py
@@ -228,8 +228,9 @@ def get_build_environ(build_system):
sys.exit(1)

with tempfile.TemporaryDirectory() as temp_dir:
- script = """#!/bin/bash
+ script = """#!/usr/bin/env bash
set -e
+ export PATH
source %s $1 > /dev/null
env
""" % init_script
@@ -238,8 +239,19 @@ def get_build_environ(build_system):
get_bb_env_file.write_text(script)
get_bb_env_file.chmod(0o775)

+ import shutil
+ dep_cmds = ['bash', 'dirname', 'readlink' ,'python3' ,'sed']
+ path_for_deps = ':'.join(sorted({
+ os.path.dirname(cmd_path) for cmd_path in (
+ shutil.which(cmd) for cmd in dep_cmds
+ )
+ if cmd_path is not None})
+ )
+
env = {}
- env['PATH'] = '/usr/sbin:/usr/bin:/sbin:/bin'
+ from itertools import chain
+ env['PATH'] = ':'.join(
+ chain([path_for_deps], ['/usr/sbin:/usr/bin:/sbin:/bin']))

(_, output) = run_cmd([str(get_bb_env_file), get_context().build_dir],
cwd=init_repo.path, env=env, liveupdate=False)
--
2.36.2

Michael Adler

unread,
Apr 17, 2023, 3:56:38 AM4/17/23
to Raymond Gauthier, kas-...@googlegroups.com
Hi Raymond,

thanks for your contribution. I'm not a maintainer of this project (but NixOS
user), so to revive this patch set I will do a short review.

> + script = """#!/usr/bin/env bash
> set -e
> + export PATH

I'm wondering, is the `export` statement really necessary here?

> + import shutil
> + dep_cmds = ['bash', 'dirname', 'readlink' ,'python3' ,'sed']
> + path_for_deps = ':'.join(sorted({
> + os.path.dirname(cmd_path) for cmd_path in (
> + shutil.which(cmd) for cmd in dep_cmds
> + )
> + if cmd_path is not None})
> + )

It's basically the same logic as in the previous patch, so following the DRY
principle, it might be worth to extract this into a method. Also, sorting the
list isn't necessary, is it?

Kind Regards,
Michael

--
Michael Adler

Siemens AG
T CED SES-DE
Otto-Hahn-Ring 6
81739 München, Deutschland

Siemens Aktiengesellschaft: Vorsitzender des Aufsichtsrats: Jim Hagemann
Snabe; Vorstand: Roland Busch, Vorsitzender; Klaus Helmrich, Cedrik Neike,
Matthias Rebellius, Ralf P. Thomas, Judith Wiese; Sitz der Gesellschaft:
Berlin und München, Deutschland; Registergericht: Berlin-Charlottenburg, HRB
12300, München, HRB 6684; WEEE-Reg.-Nr. DE 23691322

Jan Kiszka

unread,
Jun 23, 2023, 2:27:38 PM6/23/23
to Raymond Gauthier, kas-...@googlegroups.com, adl...@mailbox.org
Sorry, just noticed that these fell through some cracks. I suspect the
patches need rebasing now, there were a few comments by Michael, and I
would suggest to reorder so that NixOS is only officially added after
the ground is laid for it.

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Reply all
Reply to author
Forward
0 new messages