use experimental flags everywhere
This commit is contained in:
@@ -3,18 +3,22 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from .nix import nix_command
|
||||||
|
|
||||||
|
|
||||||
def create(args: argparse.Namespace) -> None:
|
def create(args: argparse.Namespace) -> None:
|
||||||
os.makedirs(args.folder, exist_ok=True)
|
os.makedirs(args.folder, exist_ok=True)
|
||||||
# TODO create clan template in flake
|
# TODO create clan template in flake
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
|
nix_command(
|
||||||
[
|
[
|
||||||
"nix",
|
|
||||||
"flake",
|
"flake",
|
||||||
"init",
|
"init",
|
||||||
"-t",
|
"-t",
|
||||||
"git+https://git.clan.lol/clan/clan-core#new-clan",
|
"git+https://git.clan.lol/clan/clan-core#new-clan",
|
||||||
]
|
]
|
||||||
|
),
|
||||||
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +28,7 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
"-f",
|
"-f",
|
||||||
"--folder",
|
"--folder",
|
||||||
help="the folder where the clan is defined, default to the current folder",
|
help="the folder where the clan is defined, default to the current folder",
|
||||||
default=os.environ["PWD"],
|
default=os.getcwd(),
|
||||||
)
|
)
|
||||||
subparser = parser.add_subparsers(
|
subparser = parser.add_subparsers(
|
||||||
title="command",
|
title="command",
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import subprocess
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Optional, Type, Union
|
from typing import Any, Optional, Type, Union
|
||||||
|
|
||||||
from clan_cli.errors import ClanError
|
from ..errors import ClanError
|
||||||
|
from ..nix import nix_eval
|
||||||
|
|
||||||
script_dir = Path(__file__).parent
|
script_dir = Path(__file__).parent
|
||||||
|
|
||||||
@@ -30,11 +31,9 @@ def schema_from_module_file(
|
|||||||
slib.parseModule {absolute_path}
|
slib.parseModule {absolute_path}
|
||||||
"""
|
"""
|
||||||
# run the nix expression and parse the output as json
|
# run the nix expression and parse the output as json
|
||||||
return json.loads(
|
cmd = nix_eval(["--expr", nix_expr])
|
||||||
subprocess.check_output(
|
proc = subprocess.run(cmd, stdout=subprocess.PIPE, check=True)
|
||||||
["nix", "eval", "--impure", "--json", "--expr", nix_expr]
|
return json.loads(proc.stdout)
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def subtype_from_schema(schema: dict[str, Any]) -> Type:
|
def subtype_from_schema(schema: dict[str, Any]) -> Type:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import subprocess
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ..dirs import get_clan_flake_toplevel
|
from ..dirs import get_clan_flake_toplevel
|
||||||
from ..nix import nix_eval
|
from ..nix import nix_command, nix_eval
|
||||||
from ..secrets.generate import generate_secrets
|
from ..secrets.generate import generate_secrets
|
||||||
from ..secrets.upload import upload_secrets
|
from ..secrets.upload import upload_secrets
|
||||||
from ..ssh import Host, HostGroup, HostKeyCheck
|
from ..ssh import Host, HostGroup, HostKeyCheck
|
||||||
@@ -22,7 +22,7 @@ def deploy_nixos(hosts: HostGroup) -> None:
|
|||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["NIX_SSHOPTS"] = ssh_arg
|
env["NIX_SSHOPTS"] = ssh_arg
|
||||||
res = h.run_local(
|
res = h.run_local(
|
||||||
["nix", "flake", "archive", "--to", f"ssh://{target}", "--json"],
|
nix_command(["flake", "archive", "--to", f"ssh://{target}", "--json"]),
|
||||||
check=True,
|
check=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
extra_env=env,
|
extra_env=env,
|
||||||
|
|||||||
@@ -4,28 +4,35 @@ import tempfile
|
|||||||
from .dirs import nixpkgs_flake, nixpkgs_source, unfree_nixpkgs
|
from .dirs import nixpkgs_flake, nixpkgs_source, unfree_nixpkgs
|
||||||
|
|
||||||
|
|
||||||
|
def nix_command(flags: list[str]) -> list[str]:
|
||||||
|
return ["nix", "--experimental-features", "nix-command flakes"] + flags
|
||||||
|
|
||||||
|
|
||||||
def nix_build(
|
def nix_build(
|
||||||
flags: list[str],
|
flags: list[str],
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return [
|
return (
|
||||||
"nix",
|
nix_command(
|
||||||
|
[
|
||||||
"build",
|
"build",
|
||||||
"--no-link",
|
"--no-link",
|
||||||
"--print-out-paths",
|
"--print-out-paths",
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
] + flags
|
]
|
||||||
|
)
|
||||||
|
+ flags
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def nix_eval(flags: list[str]) -> list[str]:
|
def nix_eval(flags: list[str]) -> list[str]:
|
||||||
default_flags = [
|
default_flags = nix_command(
|
||||||
"nix",
|
[
|
||||||
"eval",
|
"eval",
|
||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--json",
|
"--json",
|
||||||
"--extra-experimental-features",
|
|
||||||
"nix-command flakes",
|
|
||||||
]
|
]
|
||||||
|
)
|
||||||
if os.environ.get("IN_NIX_SANDBOX"):
|
if os.environ.get("IN_NIX_SANDBOX"):
|
||||||
with tempfile.TemporaryDirectory() as nix_store:
|
with tempfile.TemporaryDirectory() as nix_store:
|
||||||
return (
|
return (
|
||||||
@@ -51,14 +58,13 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
|||||||
return cmd
|
return cmd
|
||||||
wrapped_packages = [f"nixpkgs#{p}" for p in packages]
|
wrapped_packages = [f"nixpkgs#{p}" for p in packages]
|
||||||
return (
|
return (
|
||||||
|
nix_command(
|
||||||
[
|
[
|
||||||
"nix",
|
|
||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
|
||||||
"nix-command flakes",
|
|
||||||
"--inputs-from",
|
"--inputs-from",
|
||||||
f"{str(nixpkgs_flake())}",
|
f"{str(nixpkgs_flake())}",
|
||||||
]
|
]
|
||||||
|
)
|
||||||
+ wrapped_packages
|
+ wrapped_packages
|
||||||
+ ["-c"]
|
+ ["-c"]
|
||||||
+ cmd
|
+ cmd
|
||||||
@@ -69,14 +75,13 @@ def unfree_nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
|||||||
if os.environ.get("IN_NIX_SANDBOX"):
|
if os.environ.get("IN_NIX_SANDBOX"):
|
||||||
return cmd
|
return cmd
|
||||||
return (
|
return (
|
||||||
|
nix_command(
|
||||||
[
|
[
|
||||||
"nix",
|
|
||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
|
||||||
"nix-command flakes",
|
|
||||||
"-f",
|
"-f",
|
||||||
str(unfree_nixpkgs()),
|
str(unfree_nixpkgs()),
|
||||||
]
|
]
|
||||||
|
)
|
||||||
+ packages
|
+ packages
|
||||||
+ ["-c"]
|
+ ["-c"]
|
||||||
+ cmd
|
+ cmd
|
||||||
|
|||||||
@@ -30,9 +30,8 @@ def test_ssh_no_pass(
|
|||||||
monkeypatch.delenv("IN_NIX_SANDBOX")
|
monkeypatch.delenv("IN_NIX_SANDBOX")
|
||||||
cmd: list[Union[str, utils.Any]] = [
|
cmd: list[Union[str, utils.Any]] = [
|
||||||
"nix",
|
"nix",
|
||||||
|
fp.any(),
|
||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
|
||||||
"nix-command flakes",
|
|
||||||
fp.any(),
|
fp.any(),
|
||||||
"-c",
|
"-c",
|
||||||
"torify",
|
"torify",
|
||||||
@@ -61,9 +60,8 @@ def test_ssh_with_pass(
|
|||||||
monkeypatch.delenv("IN_NIX_SANDBOX")
|
monkeypatch.delenv("IN_NIX_SANDBOX")
|
||||||
cmd: list[Union[str, utils.Any]] = [
|
cmd: list[Union[str, utils.Any]] = [
|
||||||
"nix",
|
"nix",
|
||||||
|
fp.any(),
|
||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
|
||||||
"nix-command flakes",
|
|
||||||
fp.any(),
|
fp.any(),
|
||||||
"-c",
|
"-c",
|
||||||
"torify",
|
"torify",
|
||||||
|
|||||||
Reference in New Issue
Block a user