2023-07-26 06:00:07 +00:00
|
|
|
import os
|
2023-08-26 08:32:04 +00:00
|
|
|
import tempfile
|
2023-07-26 06:00:07 +00:00
|
|
|
|
2023-09-06 15:29:49 +00:00
|
|
|
from .dirs import nixpkgs_flake, nixpkgs_source, unfree_nixpkgs
|
2023-08-26 09:23:15 +00:00
|
|
|
|
2023-07-26 06:00:07 +00:00
|
|
|
|
2023-08-26 08:32:04 +00:00
|
|
|
def nix_eval(flags: list[str]) -> list[str]:
|
|
|
|
if os.environ.get("IN_NIX_SANDBOX"):
|
|
|
|
with tempfile.TemporaryDirectory() as nix_store:
|
|
|
|
return [
|
|
|
|
"nix",
|
|
|
|
"eval",
|
|
|
|
"--show-trace",
|
|
|
|
"--extra-experimental-features",
|
|
|
|
"nix-command flakes",
|
2023-09-06 12:40:00 +00:00
|
|
|
"--override-input",
|
|
|
|
"nixpkgs",
|
2023-09-06 15:29:49 +00:00
|
|
|
str(nixpkgs_source()),
|
2023-08-26 08:32:04 +00:00
|
|
|
# --store is required to prevent this error:
|
|
|
|
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
|
|
|
|
"--store",
|
|
|
|
nix_store,
|
|
|
|
] + flags
|
|
|
|
return [
|
|
|
|
"nix",
|
|
|
|
"eval",
|
|
|
|
"--show-trace",
|
|
|
|
"--extra-experimental-features",
|
|
|
|
"nix-command flakes",
|
|
|
|
] + flags
|
|
|
|
|
|
|
|
|
2023-07-26 06:00:07 +00:00
|
|
|
def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
2023-08-26 09:23:15 +00:00
|
|
|
# we cannot use nix-shell inside the nix sandbox
|
|
|
|
# in our tests we just make sure we have all the packages
|
|
|
|
if os.environ.get("IN_NIX_SANDBOX"):
|
|
|
|
return cmd
|
|
|
|
wrapped_packages = [f"nixpkgs#{p}" for p in packages]
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
"nix",
|
|
|
|
"shell",
|
|
|
|
"--extra-experimental-features",
|
|
|
|
"nix-command flakes",
|
2023-09-06 12:40:00 +00:00
|
|
|
"--inputs-from",
|
2023-09-06 15:29:49 +00:00
|
|
|
f"{str(nixpkgs_flake())}",
|
2023-08-26 09:23:15 +00:00
|
|
|
]
|
|
|
|
+ wrapped_packages
|
|
|
|
+ ["-c"]
|
|
|
|
+ cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def unfree_nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
|
|
|
if os.environ.get("IN_NIX_SANDBOX"):
|
2023-07-26 06:00:07 +00:00
|
|
|
return cmd
|
2023-08-26 09:23:15 +00:00
|
|
|
return (
|
|
|
|
[
|
|
|
|
"nix",
|
|
|
|
"shell",
|
|
|
|
"--extra-experimental-features",
|
|
|
|
"nix-command flakes",
|
|
|
|
"-f",
|
|
|
|
str(unfree_nixpkgs()),
|
|
|
|
]
|
|
|
|
+ packages
|
|
|
|
+ ["-c"]
|
|
|
|
+ cmd
|
|
|
|
)
|