mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-24 15:01:56 +03:00
improve flake interfaces and apps
- improve exposing apps for other flakes - configure overridesDirs via config
This commit is contained in:
parent
39db511926
commit
60d89f776f
31
flake.nix
31
flake.nix
@ -65,20 +65,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
# create a directory containing the files listed in externalPaths
|
# create a directory containing the files listed in externalPaths
|
||||||
makeExternalDir = pkgs: pkgs.runCommand "dream2nix-external" {}
|
makeExternalDir = import ./src/utils/external-dir.nix;
|
||||||
(lib.concatStringsSep "\n"
|
|
||||||
(lib.mapAttrsToList
|
|
||||||
(inputName: paths:
|
|
||||||
lib.concatStringsSep "\n"
|
|
||||||
(lib.forEach
|
|
||||||
paths
|
|
||||||
(path: ''
|
|
||||||
mkdir -p $out/${inputName}/$(dirname ${path})
|
|
||||||
cp ${inp."${inputName}"}/${path} $out/${inputName}/${path}
|
|
||||||
'')))
|
|
||||||
externalPaths));
|
|
||||||
|
|
||||||
externalDirFor = forAllSystems (system: makeExternalDir);
|
externalDirFor = forAllSystems (system: pkgs: makeExternalDir {
|
||||||
|
inherit externalPaths externalSources pkgs;
|
||||||
|
});
|
||||||
|
|
||||||
# An interface to access files of external projects.
|
# An interface to access files of external projects.
|
||||||
# This implementation aceeses the flake inputs directly,
|
# This implementation aceeses the flake inputs directly,
|
||||||
@ -95,7 +86,10 @@
|
|||||||
# system specific dream2nix api
|
# system specific dream2nix api
|
||||||
dream2nixFor = forAllSystems (system: pkgs: import ./src rec {
|
dream2nixFor = forAllSystems (system: pkgs: import ./src rec {
|
||||||
externalDir = externalDirFor."${system}";
|
externalDir = externalDirFor."${system}";
|
||||||
inherit externalSources lib overridesDirs pkgs;
|
inherit externalSources lib pkgs;
|
||||||
|
config = {
|
||||||
|
inherit overridesDirs;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
in
|
in
|
||||||
@ -112,7 +106,7 @@
|
|||||||
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
# Similar to drem2nixFor but will require 'system(s)' or 'pkgs' as an argument.
|
||||||
# Produces flake-like output schema.
|
# Produces flake-like output schema.
|
||||||
lib = (import ./src/lib.nix {
|
lib = (import ./src/lib.nix {
|
||||||
inherit externalSources overridesDirs lib;
|
inherit externalPaths externalSources lib;
|
||||||
nixpkgsSrc = "${nixpkgs}";
|
nixpkgsSrc = "${nixpkgs}";
|
||||||
})
|
})
|
||||||
# system specific dream2nix library
|
# system specific dream2nix library
|
||||||
@ -133,12 +127,7 @@
|
|||||||
|
|
||||||
# all apps including cli, install, etc.
|
# all apps including cli, install, etc.
|
||||||
apps = forAllSystems (system: pkgs:
|
apps = forAllSystems (system: pkgs:
|
||||||
lib.mapAttrs (appName: app:
|
dream2nixFor."${system}".apps.flakeApps
|
||||||
{
|
|
||||||
type = "app";
|
|
||||||
program = b.toString app.program;
|
|
||||||
}
|
|
||||||
) dream2nixFor."${system}".apps.apps
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# a dev shell for working on dream2nix
|
# a dev shell for working on dream2nix
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
{
|
{
|
||||||
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
|
||||||
callPackageDream,
|
callPackageDream,
|
||||||
translators,
|
translators,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
b = builtins;
|
||||||
|
in
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
apps = {
|
apps = {
|
||||||
inherit cli contribute install;
|
inherit cli contribute install;
|
||||||
dream2nix = cli;
|
dream2nix = cli;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
flakeApps =
|
||||||
|
lib.mapAttrs (appName: app:
|
||||||
|
{
|
||||||
|
type = "app";
|
||||||
|
program = b.toString app.program;
|
||||||
|
}
|
||||||
|
) apps;
|
||||||
|
|
||||||
# the unified translator cli
|
# the unified translator cli
|
||||||
cli = callPackageDream (import ./cli) {};
|
cli = callPackageDream (import ./cli) {};
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -12,39 +12,51 @@
|
|||||||
${pkgs.nixUnstable}/bin/nix --option experimental-features "nix-command flakes" "$@"
|
${pkgs.nixUnstable}/bin/nix --option experimental-features "nix-command flakes" "$@"
|
||||||
'',
|
'',
|
||||||
|
|
||||||
|
# default to empty dream2nix config
|
||||||
|
config ?
|
||||||
|
# if called via CLI, load cnfig via env
|
||||||
|
if builtins ? getEnv && builtins.getEnv "d2nConfigFile" != "" then
|
||||||
|
builtins.toPath (builtins.getEnv "d2nConfigFile")
|
||||||
|
# load from default directory
|
||||||
|
else
|
||||||
|
{},
|
||||||
|
|
||||||
# dependencies of dream2nix
|
# dependencies of dream2nix
|
||||||
externalSources ?
|
externalSources ?
|
||||||
lib.genAttrs
|
lib.genAttrs
|
||||||
(lib.attrNames (builtins.readDir externalDir))
|
(lib.attrNames (builtins.readDir externalDir))
|
||||||
(inputName: "${externalDir}/${inputName}"),
|
(inputName: "${externalDir}/${inputName}"),
|
||||||
|
|
||||||
|
# will be defined if called via flake
|
||||||
|
externalPaths ? null,
|
||||||
|
|
||||||
# required for non-flake mode
|
# required for non-flake mode
|
||||||
externalDir ?
|
externalDir ?
|
||||||
|
# if flake is used, construct external dir from flake inputs
|
||||||
|
if externalPaths != null then
|
||||||
|
(import ./utils/external-dir.nix {
|
||||||
|
inherit externalPaths externalSources pkgs;
|
||||||
|
})
|
||||||
# if called via CLI, load externals via env
|
# if called via CLI, load externals via env
|
||||||
if builtins ? getEnv && builtins.getEnv "d2nExternalDir" != "" then
|
else if builtins ? getEnv && builtins.getEnv "d2nExternalDir" != "" then
|
||||||
builtins.getEnv "d2nExternalDir"
|
builtins.getEnv "d2nExternalDir"
|
||||||
# load from default directory
|
# load from default directory
|
||||||
else
|
else
|
||||||
./external,
|
./external,
|
||||||
|
|
||||||
# dream2nix overrides
|
}@args:
|
||||||
overridesDirs ?
|
|
||||||
# if called via CLI, load externals via env
|
|
||||||
if builtins ? getEnv && builtins.getEnv "d2nOverridesDirs" != "" then
|
|
||||||
lib.splitString ":" (builtins.getEnv "d2nOverridesDirs")
|
|
||||||
# load from default directory
|
|
||||||
else
|
|
||||||
[ ./overrides ],
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
b = builtins;
|
b = builtins;
|
||||||
|
|
||||||
|
config = (import ./utils/config.nix).loadConfig args.config or {};
|
||||||
|
|
||||||
# like pkgs.callPackage, but includes all the dream2nix modules
|
# like pkgs.callPackage, but includes all the dream2nix modules
|
||||||
callPackageDream = f: args: pkgs.callPackage f (args // {
|
callPackageDream = f: args: pkgs.callPackage f (args // {
|
||||||
inherit builders;
|
inherit builders;
|
||||||
inherit callPackageDream;
|
inherit callPackageDream;
|
||||||
|
inherit config;
|
||||||
inherit externals;
|
inherit externals;
|
||||||
inherit externalSources;
|
inherit externalSources;
|
||||||
inherit fetchers;
|
inherit fetchers;
|
||||||
@ -57,8 +69,6 @@ let
|
|||||||
|
|
||||||
utils = callPackageDream ./utils {};
|
utils = callPackageDream ./utils {};
|
||||||
|
|
||||||
config = builtins.fromJSON (builtins.readFile ./config.json);
|
|
||||||
|
|
||||||
# apps for CLI and installation
|
# apps for CLI and installation
|
||||||
apps = callPackageDream ./apps {};
|
apps = callPackageDream ./apps {};
|
||||||
|
|
||||||
@ -88,7 +98,7 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
dreamOverrides =
|
dreamOverrides =
|
||||||
utils.loadOverridesDirs overridesDirs pkgs;
|
utils.loadOverridesDirs config.overridesDirs pkgs;
|
||||||
|
|
||||||
# the location of the dream2nix framework for self references (update scripts, etc.)
|
# the location of the dream2nix framework for self references (update scripts, etc.)
|
||||||
dream2nixWithExternals =
|
dream2nixWithExternals =
|
||||||
|
67
src/lib.nix
67
src/lib.nix
@ -6,17 +6,12 @@
|
|||||||
nixpkgsSrc ? <nixpkgs>,
|
nixpkgsSrc ? <nixpkgs>,
|
||||||
lib ? (import nixpkgsSrc {}).lib,
|
lib ? (import nixpkgsSrc {}).lib,
|
||||||
|
|
||||||
# (if called impurely ./default.nix will handle externals and overrides)
|
# default to empty dream2nix config
|
||||||
externalSources ? null,
|
config ? {},
|
||||||
|
|
||||||
# dream2nix overrides
|
externalSources,
|
||||||
overridesDirs ?
|
|
||||||
# if called via CLI, load externals via env
|
externalPaths,
|
||||||
if builtins ? getEnv && builtins.getEnv "d2nOverridesDirs" != "" then
|
|
||||||
lib.splitString ":" (builtins.getEnv "d2nOverridesDirs")
|
|
||||||
# load from default directory
|
|
||||||
else
|
|
||||||
[ ./overrides ],
|
|
||||||
|
|
||||||
}@args:
|
}@args:
|
||||||
|
|
||||||
@ -24,6 +19,13 @@ let
|
|||||||
|
|
||||||
b = builtins;
|
b = builtins;
|
||||||
|
|
||||||
|
config = (import ./utils/config.nix).loadConfig args.config or {};
|
||||||
|
|
||||||
|
dream2nixForSystem = system: pkgs:
|
||||||
|
import ./default.nix
|
||||||
|
{ inherit config externalPaths externalSources pkgs; };
|
||||||
|
|
||||||
|
|
||||||
# TODO: design output schema for cross compiled packages
|
# TODO: design output schema for cross compiled packages
|
||||||
makePkgsKey = pkgs:
|
makePkgsKey = pkgs:
|
||||||
let
|
let
|
||||||
@ -75,28 +77,18 @@ let
|
|||||||
{
|
{
|
||||||
pkgs ? null,
|
pkgs ? null,
|
||||||
systems ? [],
|
systems ? [],
|
||||||
overridesDirs ? [],
|
config ? {},
|
||||||
}@argsInit:
|
}@argsInit:
|
||||||
let
|
let
|
||||||
|
|
||||||
overridesDirs' = args.overridesDirs ++ argsInit.overridesDirs or [];
|
overridesDirs' = config.overridesDirs;
|
||||||
|
|
||||||
allPkgs = makeNixpkgs pkgs systems;
|
allPkgs = makeNixpkgs pkgs systems;
|
||||||
|
|
||||||
dream2nixFor =
|
forAllSystems = f:
|
||||||
lib.mapAttrs
|
lib.mapAttrs f allPkgs;
|
||||||
(system: pkgs:
|
|
||||||
import ./default.nix
|
dream2nixFor = forAllSystems dream2nixForSystem;
|
||||||
(
|
|
||||||
{
|
|
||||||
inherit pkgs;
|
|
||||||
overridesDirs = overridesDirs';
|
|
||||||
}
|
|
||||||
// (lib.optionalAttrs (externalSources != null) {
|
|
||||||
inherit externalSources;
|
|
||||||
})
|
|
||||||
))
|
|
||||||
allPkgs;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
riseAndShine = riseAndShineArgs:
|
riseAndShine = riseAndShineArgs:
|
||||||
@ -117,6 +109,17 @@ let
|
|||||||
(allOutputs: output: lib.recursiveUpdate allOutputs output)
|
(allOutputs: output: lib.recursiveUpdate allOutputs output)
|
||||||
{}
|
{}
|
||||||
flakifiedOutputs;
|
flakifiedOutputs;
|
||||||
|
|
||||||
|
apps =
|
||||||
|
forAllSystems
|
||||||
|
(system: pkgs:
|
||||||
|
dream2nixFor."${system}".apps.flakeApps);
|
||||||
|
|
||||||
|
defaultApp =
|
||||||
|
forAllSystems
|
||||||
|
(system: pkgs:
|
||||||
|
dream2nixFor."${system}".apps.flakeApps.dream2nix);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
riseAndShine =
|
riseAndShine =
|
||||||
@ -132,17 +135,7 @@ let
|
|||||||
allPkgs = makeNixpkgs pkgs systems;
|
allPkgs = makeNixpkgs pkgs systems;
|
||||||
|
|
||||||
dream2nixFor =
|
dream2nixFor =
|
||||||
lib.mapAttrs
|
lib.mapAttrs dream2nixForSystem allPkgs;
|
||||||
(system: pkgs:
|
|
||||||
import ./default.nix
|
|
||||||
({ inherit pkgs; }
|
|
||||||
// (lib.optionalAttrs (externalSources != null) {
|
|
||||||
inherit externalSources;
|
|
||||||
})
|
|
||||||
// (lib.optionalAttrs (overridesDirs != null) {
|
|
||||||
inherit overridesDirs;
|
|
||||||
})))
|
|
||||||
allPkgs;
|
|
||||||
|
|
||||||
allBuilderOutputs =
|
allBuilderOutputs =
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
|
32
src/utils/config.nix
Normal file
32
src/utils/config.nix
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
let
|
||||||
|
|
||||||
|
b = builtins;
|
||||||
|
|
||||||
|
# loads attrs either from s:
|
||||||
|
# - json file
|
||||||
|
# - json string
|
||||||
|
# - attrset (no changes)
|
||||||
|
loadAttrs = input:
|
||||||
|
if b.isPath input then
|
||||||
|
b.fromJSON (b.readFile input)
|
||||||
|
else if b.isString input then
|
||||||
|
b.fromJSON input
|
||||||
|
else if b.isAttrs input then
|
||||||
|
input
|
||||||
|
else
|
||||||
|
throw "input for loadAttrs must be json file or string or attrs";
|
||||||
|
|
||||||
|
# load dream2nix config extending with defaults
|
||||||
|
loadConfig = configInput:
|
||||||
|
let
|
||||||
|
config = loadAttrs configInput;
|
||||||
|
defaults = {
|
||||||
|
overridesDirs = [];
|
||||||
|
packagesDir = null;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
defaults // config;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit loadConfig;
|
||||||
|
}
|
19
src/utils/external-dir.nix
Normal file
19
src/utils/external-dir.nix
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
lib ? pkgs.lib,
|
||||||
|
pkgs,
|
||||||
|
externalSources,
|
||||||
|
externalPaths,
|
||||||
|
}:
|
||||||
|
|
||||||
|
pkgs.runCommand "dream2nix-external-dir" {}
|
||||||
|
(lib.concatStringsSep "\n"
|
||||||
|
(lib.mapAttrsToList
|
||||||
|
(inputName: paths:
|
||||||
|
lib.concatStringsSep "\n"
|
||||||
|
(lib.forEach
|
||||||
|
paths
|
||||||
|
(path: ''
|
||||||
|
mkdir -p $out/${inputName}/$(dirname ${path})
|
||||||
|
cp ${externalSources."${inputName}"}/${path} $out/${inputName}/${path}
|
||||||
|
'')))
|
||||||
|
externalPaths))
|
Loading…
Reference in New Issue
Block a user