From 6a1423351910efb4d74596103b9ac6eda794d909 Mon Sep 17 00:00:00 2001 From: Andres Cuberos Date: Fri, 15 Dec 2023 19:11:29 -0500 Subject: [PATCH] rever(back): #1202 pin nix version - This reverts commit 932796834be608f3dddfc1c128ffda161ef653c0. --- makes/main.nix | 6 +++-- src/cli/main/cli.py | 50 ++++++++++++++++++++++++++------------- src/evaluator/default.nix | 4 +++- src/nix/sources.json | 6 ++--- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/makes/main.nix b/makes/main.nix index ad6343bb..389123db 100644 --- a/makes/main.nix +++ b/makes/main.nix @@ -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 = [ diff --git a/src/cli/main/cli.py b/src/cli/main/cli.py index dfe2a6c7..9e647e0c 100644 --- a/src/cli/main/cli.py +++ b/src/cli/main/cli.py @@ -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 @@ -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 [] @@ -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)) @@ -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"], @@ -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", ] @@ -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", @@ -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 @@ -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(), ) @@ -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, ) diff --git a/src/evaluator/default.nix b/src/evaluator/default.nix index 5d23bce4..f43d18f7 100644 --- a/src/evaluator/default.nix +++ b/src/evaluator/default.nix @@ -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. @@ -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; diff --git a/src/nix/sources.json b/src/nix/sources.json index e99edee2..87f78a25 100644 --- a/src/nix/sources.json +++ b/src/nix/sources.json @@ -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///archive/.tar.gz" } }