diff --git a/nixos/modules/system/boot/loader/limine/limine-install.py b/nixos/modules/system/boot/loader/limine/limine-install.py index 9add26b636c6..dacf4a339d0e 100644 --- a/nixos/modules/system/boot/loader/limine/limine-install.py +++ b/nixos/modules/system/boot/loader/limine/limine-install.py @@ -347,7 +347,7 @@ def config_entry(levels: int, bootspec: BootSpec, label: str, time: str) -> str: os.path.basename(bootspec.toplevel) + "-secrets" ) - if os.system(bootspec.initrdSecrets + " " + initrd_secrets_path_temp) != 0: + if subprocess.run([bootspec.initrdSecrets, initrd_secrets_path_temp]).returncode != 0: print( f'warning: failed to create initrd secrets for "{label}"', file=sys.stderr, diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 5e2b349d0813..7b5ce335f0bf 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -63,7 +63,7 @@ let - `config.node.pkgs.` or `config.nodes.foo.nixpkgs.pkgs.` to refer to the Nixpkgs used on the VM guest(s). - `hostPkgs.` when invoking commands on the VM host (e.g. in Python - `os.system("foo")`) + `subprocess.run(["foo"])`) - Since the runTest argument is a module instead of a function, arguments must be passed as option definitions. You may declare explicit `options` for the test parameter(s), or use the diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix index a59f94b94edf..ecc6240fc888 100644 --- a/nixos/tests/boot.nix +++ b/nixos/tests/boot.nix @@ -203,11 +203,26 @@ in makeTest { name = "boot-uboot-extlinux"; nodes = { }; - testScript = '' - import os + testScript = /* py */ '' + import subprocess # Create a mutable linked image backed by the read-only SD image - if os.system("${pkgs.qemu}/bin/qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0: + if ( + subprocess.run( + [ + "${pkgs.qemu}/bin/qemu-img", + "create", + "-f", + "qcow2", + "-F", + "raw", + "-b", + "${sdImage}", + "${mutableImage}", + ] + ).returncode + != 0 + ): raise RuntimeError("Could not create mutable linked image") machine = create_machine("${startCommand}") diff --git a/nixos/tests/ec2-image.nix b/nixos/tests/ec2-image.nix index df07d14b8ba7..b711ceadc2d5 100644 --- a/nixos/tests/ec2-image.nix +++ b/nixos/tests/ec2-image.nix @@ -135,7 +135,17 @@ in public_key = os.path.join(key_dir, "id_ed25519.pub") # Generate key pair using host SSH tools - ret = os.system(f"${hostPkgs.openssh}/bin/ssh-keygen -t ed25519 -f {private_key} -N \"\"") + ret = subprocess.run( + [ + "${hostPkgs.openssh}/bin/ssh-keygen", + "-t", + "ed25519", + "-f", + private_key, + "-N", + "" + ] + ).returncode if ret != 0: raise Exception("Failed to generate SSH key pair") diff --git a/nixos/tests/ghostunnel-modular.nix b/nixos/tests/ghostunnel-modular.nix index bb4cef2a9f08..7fa301168a46 100644 --- a/nixos/tests/ghostunnel-modular.nix +++ b/nixos/tests/ghostunnel-modular.nix @@ -54,13 +54,13 @@ }; testScript = '' - import os + import subprocess # prepare certificates def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/nixos/tests/ghostunnel.nix b/nixos/tests/ghostunnel.nix index acd9c4331835..58749591ffbc 100644 --- a/nixos/tests/ghostunnel.nix +++ b/nixos/tests/ghostunnel.nix @@ -48,13 +48,13 @@ }; testScript = '' - import os + import subprocess # prepare certificates def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/nixos/tests/haproxy.nix b/nixos/tests/haproxy.nix index 107010528737..20bcd700bb58 100644 --- a/nixos/tests/haproxy.nix +++ b/nixos/tests/haproxy.nix @@ -69,12 +69,12 @@ }; }; testScript = '' - import os + import subprocess # Helpers def cmd(command): print(f"+{command}") - r = os.system(command) + r = subprocess.run(command, shell=True).returncode if r != 0: raise Exception(f"Command {command} failed with exit code {r}") diff --git a/pkgs/by-name/mi/microsoft-edge/update.py b/pkgs/by-name/mi/microsoft-edge/update.py index d2298c382e6f..1e6419338fce 100755 --- a/pkgs/by-name/mi/microsoft-edge/update.py +++ b/pkgs/by-name/mi/microsoft-edge/update.py @@ -1,7 +1,7 @@ #! /usr/bin/env nix-shell #! nix-shell -i python3 -p python3Packages.packaging python3Packages.python-debian common-updater-scripts -import os +import subprocess from collections import OrderedDict from os.path import abspath, dirname from urllib import request @@ -39,8 +39,8 @@ def write_expression(): version = Version.re_valid_version.match(latest["stable"]["Version"]).group( "upstream_version" ) - os.system(f'update-source-version microsoft-edge "{version}"') - os.system(f'update-source-version msedgedriver "{version}"') + subprocess.run(["update-source-version", "microsoft-edge", version]) + subprocess.run(["update-source-version", "msedgedriver", version]) write_expression() diff --git a/pkgs/development/python-modules/courlan/default.nix b/pkgs/development/python-modules/courlan/default.nix index d3e63da7213b..86da2f43e917 100644 --- a/pkgs/development/python-modules/courlan/default.nix +++ b/pkgs/development/python-modules/courlan/default.nix @@ -39,7 +39,7 @@ buildPythonPackage (finalAttrs: { substituteInPlace tests/unit_tests.py \ --replace-fail \ 'assert os.system("courlan --help") == 0' \ - 'assert os.system("${courlanBinPath} --help") == 0' \ + 'assert subprocess.run(["${courlanBinPath}", "--help"]).returncode == 0' \ --replace-fail \ 'courlan_bin = "courlan"' \ 'courlan_bin = "${courlanBinPath}"' diff --git a/pkgs/development/python-modules/riscof/make_writeable.patch b/pkgs/development/python-modules/riscof/make_writeable.patch index 938f9913a7ad..c597338cda00 100644 --- a/pkgs/development/python-modules/riscof/make_writeable.patch +++ b/pkgs/development/python-modules/riscof/make_writeable.patch @@ -1,25 +1,33 @@ diff --git a/riscof/cli.py b/riscof/cli.py -index 26af62e..9d0ddbf 100644 +index 26af62e..94051ae 100644 --- a/riscof/cli.py +++ b/riscof/cli.py -@@ -502,6 +502,7 @@ def setup(dutname,refname,work_dir): +@@ -7,6 +7,7 @@ import os + import sys + import pytz + import shutil ++import subprocess + import configparser + import distutils.dir_util + +@@ -502,6 +503,7 @@ def setup(dutname,refname,work_dir): src = os.path.join(constants.root, "Templates/setup/model/") dest = os.path.join(cwd, dutname) distutils.dir_util.copy_tree(src, dest) -+ os.system(f"chmod +w -R '{dest}'") ++ subprcess.run(["chmod", "+w", "-R", dest]) os.rename(cwd+'/'+dutname+'/model_isa.yaml', cwd+'/'+dutname+'/'+dutname+'_isa.yaml') -@@ -525,10 +526,12 @@ def setup(dutname,refname,work_dir): +@@ -525,10 +527,12 @@ def setup(dutname,refname,work_dir): src = os.path.join(constants.root, "Templates/setup/sail_cSim/") dest = os.path.join(cwd, refname) distutils.dir_util.copy_tree(src, dest) -+ os.system(f"chmod +w -R '{dest}'") ++ subprcess.run(["chmod", "+w", "-R", dest]) else: src = os.path.join(constants.root, "Templates/setup/reference/") dest = os.path.join(cwd, refname) distutils.dir_util.copy_tree(src, dest) -+ os.system(f"chmod +w -R '{dest}'") ++ subprcess.run(["chmod", "+w", "-R", dest]) os.rename(cwd+'/'+refname+'/riscof_model.py', cwd+'/'+refname+'/riscof_'+refname+'.py') with open(cwd+'/'+refname+'/riscof_'+refname+'.py', 'r') as file : diff --git a/pkgs/os-specific/linux/usbrelay/test.nix b/pkgs/os-specific/linux/usbrelay/test.nix index b7894b0da773..60118dee1cd3 100644 --- a/pkgs/os-specific/linux/usbrelay/test.nix +++ b/pkgs/os-specific/linux/usbrelay/test.nix @@ -45,9 +45,11 @@ import ../../../../nixos/tests/make-test-python.nix ( documentation.nixos.enable = false; # building nixos manual takes long time }; - testScript = '' + testScript = /* py */ '' import os - if os.waitstatus_to_exitcode(os.system("lsusb -d 16c0:05df")) != 0: + import subprocess + + if os.waitstatus_to_exitcode(subprocess.run(["lsusb", "-d", "16c0:05df"]).returncode) != 0: print("No USB relay detected, skipping test") import sys sys.exit(2)