From 8e48b6fd744bdfb50b9c315191ccb409d673ebf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Mon, 31 May 2021 17:57:43 +0200 Subject: [PATCH 1/2] add NixOS support to mach and automatically re-launch mach in nix-shell --- mach | 12 +++++++++++- python/servo/bootstrap.py | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mach b/mach index bfee69d7326..e0073fc7ae7 100755 --- a/mach +++ b/mach @@ -106,4 +106,14 @@ if __name__ == '__main__': orig_command_line = forking.get_command_line forking.get_command_line = my_get_command_line - main(sys.argv) + if os.path.exists('/etc/NIXOS') and not 'IN_NIX_SHELL' in os.environ: # we're on a nixOS system, need to run mach in nix-shell + import subprocess + from shlex import quote + mach_dir = os.path.abspath(os.path.dirname(__file__)) + try: + # sys argv already contains the ./mach part, so we just need to pass it as-is + subprocess.Popen(['nix-shell', mach_dir + '/etc/shell.nix', '--run', ' '.join(map(quote, sys.argv))]).wait() + except KeyboardInterrupt: + sys.exit(0) + else: + main(sys.argv) diff --git a/python/servo/bootstrap.py b/python/servo/bootstrap.py index 9c94d7cfae9..21fcd967693 100644 --- a/python/servo/bootstrap.py +++ b/python/servo/bootstrap.py @@ -383,6 +383,7 @@ def get_linux_distribution(): 'debian gnu/linux', 'fedora', 'void', + 'nixos', ]: raise Exception('mach bootstrap does not support %s, please file a bug' % distrib) @@ -398,6 +399,11 @@ def bootstrap(context, force=False, specific=None): elif "linux-gnu" in host_triple(): distrib, version = get_linux_distribution() + if distrib.lower() == 'nixos': + print('NixOS does not need bootstrap') + print('just run ./mach build') + return + context.distro = distrib context.distro_version = version bootstrapper = LINUX_SPECIFIC_BOOTSTRAPPERS.get(specific, linux) From 49fc87f385a8b59a6004049b0edb07bc30459863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Mon, 21 Jun 2021 09:12:15 +0200 Subject: [PATCH 2/2] extend message about nixOS shell --- mach | 1 + python/servo/bootstrap.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mach b/mach index e0073fc7ae7..c6efe1a9411 100755 --- a/mach +++ b/mach @@ -110,6 +110,7 @@ if __name__ == '__main__': import subprocess from shlex import quote mach_dir = os.path.abspath(os.path.dirname(__file__)) + print('NOTE: Entering nix-shell etc/shell.nix') try: # sys argv already contains the ./mach part, so we just need to pass it as-is subprocess.Popen(['nix-shell', mach_dir + '/etc/shell.nix', '--run', ' '.join(map(quote, sys.argv))]).wait() diff --git a/python/servo/bootstrap.py b/python/servo/bootstrap.py index 21fcd967693..92068f3519b 100644 --- a/python/servo/bootstrap.py +++ b/python/servo/bootstrap.py @@ -400,8 +400,12 @@ def bootstrap(context, force=False, specific=None): distrib, version = get_linux_distribution() if distrib.lower() == 'nixos': - print('NixOS does not need bootstrap') - print('just run ./mach build') + print('NixOS does not need bootstrap, it will automatically enter a nix-shell') + print('Just run ./mach build') + print('') + print('You will need to run a nix-shell if you are trying to run any of the built binaries') + print('To enter the nix-shell manually use:') + print(' $ nix-shell etc/shell.nix') return context.distro = distrib