Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rever(back): #1202 pin nix version #1222

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions makes/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ in
];
replace = {
__argMakesSrc__ = projectPath "/";
__argNix__ = __nixpkgs__.nixVersions.nix_2_15;
__argNixStable__ = __nixpkgs__.nixStable;
__argNixUnstable__ = __nixpkgs__.nixUnstable;
};
entrypoint = ''
__MAKES_SRC__=__argMakesSrc__ \
__NIX__=__argNix__ \
__NIX_STABLE__=__argNixStable__ \
__NIX_UNSTABLE__=__argNixUnstable__ \
python -u __argMakesSrc__/src/cli/main/__main__.py "$@"
'';
searchPaths.source = [
Expand Down
50 changes: 34 additions & 16 deletions src/cli/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@

# Environment
__MAKES_SRC__: str = environ["__MAKES_SRC__"]
__NIX__: str = environ["__NIX__"]
__NIX_STABLE__: str = environ["__NIX_STABLE__"]
__NIX_UNSTABLE__: str = environ["__NIX_UNSTABLE__"]


# Feature flags
Expand All @@ -100,6 +101,10 @@
if K8S_COMPAT:
CON.out("Using feature flag: MAKES_K8S_COMPAT")

NIX_STABLE: bool = not bool(environ.get("MAKES_NIX_UNSTABLE"))
if not NIX_STABLE:
CON.out("Using feature flag: MAKES_NIX_UNSTABLE")


def _if(condition: Any, *value: Any) -> List[Any]:
return list(value) if condition else []
Expand All @@ -113,7 +118,11 @@ def _clone_src(src: str) -> str:
ON_EXIT.append(partial(shutil.rmtree, head, ignore_errors=True))

if abspath(src) == CWD: # `m .` ?
_clone_src_git_worktree_add(src, head)
if NIX_STABLE:
_clone_src_git_worktree_add(src, head)
else:
# Nix with Flakes already ensures a pristine git repo
head = src
else:
if (
(match := _clone_src_github(src))
Expand Down Expand Up @@ -277,12 +286,16 @@ def _nix_build(
]
)
return [
*[f"{__NIX__}/bin/nix-build"],
*["--argstr", "makesSrc", __MAKES_SRC__],
*["--argstr", "projectSrc", head],
*_if(NIX_STABLE, f"{__NIX_STABLE__}/bin/nix-build"),
*_if(not NIX_STABLE, f"{__NIX_UNSTABLE__}/bin/nix"),
*_if(not NIX_STABLE, "--experimental-features", "flakes nix-command"),
*_if(not NIX_STABLE, "build"),
*_if(NIX_STABLE, "--argstr", "makesSrc", __MAKES_SRC__),
*_if(NIX_STABLE, "--argstr", "projectSrc", head),
*["--argstr", "attrPaths", attr_paths],
*["--attr", attr],
*_if(NIX_STABLE, "--attr", attr),
*["--option", "cores", "0"],
*_if(not NIX_STABLE, "--impure"),
*["--option", "narinfo-cache-negative-ttl", "1"],
*["--option", "narinfo-cache-positive-ttl", "1"],
*["--option", "max-jobs", "auto"],
Expand All @@ -292,14 +305,15 @@ def _nix_build(
*_if(out, "--out-link", out),
*_if(not out, "--no-out-link"),
*["--show-trace"],
*[f"{__MAKES_SRC__}/src/evaluator/default.nix"],
*_if(NIX_STABLE, f"{__MAKES_SRC__}/src/evaluator/default.nix"),
*_if(not NIX_STABLE, attr),
]


def _nix_hashes(paths: bytes) -> List[str]:
cmd = [
"xargs",
f"{__NIX__}/bin/nix-store",
f"{__NIX_STABLE__}/bin/nix-store",
"--query",
"--hash",
]
Expand All @@ -312,13 +326,13 @@ def _nix_hashes(paths: bytes) -> List[str]:

def _nix_build_requisites(path: str) -> List[Tuple[str, str]]:
"""Answer the question: what do I need to build `out`."""
cmd = [f"{__NIX__}/bin/nix-store", "--query", "--deriver", path]
cmd = [f"{__NIX_STABLE__}/bin/nix-store", "--query", "--deriver", path]
out, stdout, _ = _run_outputs(cmd, stderr=None)
if out != 0:
raise SystemExit(out)

cmd = [
f"{__NIX__}/bin/nix-store",
f"{__NIX_STABLE__}/bin/nix-store",
"--query",
"--requisites",
"--include-outputs",
Expand All @@ -344,8 +358,8 @@ def _get_head(src: str) -> str:
CON.out()
head: str = _clone_src(src)

# Applies only to local repositories
if abspath(src) == CWD: # `m .` ?
# Applies only to local repositories on non-flakes Nix
if abspath(src) == CWD and NIX_STABLE: # `m .` ?
paths: Set[str] = set()

# Propagated `git add`ed files
Expand Down Expand Up @@ -396,13 +410,15 @@ def _get_config(head: str, attr_paths: str) -> Config:
out: str = _get_named_temporary_file_name()
code = _run(
args=_nix_build(
attr="config.configAsJson",
attr="config.configAsJson"
if NIX_STABLE
else f'{head}#__makes__."config:configAsJson"',
attr_paths=attr_paths,
cache=None,
head=head,
out=out,
),
env=None,
env=None if NIX_STABLE else dict(HOME=environ["HOME_IMPURE"]),
stderr=None,
stdout=sys.stderr.fileno(),
)
Expand Down Expand Up @@ -610,13 +626,15 @@ def _cli_build( # pylint: disable=too-many-arguments

code = _run(
args=_nix_build(
attr=f'config.outputs."{attr}"',
attr=f'config.outputs."{attr}"'
if NIX_STABLE
else f'{head}#__makes__."config:outputs:{attr}"',
attr_paths=attr_paths,
cache=config.cache,
head=head,
out=out,
),
env=None,
env=None if NIX_STABLE else dict(HOME=environ["HOME_IMPURE"]),
stderr=None,
stdout=None,
)
Expand Down
4 changes: 3 additions & 1 deletion src/evaluator/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{
# JSON String containing complete list of main.nix files found within projectSrc
attrPaths,
# flake inputs to inject, if any
flakeInputs ? {},
# Source code of makes, can be overriden by the user.
makesSrc,
# Path to the user's project, inside a sandbox.
Expand Down Expand Up @@ -39,7 +41,7 @@
else makesSrc;

args = import "${makesSrcOverriden}/src/args/default.nix" {
inherit (result.config) inputs;
inputs = flakeInputs // result.config.inputs;
inherit (result.config) outputs;
inherit (result.config) projectIdentifier;
inherit projectSrc;
Expand Down
6 changes: 3 additions & 3 deletions src/nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e072852d9f29be750951c1db3c63b65e68448ed5",
"sha256": "sha256:0w8cb80h83bns7a63rb7ci3aww3n6zrpvivx4blzhamnc8ipfhdp",
"rev": "4ecab3273592f27479a583fb6d975d4aba3486fe",
"sha256": "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/e072852d9f29be750951c1db3c63b65e68448ed5.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/4ecab3273592f27479a583fb6d975d4aba3486fe.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading