Apply nix fmt on setupNixInNixPython-only

This commit is contained in:
Jörg Thalheim
2025-06-17 11:20:43 +02:00
parent 4ecf71824c
commit e5ff78c28f
2 changed files with 80 additions and 35 deletions

View File

@@ -22,10 +22,15 @@ nixosLib.runTest (
clan.test.fromFlake = ./.; clan.test.fromFlake = ./.;
extraPythonPackages = _p: [
clan-core.legacyPackages.${hostPkgs.system}.setupNixInNixPythonPackage
];
testScript = testScript =
{ nodes, ... }: { nodes, ... }:
'' ''
${clan-core.legacyPackages.${hostPkgs.system}.setupNixInNixPython} from setup_nix_in_nix import setup_nix_in_nix # type: ignore[import-untyped]
setup_nix_in_nix()
def run_clan(cmd: list[str], **kwargs) -> str: def run_clan(cmd: list[str], **kwargs) -> str:
import subprocess import subprocess

View File

@@ -1,37 +1,77 @@
{ {
perSystem = { perSystem =
legacyPackages = { { pkgs, ... }:
setupNixInNix = '' {
export HOME=$TMPDIR legacyPackages = {
export NIX_STATE_DIR=$TMPDIR/nix setupNixInNix = ''
export NIX_CONF_DIR=$TMPDIR/etc set -xeu -o pipefail
export IN_NIX_SANDBOX=1 export HOME=$TMPDIR
export CLAN_TEST_STORE=$TMPDIR/store export NIX_STATE_DIR=$TMPDIR/nix
# required to prevent concurrent 'nix flake lock' operations export NIX_CONF_DIR=$TMPDIR/etc
export LOCK_NIX=$TMPDIR/nix_lock export IN_NIX_SANDBOX=1
mkdir -p "$CLAN_TEST_STORE/nix/store" export CLAN_TEST_STORE=$TMPDIR/store
mkdir -p "$CLAN_TEST_STORE/nix/var/nix/gcroots" # required to prevent concurrent 'nix flake lock' operations
if [[ -n "''${closureInfo-}" ]]; then export LOCK_NIX=$TMPDIR/nix_lock
xargs cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths" mkdir -p "$CLAN_TEST_STORE/nix/store"
nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration" mkdir -p "$CLAN_TEST_STORE/nix/var/nix/gcroots"
fi if [[ -n "''${closureInfo-}" ]]; then
''; # ${pkgs.findutils}/bin/xargs ${pkgs.xcp}/bin/xcp --recursive --target-directory "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths"
setupNixInNixPython = '' ${pkgs.findutils}/bin/xargs ${pkgs.coreutils}/bin/cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths"
from os import environ ${pkgs.nix}/bin/nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration"
import subprocess fi
from pathlib import Path '';
environ['HOME'] = environ['TMPDIR']
environ['NIX_STATE_DIR'] = environ['TMPDIR'] + '/nix' setupNixInNixPythonPackage = pkgs.python3Packages.buildPythonPackage {
environ['NIX_CONF_DIR'] = environ['TMPDIR'] + '/etc' pname = "setup-nix-in-nix";
environ['IN_NIX_SANDBOX'] = '1' version = "1.0.0";
environ['CLAN_TEST_STORE'] = environ['TMPDIR'] + '/store' format = "other";
environ['LOCK_NIX'] = environ['TMPDIR'] + '/nix_lock'
Path(environ['CLAN_TEST_STORE'] + '/nix/store').mkdir(parents=True, exist_ok=True) dontUnpack = true;
Path(environ['CLAN_TEST_STORE'] + '/nix/var/nix/gcroots').mkdir(parents=True, exist_ok=True)
if 'closureInfo' in environ: installPhase = ''
subprocess.run(['cp', '--recursive', '--target', environ['CLAN_TEST_STORE'] + '/nix/store'] + environ['closureInfo'].split(), check=True) mkdir -p $out/${pkgs.python3.sitePackages}
subprocess.run(['nix-store', '--load-db', '--store', environ['CLAN_TEST_STORE']] + ['<', environ['closureInfo'] + '/registration'], shell=True, check=True) cat > $out/${pkgs.python3.sitePackages}/setup_nix_in_nix.py << 'EOF'
''; from os import environ
import subprocess
from pathlib import Path
def setup_nix_in_nix():
"""Set up a Nix store inside the test environment."""
environ['HOME'] = environ['TMPDIR']
environ['NIX_STATE_DIR'] = environ['TMPDIR'] + '/nix'
environ['NIX_CONF_DIR'] = environ['TMPDIR'] + '/etc'
environ['IN_NIX_SANDBOX'] = '1'
environ['CLAN_TEST_STORE'] = environ['TMPDIR'] + '/store'
environ['LOCK_NIX'] = environ['TMPDIR'] + '/nix_lock'
Path(environ['CLAN_TEST_STORE'] + '/nix/store').mkdir(parents=True, exist_ok=True)
Path(environ['CLAN_TEST_STORE'] + '/nix/var/nix/gcroots').mkdir(parents=True, exist_ok=True)
if 'closureInfo' in environ:
# Read store paths from the closure info file
with open(environ['closureInfo'] + '/store-paths', 'r') as f:
store_paths = f.read().strip().split('\n')
# Copy store paths using absolute path to cp
subprocess.run(
['${pkgs.coreutils}/bin/cp', '--recursive', '--target', environ['CLAN_TEST_STORE'] + '/nix/store'] + store_paths,
check=True
)
# Load the nix database using absolute path to nix-store
with open(environ['closureInfo'] + '/registration', 'r') as f:
subprocess.run(
['${pkgs.nix}/bin/nix-store', '--load-db', '--store', environ['CLAN_TEST_STORE']],
input=f.read(),
text=True,
check=True
)
EOF
touch $out/${pkgs.python3.sitePackages}/py.typed
'';
doCheck = false;
};
};
}; };
};
} }