mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-18 20:11:33 +03:00
Always build from dream-lock.json if exists
- add an invalidationHash to dream-lock.json - always evaluate dream-lock.json if exists - warn user if dream-lock.json doesn't exist
This commit is contained in:
parent
ba967fcbe0
commit
d8300cb909
@ -63,6 +63,7 @@ class AddCommand(Command):
|
|||||||
),
|
),
|
||||||
option("force", None, "override existing files", flag=True),
|
option("force", None, "override existing files", flag=True),
|
||||||
option("no-default-nix", None, "create default.nix", flag=True),
|
option("no-default-nix", None, "create default.nix", flag=True),
|
||||||
|
option("invalidation-hash", None, "invalidation hash to attach", flag=False),
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
@ -383,6 +384,7 @@ class AddCommand(Command):
|
|||||||
) + [
|
) + [
|
||||||
f"--arg {n}={v}" for n, v in specified_extra_args.items()
|
f"--arg {n}={v}" for n, v in specified_extra_args.items()
|
||||||
])
|
])
|
||||||
|
lock['_generic']['invalidationHash'] = self.option('invalidation-hash')
|
||||||
|
|
||||||
def calc_outputs(self, main_package_dir_name, packages_root):
|
def calc_outputs(self, main_package_dir_name, packages_root):
|
||||||
if self.option('target'):
|
if self.option('target'):
|
||||||
@ -504,7 +506,7 @@ class AddCommand(Command):
|
|||||||
|
|
||||||
# assume defaults for unspecified extra args
|
# assume defaults for unspecified extra args
|
||||||
specified_extra_args.update(
|
specified_extra_args.update(
|
||||||
{n: (True if v['type'] == 'flag' else v['default']) \
|
{n: (False if v['type'] == 'flag' else v['default']) \
|
||||||
for n, v in translator['extraArgs'].items() \
|
for n, v in translator['extraArgs'].items() \
|
||||||
if n not in specified_extra_args}
|
if n not in specified_extra_args}
|
||||||
)
|
)
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
|
|
||||||
# default to empty dream2nix config
|
# default to empty dream2nix config
|
||||||
config ?
|
config ?
|
||||||
# if called via CLI, load cnfig via env
|
# if called via CLI, load config via env
|
||||||
if builtins ? getEnv && builtins.getEnv "d2nConfigFile" != "" then
|
if builtins ? getEnv && builtins.getEnv "dream2nixConfig" != "" then
|
||||||
builtins.toPath (builtins.getEnv "d2nConfigFile")
|
builtins.toPath (builtins.getEnv "dream2nixConfig")
|
||||||
# load from default directory
|
# load from default directory
|
||||||
else
|
else
|
||||||
{},
|
{},
|
||||||
|
77
src/lib.nix
77
src/lib.nix
@ -110,6 +110,7 @@ let
|
|||||||
|
|
||||||
riseAndShineFunc =
|
riseAndShineFunc =
|
||||||
{
|
{
|
||||||
|
pname,
|
||||||
pkgs ? null,
|
pkgs ? null,
|
||||||
source,
|
source,
|
||||||
systems ? [],
|
systems ? [],
|
||||||
@ -121,12 +122,12 @@ let
|
|||||||
|
|
||||||
config = args.config or ((import ./utils/config.nix).loadConfig {});
|
config = args.config or ((import ./utils/config.nix).loadConfig {});
|
||||||
|
|
||||||
argsForward = b.removeAttrs args [ "config" "pkgs" "systems" ];
|
argsForward = b.removeAttrs args [ "config" "pname" "pkgs" "systems" ];
|
||||||
|
|
||||||
allPkgs = makeNixpkgs pkgs systems;
|
allPkgs = makeNixpkgs pkgs systems;
|
||||||
|
|
||||||
dream2nixFor =
|
dream2nixFor =
|
||||||
lib.mapAttrs (dream2nixForSystem {}) allPkgs;
|
lib.mapAttrs (dream2nixForSystem config) allPkgs;
|
||||||
|
|
||||||
allBuilderOutputs =
|
allBuilderOutputs =
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
@ -139,18 +140,65 @@ let
|
|||||||
translatorName = args.translator or null;
|
translatorName = args.translator or null;
|
||||||
};
|
};
|
||||||
|
|
||||||
result = translator:
|
invalidationHash = dream2nix.utils.calcInvalidationHash {
|
||||||
dream2nix.riseAndShine (argsForward // {
|
inherit source translatorArgs;
|
||||||
|
translator = translatorFound.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
dreamLockJsonPath = with config;
|
||||||
|
"${projectRoot}/${packagesDir}/${pname}/dream-lock.json";
|
||||||
|
|
||||||
|
dreamLock = dream2nix.utils.readDreamLock {
|
||||||
|
dreamLock = dreamLockJsonPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
dreamLockExistsAndValid =
|
||||||
|
b.pathExists dreamLockJsonPath
|
||||||
|
&& dreamLock.lock._generic.invalidationHash or "" == invalidationHash;
|
||||||
|
|
||||||
|
result = translator: args:
|
||||||
|
dream2nix.riseAndShine (argsForward // args // {
|
||||||
# TODO: this triggers the translator finding routine a second time
|
# TODO: this triggers the translator finding routine a second time
|
||||||
translator = translatorFound.name;
|
translator = translatorFound.name;
|
||||||
});
|
});
|
||||||
in
|
in
|
||||||
if b.elem translatorFound.type [ "pure" "ifd" ] then
|
|
||||||
result translatorFound
|
if dreamLockExistsAndValid then
|
||||||
else
|
# we need to override the source here as it is coming from
|
||||||
|
# a flake input
|
||||||
|
let
|
||||||
|
defaultPackage = dreamLock.lock._generic.defaultPackage;
|
||||||
|
defaultPackageVersion =
|
||||||
|
dreamLock.lock._generic.packages."${defaultPackage}";
|
||||||
|
in
|
||||||
|
result translatorFound {
|
||||||
|
source = dreamLockJsonPath;
|
||||||
|
sourceOverrides = oldSources: {
|
||||||
|
"${defaultPackage}"."${defaultPackageVersion}" =
|
||||||
|
args.source;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if b.elem translatorFound.type [ "pure" "ifd" ] then
|
||||||
|
# warn the user about potentially slow on-the-fly evaluation
|
||||||
b.trace ''
|
b.trace ''
|
||||||
Some information is missing to build this project reproducibly.
|
${"\n"}
|
||||||
Please execute nix run .#resolve to resolve impurities.
|
The dream-lock.json for input '${pname}' doesn't exist or is outdated.
|
||||||
|
...Falling back to on-the-fly evaluation (possibly slow).
|
||||||
|
To speed up future evalutations run once:
|
||||||
|
nix run .#resolve
|
||||||
|
''
|
||||||
|
result translatorFound {}
|
||||||
|
|
||||||
|
else
|
||||||
|
# print error because impure translation is required first.
|
||||||
|
# continue the evaluation anyways, as otherwise we won't have
|
||||||
|
# the `resolve` app
|
||||||
|
b.trace ''
|
||||||
|
${"\n"}
|
||||||
|
ERROR:
|
||||||
|
Some information is missing to build this project reproducibly.
|
||||||
|
Please execute nix run .#resolve to resolve all impurities.
|
||||||
''
|
''
|
||||||
{})
|
{})
|
||||||
|
|
||||||
@ -178,11 +226,20 @@ let
|
|||||||
resolve.program =
|
resolve.program =
|
||||||
let
|
let
|
||||||
utils = (dream2nixFor."${system}".utils);
|
utils = (dream2nixFor."${system}".utils);
|
||||||
|
|
||||||
|
# TODO: Too many calls to findOneTranslator.
|
||||||
|
# -> make findOneTranslator system independent
|
||||||
|
translatorFound =
|
||||||
|
dream2nixFor."${system}".translators.findOneTranslator {
|
||||||
|
inherit source;
|
||||||
|
translatorName = args.translator or null;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
b.toString
|
b.toString
|
||||||
(utils.makePackageLockScript {
|
(utils.makePackageLockScript {
|
||||||
inherit source translator translatorArgs;
|
inherit source translatorArgs;
|
||||||
packagesDir = config.packagesDir;
|
packagesDir = config.packagesDir;
|
||||||
|
translator = translatorFound.name;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -154,6 +154,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"defaultPackage": { "type": ["string", "null"] },
|
"defaultPackage": { "type": ["string", "null"] },
|
||||||
|
"invalidationHash": { "type": ["string", "null"] },
|
||||||
"packages": { "type": "object" },
|
"packages": { "type": "object" },
|
||||||
"sourcesAggregatedHash": { "type": ["string", "null"] },
|
"sourcesAggregatedHash": { "type": ["string", "null"] },
|
||||||
"subsystem": { "type": "string" },
|
"subsystem": { "type": "string" },
|
||||||
|
@ -23,7 +23,8 @@ let
|
|||||||
defaults = {
|
defaults = {
|
||||||
overridesDirs = [];
|
overridesDirs = [];
|
||||||
packagesDir = null;
|
packagesDir = null;
|
||||||
repoName = "this repo";
|
projectRoot = throw "projectRoot not specified in dream2nix config";
|
||||||
|
repoName = null;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
defaults // config;
|
defaults // config;
|
||||||
|
@ -198,6 +198,19 @@ rec {
|
|||||||
recursiveUpdateUntilDepth = depth: lhs: rhs:
|
recursiveUpdateUntilDepth = depth: lhs: rhs:
|
||||||
lib.recursiveUpdateUntil (path: l: r: (b.length path) > depth) lhs rhs;
|
lib.recursiveUpdateUntil (path: l: r: (b.length path) > depth) lhs rhs;
|
||||||
|
|
||||||
|
# calculate an invalidation hash for given source translation inputs
|
||||||
|
calcInvalidationHash =
|
||||||
|
{
|
||||||
|
source,
|
||||||
|
translator,
|
||||||
|
translatorArgs,
|
||||||
|
}:
|
||||||
|
b.hashString "sha256" ''
|
||||||
|
${source}
|
||||||
|
${translator}
|
||||||
|
${b.toString
|
||||||
|
(lib.mapAttrsToList (k: v: "${k}=${v}") translatorArgs)}
|
||||||
|
'';
|
||||||
|
|
||||||
# a script that produces and dumps the dream-lock json for a given source
|
# a script that produces and dumps the dream-lock json for a given source
|
||||||
makePackageLockScript =
|
makePackageLockScript =
|
||||||
@ -210,10 +223,14 @@ rec {
|
|||||||
writePureShellScript
|
writePureShellScript
|
||||||
[]
|
[]
|
||||||
''
|
''
|
||||||
|
cd $WORKDIR
|
||||||
${apps.cli.program} add ${source} \
|
${apps.cli.program} add ${source} \
|
||||||
--force \
|
--force \
|
||||||
--no-default-nix \
|
--no-default-nix \
|
||||||
--translator ${translator} \
|
--translator ${translator} \
|
||||||
|
--invalidation-hash ${calcInvalidationHash {
|
||||||
|
inherit source translator translatorArgs;
|
||||||
|
}} \
|
||||||
--packages-root $WORKDIR/${packagesDir} \
|
--packages-root $WORKDIR/${packagesDir} \
|
||||||
${lib.concatStringsSep " \\\n"
|
${lib.concatStringsSep " \\\n"
|
||||||
(lib.mapAttrsToList
|
(lib.mapAttrsToList
|
||||||
|
Loading…
Reference in New Issue
Block a user