Skip to content

Commit

Permalink
feat(back): fluidattacks#1202 pin nix version
Browse files Browse the repository at this point in the history
- Pin nix version to 2.15 as it looks like
2.16 brings breaking changes for current back pinning method
- Stop supporting nix unstable as it is broken and no being used
- Update nixpkgs to support latest nodejs version

Signed-off-by: Daniel Salazar <[email protected]>
  • Loading branch information
dsalaza4 committed Dec 15, 2023
1 parent 85d55b2 commit 297a77a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 44 deletions.
6 changes: 2 additions & 4 deletions makes/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ in
];
replace = {
__argMakesSrc__ = projectPath "/";
__argNixStable__ = __nixpkgs__.nixStable;
__argNixUnstable__ = __nixpkgs__.nixUnstable;
__argNix__ = __nixpkgs__.nixVersions.nix_2_15;
};
entrypoint = ''
__MAKES_SRC__=__argMakesSrc__ \
__NIX_STABLE__=__argNixStable__ \
__NIX_UNSTABLE__=__argNixUnstable__ \
__NIX__=__argNix__ \
python -u __argMakesSrc__/src/cli/main/__main__.py "$@"
'';
searchPaths.source = [
Expand Down
50 changes: 16 additions & 34 deletions src/cli/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@

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


# Feature flags
Expand All @@ -101,10 +100,6 @@
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 @@ -118,11 +113,7 @@ def _clone_src(src: str) -> str:
ON_EXIT.append(partial(shutil.rmtree, head, ignore_errors=True))

if abspath(src) == CWD: # `m .` ?
if NIX_STABLE:
_clone_src_git_worktree_add(src, head)
else:
# Nix with Flakes already ensures a pristine git repo
head = src
_clone_src_git_worktree_add(src, head)
else:
if (
(match := _clone_src_github(src))
Expand Down Expand Up @@ -286,16 +277,12 @@ def _nix_build(
]
)
return [
*_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),
*[f"{__NIX__}/bin/nix-build"],
*["--argstr", "makesSrc", __MAKES_SRC__],
*["--argstr", "projectSrc", head],
*["--argstr", "attrPaths", attr_paths],
*_if(NIX_STABLE, "--attr", attr),
*["--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 @@ -305,15 +292,14 @@ def _nix_build(
*_if(out, "--out-link", out),
*_if(not out, "--no-out-link"),
*["--show-trace"],
*_if(NIX_STABLE, f"{__MAKES_SRC__}/src/evaluator/default.nix"),
*_if(not NIX_STABLE, attr),
*[f"{__MAKES_SRC__}/src/evaluator/default.nix"],
]


def _nix_hashes(paths: bytes) -> List[str]:
cmd = [
"xargs",
f"{__NIX_STABLE__}/bin/nix-store",
f"{__NIX__}/bin/nix-store",
"--query",
"--hash",
]
Expand All @@ -326,13 +312,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_STABLE__}/bin/nix-store", "--query", "--deriver", path]
cmd = [f"{__NIX__}/bin/nix-store", "--query", "--deriver", path]
out, stdout, _ = _run_outputs(cmd, stderr=None)
if out != 0:
raise SystemExit(out)

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

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

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

code = _run(
args=_nix_build(
attr=f'config.outputs."{attr}"'
if NIX_STABLE
else f'{head}#__makes__."config:outputs:{attr}"',
attr=f'config.outputs."{attr}"',
attr_paths=attr_paths,
cache=config.cache,
head=head,
out=out,
),
env=None if NIX_STABLE else dict(HOME=environ["HOME_IMPURE"]),
env=None,
stderr=None,
stdout=None,
)
Expand Down
4 changes: 1 addition & 3 deletions src/evaluator/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
{
# 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 @@ -41,7 +39,7 @@
else makesSrc;

args = import "${makesSrcOverriden}/src/args/default.nix" {
inputs = flakeInputs // result.config.inputs;
inputs = 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": "4ecab3273592f27479a583fb6d975d4aba3486fe",
"sha256": "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf",
"rev": "e072852d9f29be750951c1db3c63b65e68448ed5",
"sha256": "sha256:0w8cb80h83bns7a63rb7ci3aww3n6zrpvivx4blzhamnc8ipfhdp",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/4ecab3273592f27479a583fb6d975d4aba3486fe.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/e072852d9f29be750951c1db3c63b65e68448ed5.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

0 comments on commit 297a77a

Please sign in to comment.