mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 09:04:37 +03:00
feat: make apps use modules
This commit is contained in:
parent
5252794e58
commit
719f03ab46
@ -174,7 +174,7 @@
|
||||
|
||||
docsCli = forAllSystems (
|
||||
system: pkgs:
|
||||
pkgs.callPackage ./src/apps/docs {
|
||||
pkgs.callPackage ./src/utils/view-docs {
|
||||
dream2nixDocsSrc = "${self}/docs/src";
|
||||
}
|
||||
);
|
||||
@ -202,7 +202,7 @@
|
||||
# all apps including cli, install, etc.
|
||||
apps = forAllSystems (
|
||||
system: pkgs:
|
||||
dream2nixFor."${system}".apps.flakeApps
|
||||
dream2nixFor."${system}".framework.flakeApps
|
||||
// {
|
||||
tests-unit.type = "app";
|
||||
tests-unit.program =
|
||||
|
@ -1,21 +1,20 @@
|
||||
{
|
||||
# dream2nix deps
|
||||
configFile,
|
||||
dream2nixConfigFile,
|
||||
dream2nixWithExternals,
|
||||
utils,
|
||||
# nixpkgs deps
|
||||
nix,
|
||||
pkgs,
|
||||
...
|
||||
} @ args:
|
||||
}:
|
||||
utils.writePureShellScript
|
||||
[nix]
|
||||
[pkgs.nix]
|
||||
''
|
||||
nix ''${@:1:$#-1} --impure --expr "
|
||||
let
|
||||
nixpkgs = <nixpkgs>;
|
||||
l = (import \"\''${nixpkgs}/lib\") // builtins;
|
||||
dream2nix = import ${dream2nixWithExternals} {
|
||||
config = ''${dream2nixConfig:-"${configFile}"};
|
||||
config = ''${dream2nixConfig:-"${dream2nixConfigFile}"};
|
||||
};
|
||||
in ''${@:$#}
|
||||
"
|
||||
|
@ -1,12 +1,7 @@
|
||||
{
|
||||
# from nixpkgs
|
||||
python3,
|
||||
writeScriptBin,
|
||||
...
|
||||
}: let
|
||||
cliPython = python3.withPackages (ps: [ps.cleo]);
|
||||
{pkgs, ...}: let
|
||||
cliPython = pkgs.python3.withPackages (ps: [ps.cleo]);
|
||||
in
|
||||
writeScriptBin
|
||||
pkgs.writeScriptBin
|
||||
"contribute"
|
||||
''
|
||||
dream2nixSrc=${../../.} \
|
||||
|
@ -1,56 +0,0 @@
|
||||
{
|
||||
callPackageDream,
|
||||
dream2nixWithExternals,
|
||||
config,
|
||||
...
|
||||
} @ topArgs: let
|
||||
b = builtins;
|
||||
|
||||
callPackageDream = f: args:
|
||||
topArgs.callPackageDream f (args // (b.removeAttrs apps ["flakeApps"]));
|
||||
|
||||
apps = rec {
|
||||
# the contribute cli
|
||||
contribute = callPackageDream ./contribute {};
|
||||
|
||||
# install the framework to a specified location by copying the code
|
||||
install = callPackageDream ./install {};
|
||||
|
||||
# translate a given source shortcut
|
||||
translate = callPackageDream ./translate {};
|
||||
|
||||
runNixCmdInSrc = callPackageDream ./runNixCmdInSrc {};
|
||||
|
||||
# index packages with an indexer
|
||||
index = callPackageDream ./index {};
|
||||
|
||||
translate-index = callPackageDream ./translate-index {};
|
||||
|
||||
translateSourceShortcut = callPackageDream ./translateSourceShortcut {};
|
||||
|
||||
callNixWithD2N = callPackageDream ./callNixWithD2N {};
|
||||
|
||||
writeFlakeD2N = callPackageDream ./writeFlakeD2N {};
|
||||
|
||||
replaceRootSources = callPackageDream ./replaceRootSources {};
|
||||
|
||||
flakeApps =
|
||||
b.mapAttrs (
|
||||
appName: app: {
|
||||
type = "app";
|
||||
program = "${app}/bin/${appName}";
|
||||
}
|
||||
)
|
||||
{
|
||||
inherit
|
||||
contribute
|
||||
install
|
||||
translate
|
||||
runNixCmdInSrc
|
||||
index
|
||||
translate-index
|
||||
;
|
||||
};
|
||||
};
|
||||
in
|
||||
apps
|
@ -1,12 +1,12 @@
|
||||
{
|
||||
apps,
|
||||
utils,
|
||||
callNixWithD2N,
|
||||
coreutils,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
utils.writePureShellScriptBin
|
||||
"index"
|
||||
[coreutils]
|
||||
[pkgs.coreutils]
|
||||
''
|
||||
usage="usage:
|
||||
$0 INDEXER_NAME INDEXER_INPUT"
|
||||
@ -29,7 +29,7 @@ utils.writePureShellScriptBin
|
||||
|
||||
resultBin="$TMPDIR/result"
|
||||
|
||||
${callNixWithD2N} build -L --keep-failed --show-trace --out-link $resultBin \
|
||||
${apps.callNixWithD2N} build -L --keep-failed --show-trace --out-link $resultBin \
|
||||
"dream2nix.framework.indexers.$name.indexBin"
|
||||
|
||||
$resultBin $inputFile
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
writeScriptBin,
|
||||
pkgs,
|
||||
# dream2nix inputs
|
||||
dream2nixWithExternals,
|
||||
...
|
||||
}:
|
||||
writeScriptBin
|
||||
pkgs.writeScriptBin
|
||||
"install"
|
||||
''
|
||||
target="$1"
|
||||
|
@ -1,12 +1,7 @@
|
||||
{
|
||||
# from nixpkgs
|
||||
python3,
|
||||
writeScriptBin,
|
||||
...
|
||||
}: let
|
||||
cliPython = python3.withPackages (ps: []);
|
||||
{pkgs, ...}: let
|
||||
cliPython = pkgs.python3.withPackages (ps: []);
|
||||
in
|
||||
writeScriptBin
|
||||
pkgs.writeScriptBin
|
||||
"replaceRootSources"
|
||||
''
|
||||
${cliPython}/bin/python ${./replaceRootSources.py} "$@"
|
||||
|
@ -1,14 +1,9 @@
|
||||
{
|
||||
# dream2nix deps
|
||||
writeFlakeD2N,
|
||||
callNixWithD2N,
|
||||
translate,
|
||||
writers,
|
||||
coreutils,
|
||||
nix,
|
||||
pkgs,
|
||||
apps,
|
||||
...
|
||||
}:
|
||||
writers.writeBashBin
|
||||
pkgs.writers.writeBashBin
|
||||
"runNixCmdInSrc"
|
||||
''
|
||||
set -e
|
||||
@ -27,18 +22,18 @@ writers.writeBashBin
|
||||
|
||||
source="''${1:?"error: pass a source shortcut"}"
|
||||
|
||||
TMPDIR="$(${coreutils}/bin/mktemp --directory)"
|
||||
SRC="$(${coreutils}/bin/mktemp --directory)"
|
||||
TMPDIR="$(${pkgs.coreutils}/bin/mktemp --directory)"
|
||||
SRC="$(${pkgs.coreutils}/bin/mktemp --directory)"
|
||||
|
||||
# translate any impure packages
|
||||
export translateSkipResolved=1
|
||||
export translateSourceInfoPath="$SRC/sourceInfo.json"
|
||||
${translate}/bin/translate "$source" "$TMPDIR/packages"
|
||||
${apps.translate}/bin/translate "$source" "$TMPDIR/packages"
|
||||
|
||||
# write flake.nix file
|
||||
export dream2nixConfig="{packagesDir=\"./packages\"; projectRoot=./.;}"
|
||||
export flakeSrcInfoPath="$translateSourceInfoPath"
|
||||
${writeFlakeD2N} "$TMPDIR/flake.nix"
|
||||
${apps.writeFlakeD2N} "$TMPDIR/flake.nix"
|
||||
|
||||
# process arguments to pass to Nix
|
||||
args=()
|
||||
@ -60,8 +55,8 @@ writers.writeBashBin
|
||||
fi
|
||||
|
||||
# enable IFD explicitly so 'flake show' works
|
||||
${nix}/bin/nix --option allow-import-from-derivation true \
|
||||
${pkgs.nix}/bin/nix --option allow-import-from-derivation true \
|
||||
''${cmdArgs[@]} --impure ''${remArgs[@]}
|
||||
|
||||
${coreutils}/bin/rm -rf {$TMPDIR,$SRC}
|
||||
${pkgs.coreutils}/bin/rm -rf {$TMPDIR,$SRC}
|
||||
''
|
||||
|
@ -1,17 +1,12 @@
|
||||
{
|
||||
callNixWithD2N,
|
||||
apps,
|
||||
utils,
|
||||
translate,
|
||||
coreutils,
|
||||
jq,
|
||||
parallel,
|
||||
python3,
|
||||
writeScript,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
script =
|
||||
utils.writePureShellScript
|
||||
[coreutils translate jq python3]
|
||||
(with pkgs; [coreutils translate jq python3])
|
||||
''
|
||||
jobJson=$1
|
||||
job_nr=$2
|
||||
@ -34,7 +29,7 @@
|
||||
in
|
||||
utils.writePureShellScriptBin
|
||||
"translate-index"
|
||||
[coreutils translate jq parallel python3]
|
||||
(with pkgs; [coreutils translate jq parallel python3])
|
||||
''
|
||||
set -e
|
||||
usage="usage:
|
||||
@ -64,7 +59,7 @@ in
|
||||
bin="$TRANSLATOR_DIR/$translator"
|
||||
if [ ! -e "$bin" ]; then
|
||||
echo "building executable for translator $translator"
|
||||
${callNixWithD2N} build -o "$bin" "
|
||||
${apps.callNixWithD2N} build -o "$bin" "
|
||||
dream2nix.framework.translators.$translator.finalTranslateBin
|
||||
"
|
||||
fi
|
||||
|
@ -1,25 +1,19 @@
|
||||
{
|
||||
# dream2nix deps
|
||||
framework,
|
||||
apps,
|
||||
utils,
|
||||
callNixWithD2N,
|
||||
translateSourceShortcut,
|
||||
coreutils,
|
||||
moreutils,
|
||||
nix,
|
||||
python3,
|
||||
jq,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
utils.writePureShellScriptBin
|
||||
"translate"
|
||||
[
|
||||
(with pkgs; [
|
||||
jq
|
||||
coreutils
|
||||
nix
|
||||
python3
|
||||
moreutils
|
||||
]
|
||||
])
|
||||
''
|
||||
usage="usage:
|
||||
$0 PROJECT_JSON TARGET_DIR"
|
||||
@ -50,7 +44,7 @@ utils.writePureShellScriptBin
|
||||
if [ -n "''${TRANSLATOR_DIR:-""}" ]; then
|
||||
translateBin="$TRANSLATOR_DIR/$translator"
|
||||
else
|
||||
translateBin=$(${callNixWithD2N} build --print-out-paths --no-link "
|
||||
translateBin=$(${apps.callNixWithD2N} build --print-out-paths --no-link "
|
||||
dream2nix.framework.translators.$translator.finalTranslateBin
|
||||
")
|
||||
fi
|
||||
@ -68,7 +62,7 @@ utils.writePureShellScriptBin
|
||||
| python3 ${../cli/format-dream-lock.py} \
|
||||
| sponge $dreamLockPath
|
||||
|
||||
${python3.pkgs.jsonschema}/bin/jsonschema \
|
||||
${pkgs.python3.pkgs.jsonschema}/bin/jsonschema \
|
||||
--instance $dreamLockPath \
|
||||
--output pretty \
|
||||
${../../specifications/dream-lock-schema.json}
|
||||
|
@ -1,15 +1,11 @@
|
||||
{
|
||||
callNixWithD2N,
|
||||
writers,
|
||||
...
|
||||
}:
|
||||
writers.writeBash
|
||||
{pkgs, ...}:
|
||||
pkgs.writers.writeBash
|
||||
"translateSourceShortcut"
|
||||
''
|
||||
set -e
|
||||
sourceShortcut=''${1:?"error: you must pass a source shortcut"}
|
||||
|
||||
# translate shortcut to source info
|
||||
${callNixWithD2N} eval --json \
|
||||
${pkgs.callNixWithD2N} eval --json \
|
||||
"dream2nix.fetchers.translateShortcut {shortcut=\"$sourceShortcut\";}"
|
||||
''
|
||||
|
@ -1,13 +1,10 @@
|
||||
{
|
||||
# dream2nix deps
|
||||
dream2nixWithExternals,
|
||||
# nixpkgs deps
|
||||
writers,
|
||||
nix,
|
||||
pkgs,
|
||||
...
|
||||
} @ args:
|
||||
writers.writeBash
|
||||
}:
|
||||
pkgs.writers.writeBash
|
||||
"writeFlakeD2N"
|
||||
''
|
||||
set -e
|
||||
|
@ -72,7 +72,6 @@ in let
|
||||
framework = import ./modules/framework.nix {
|
||||
inherit
|
||||
inputs
|
||||
apps
|
||||
lib
|
||||
dlib
|
||||
pkgs
|
||||
@ -94,7 +93,6 @@ in let
|
||||
callPackageDreamArgs =
|
||||
pkgs
|
||||
// {
|
||||
inherit apps;
|
||||
inherit callPackageDream;
|
||||
inherit config;
|
||||
inherit configFile;
|
||||
@ -123,9 +121,6 @@ in let
|
||||
|
||||
utils = callPackageDream ./utils {};
|
||||
|
||||
# apps for CLI and installation
|
||||
apps = callPackageDream ./apps {};
|
||||
|
||||
# updater modules to find newest package versions
|
||||
updaters = callPackageDream ./updaters {};
|
||||
|
||||
@ -724,7 +719,6 @@ in let
|
||||
};
|
||||
in {
|
||||
inherit
|
||||
apps
|
||||
callPackageDream
|
||||
dream2nixWithExternals
|
||||
framework
|
||||
|
6
src/modules/apps/default.nix
Normal file
6
src/modules/apps/default.nix
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
imports = [
|
||||
./interface.nix
|
||||
./implementation.nix
|
||||
];
|
||||
}
|
31
src/modules/apps/implementation.nix
Normal file
31
src/modules/apps/implementation.nix
Normal file
@ -0,0 +1,31 @@
|
||||
{config, ...}: let
|
||||
l = config.lib;
|
||||
appsDir = ../../apps;
|
||||
appNames = l.attrNames (l.readDir appsDir);
|
||||
appModules =
|
||||
l.genAttrs
|
||||
appNames
|
||||
(name: import "${appsDir}/${name}" config);
|
||||
in {
|
||||
config = {
|
||||
apps = appModules;
|
||||
flakeApps =
|
||||
l.mapAttrs (
|
||||
appName: app: {
|
||||
type = "app";
|
||||
program = "${app}/bin/${appName}";
|
||||
}
|
||||
)
|
||||
{
|
||||
inherit
|
||||
(config.apps)
|
||||
contribute
|
||||
install
|
||||
translate
|
||||
runNixCmdInSrc
|
||||
index
|
||||
translate-index
|
||||
;
|
||||
};
|
||||
};
|
||||
}
|
13
src/modules/apps/interface.nix
Normal file
13
src/modules/apps/interface.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{config, ...}: let
|
||||
l = config.lib;
|
||||
t = l.types;
|
||||
in {
|
||||
options = {
|
||||
apps = l.mkOption {
|
||||
type = t.lazyAttrsOf (t.either t.path t.package);
|
||||
};
|
||||
flakeApps = l.mkOption {
|
||||
type = t.attrsOf t.raw;
|
||||
};
|
||||
};
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
in {
|
||||
options = {
|
||||
builders = lib.mkOption {
|
||||
type = t.attrsOf (t.submoduleWith {
|
||||
type = t.lazyAttrsOf (t.submoduleWith {
|
||||
modules = [../interfaces.builder];
|
||||
specialArgs = {framework = config;};
|
||||
});
|
||||
|
@ -4,7 +4,7 @@
|
||||
in {
|
||||
options = {
|
||||
discoverers = lib.mkOption {
|
||||
type = t.attrsOf (t.submoduleWith {
|
||||
type = t.lazyAttrsOf (t.submoduleWith {
|
||||
modules = [../interfaces.discoverer];
|
||||
specialArgs = {framework = config;};
|
||||
});
|
||||
|
@ -4,7 +4,7 @@
|
||||
in {
|
||||
options = {
|
||||
fetchers = l.mkOption {
|
||||
type = t.attrsOf (
|
||||
type = t.lazyAttrsOf (
|
||||
t.submoduleWith {
|
||||
modules = [../interfaces.fetcher];
|
||||
specialArgs = {framework = config;};
|
||||
|
@ -57,7 +57,7 @@
|
||||
(dreamLock // {
|
||||
_generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ];
|
||||
})
|
||||
" | python3 ${../../apps/cli/format-dream-lock.py} > out
|
||||
" | python3 ${../../utils/cli/format-dream-lock.py} > out
|
||||
tmpOut=$(realpath out)
|
||||
popd
|
||||
mkdir -p $(dirname $outputFile)
|
||||
|
@ -4,7 +4,7 @@
|
||||
in {
|
||||
options = {
|
||||
indexers = l.mkOption {
|
||||
type = t.attrsOf (
|
||||
type = t.lazyAttrsOf (
|
||||
t.submoduleWith {
|
||||
modules = [../interfaces.indexer];
|
||||
specialArgs = {framework = config;};
|
||||
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
apps,
|
||||
dlib,
|
||||
externals,
|
||||
externalSources,
|
||||
@ -19,6 +18,7 @@ in {
|
||||
./functions.default-fetcher
|
||||
./functions.combined-fetcher
|
||||
./functions.translators
|
||||
./apps
|
||||
./builders
|
||||
./discoverers
|
||||
./discoverers.default-discoverer
|
||||
@ -27,9 +27,6 @@ in {
|
||||
./indexers
|
||||
];
|
||||
options = {
|
||||
apps = lib.mkOption {
|
||||
type = t.raw;
|
||||
};
|
||||
lib = lib.mkOption {
|
||||
type = t.raw;
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
in {
|
||||
options = {
|
||||
translators = lib.mkOption {
|
||||
type = t.attrsOf (t.submoduleWith {
|
||||
type = t.lazyAttrsOf (t.submoduleWith {
|
||||
modules = [../interfaces.translator];
|
||||
specialArgs = {framework = config;};
|
||||
});
|
||||
|
@ -15,7 +15,6 @@
|
||||
writeScript,
|
||||
writeScriptBin,
|
||||
# dream2nix inputs
|
||||
apps,
|
||||
callPackageDream,
|
||||
dream2nixWithExternals,
|
||||
externalSources,
|
||||
@ -213,7 +212,7 @@ in
|
||||
echo "aggregating all sources to one large FOD"
|
||||
dream2nixWithExternals=${dream2nixWithExternals} \
|
||||
dream2nixConfig=${configFile} \
|
||||
python3 ${../apps/cli}/aggregate-hashes.py $dreamLockPath
|
||||
python3 ${./cli}/aggregate-hashes.py $dreamLockPath
|
||||
fi
|
||||
|
||||
# add invalidationHash to dream-lock.json
|
||||
@ -222,7 +221,7 @@ in
|
||||
|
||||
# format dream lock
|
||||
cat $dreamLockPath \
|
||||
| python3 ${../apps/cli/format-dream-lock.py} \
|
||||
| python3 ${./cli/format-dream-lock.py} \
|
||||
| sponge $dreamLockPath
|
||||
|
||||
# validate dream-lock.json against jsonschema
|
||||
|
@ -3,11 +3,11 @@
|
||||
dlib,
|
||||
dream2nixInterface,
|
||||
pkgs,
|
||||
apps,
|
||||
callPackageDream,
|
||||
utils,
|
||||
framework,
|
||||
...
|
||||
} @ topArgs: let
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
in rec {
|
||||
generatePackagesFromLocksTree = {
|
||||
@ -77,7 +77,7 @@ in rec {
|
||||
inputJson="$(${pkgs.coreutils}/bin/mktemp)"
|
||||
echo '${l.toJSON inputFinal}' > $inputJson
|
||||
mkdir -p $(dirname ${inputFinal.outputFile})
|
||||
${apps.index}/bin/index ${input.indexer} $inputJson
|
||||
${framework.apps.index}/bin/index ${input.indexer} $inputJson
|
||||
'';
|
||||
in
|
||||
mkApp script;
|
||||
@ -86,7 +86,7 @@ in rec {
|
||||
mkApp (
|
||||
pkgs.writers.writeBash "translate-${name}" ''
|
||||
set -e
|
||||
${apps.translate-index}/bin/translate-index \
|
||||
${framework.apps.translate-index}/bin/translate-index \
|
||||
${name}/index.json ${name}/locks
|
||||
''
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user