mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-09-21 03:19:17 +03:00
Merge pull request #94 from zimbatm/one-nixpkgs-instance
use one nixpkgs instance
This commit is contained in:
commit
e5396006c0
10
flake.nix
10
flake.nix
@ -41,7 +41,7 @@
|
||||
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
|
||||
forAllSystems = f: lib.genAttrs supportedSystems (system:
|
||||
f system (import nixpkgs { inherit system; overlays = [ self.overlay ]; })
|
||||
f system nixpkgs.legacyPackages.${system}
|
||||
);
|
||||
|
||||
# To use dream2nix in non-flake + non-IFD enabled repos, the source code of dream2nix
|
||||
@ -113,14 +113,6 @@
|
||||
|
||||
in
|
||||
{
|
||||
# overlay with flakes enabled nix
|
||||
# (all of dream2nix cli dependends on nix ^2.4)
|
||||
overlay = final: prev: {
|
||||
nix = prev.writeScriptBin "nix" ''
|
||||
${final.nixUnstable}/bin/nix --option experimental-features "nix-command flakes" "$@"
|
||||
'';
|
||||
};
|
||||
|
||||
# System independent dream2nix api.
|
||||
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
||||
# Produces flake-like output schema.
|
||||
|
@ -12,7 +12,7 @@ import networkx as nx
|
||||
from cleo import Command, argument, option
|
||||
|
||||
from utils import config, dream2nix_src, checkLockJSON, list_translators_for_source, strip_hashes_from_lock
|
||||
from nix_ffi import callNixFunction, buildNixFunction, buildNixAttribute
|
||||
from nix_ffi import nix, callNixFunction, buildNixFunction, buildNixAttribute
|
||||
|
||||
|
||||
class AddCommand(Command):
|
||||
@ -294,12 +294,9 @@ class AddCommand(Command):
|
||||
with open(outputDreamLock, 'w') as f:
|
||||
json.dump(lock, f, indent=2)
|
||||
# compute FOD hash of aggregated sources
|
||||
proc = sp.run(
|
||||
[
|
||||
"nix", "build", "--impure", "-L", "--show-trace", "--expr",
|
||||
f"(import {dream2nix_src} {{}}).fetchSources {{ dreamLock = {outputDreamLock}; }}"
|
||||
],
|
||||
capture_output=True,
|
||||
proc = nix(
|
||||
"build", "--impure", "-L", "--show-trace", "--expr",
|
||||
f"(import {dream2nix_src} {{}}).fetchSources {{ dreamLock = {outputDreamLock}; }}"
|
||||
)
|
||||
# read the output hash from the failed build log
|
||||
match = re.search(r"FOD_HASH=(.*=)", proc.stderr.decode())
|
||||
|
@ -6,6 +6,8 @@ import tempfile
|
||||
|
||||
dream2nix_src = os.environ.get("dream2nixSrc")
|
||||
|
||||
def nix(*args, **kwargs):
|
||||
return sp.run(["nix", "--option", "experimental-features", "nix-command flakes"] + list(args), capture_output=True, **kwargs)
|
||||
|
||||
def callNixFunction(function_path, **kwargs):
|
||||
with tempfile.NamedTemporaryFile("w") as input_json_file:
|
||||
@ -15,19 +17,16 @@ def callNixFunction(function_path, **kwargs):
|
||||
env.update(dict(
|
||||
FUNC_ARGS=input_json_file.name
|
||||
))
|
||||
proc = sp.run(
|
||||
[
|
||||
"nix", "eval", "--show-trace", "--impure", "--raw", "--expr",
|
||||
f'''
|
||||
let
|
||||
d2n = (import {dream2nix_src} {{}});
|
||||
in
|
||||
builtins.toJSON (
|
||||
(d2n.utils.callViaEnv d2n.{function_path})
|
||||
)
|
||||
''',
|
||||
],
|
||||
capture_output=True,
|
||||
proc = nix(
|
||||
"eval", "--show-trace", "--impure", "--raw", "--expr",
|
||||
f'''
|
||||
let
|
||||
d2n = (import {dream2nix_src} {{}});
|
||||
in
|
||||
builtins.toJSON (
|
||||
(d2n.utils.callViaEnv d2n.{function_path})
|
||||
)
|
||||
''',
|
||||
env=env
|
||||
)
|
||||
if proc.returncode:
|
||||
@ -47,17 +46,14 @@ def buildNixFunction(function_path, **kwargs):
|
||||
env.update(dict(
|
||||
FUNC_ARGS=input_json_file.name
|
||||
))
|
||||
proc = sp.run(
|
||||
[
|
||||
"nix", "build", "--show-trace", "--impure", "-o", "tmp-result", "--expr",
|
||||
f'''
|
||||
let
|
||||
d2n = (import {dream2nix_src} {{}});
|
||||
in
|
||||
(d2n.utils.callViaEnv d2n.{function_path})
|
||||
''',
|
||||
],
|
||||
capture_output=True,
|
||||
proc = nix(
|
||||
"build", "--show-trace", "--impure", "-o", "tmp-result", "--expr",
|
||||
f'''
|
||||
let
|
||||
d2n = (import {dream2nix_src} {{}});
|
||||
in
|
||||
(d2n.utils.callViaEnv d2n.{function_path})
|
||||
''',
|
||||
env=env
|
||||
)
|
||||
if proc.returncode:
|
||||
@ -72,12 +68,9 @@ def buildNixFunction(function_path, **kwargs):
|
||||
|
||||
|
||||
def buildNixAttribute(attribute_path):
|
||||
proc = sp.run(
|
||||
[
|
||||
"nix", "build", "--show-trace", "--impure", "-o", "tmp-result", "--expr",
|
||||
f"(import {dream2nix_src} {{}}).{attribute_path}",
|
||||
],
|
||||
capture_output=True,
|
||||
proc = nix(
|
||||
"build", "--show-trace", "--impure", "-o", "tmp-result", "--expr",
|
||||
f"(import {dream2nix_src} {{}}).{attribute_path}",
|
||||
)
|
||||
if proc.returncode:
|
||||
print(f"Failed to build '{attribute_path}'", file=sys.stderr)
|
||||
|
@ -7,12 +7,7 @@
|
||||
pkgs ? import <nixpkgs> {},
|
||||
dlib ? import ./lib { inherit lib; },
|
||||
lib ? pkgs.lib,
|
||||
|
||||
# the dream2nix cli depends on some nix 2.4 features
|
||||
nix ? pkgs.writeScriptBin "nix" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
${pkgs.nixUnstable}/bin/nix --option experimental-features "nix-command flakes" "$@"
|
||||
'',
|
||||
nix ? pkgs.nix,
|
||||
|
||||
# default to empty dream2nix config
|
||||
config ?
|
||||
|
Loading…
Reference in New Issue
Block a user