Merge pull request #609 from nix-community/docs

examples: move to /examples from /modules/drvs
This commit is contained in:
DavHau 2023-07-29 15:10:20 +02:00 committed by GitHub
commit 8f36c5b85e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 62 additions and 33 deletions

View File

@ -1,14 +1,15 @@
{
lib,
config,
dream2nix,
...
}: let
l = lib // builtins;
system = config.deps.stdenv.system;
in {
imports = [
../../drv-parts/nodejs-package-json
../../drv-parts/nodejs-granular
dream2nix.modules.drv-parts.nodejs-package-json
dream2nix.modules.drv-parts.nodejs-granular
];
mkDerivation = {
@ -42,5 +43,5 @@ in {
version = l.mkForce "0.0.0";
lock.lockFileRel =
l.mkForce "/modules/drvs/nodejs-no-lock/lock-${system}.json";
l.mkForce "/locks/example-package-nodejs-no-lock/lock-${system}.json";
}

View File

@ -1,12 +1,13 @@
{
lib,
config,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/nodejs-devshell
dream2nix.modules.drv-parts.nodejs-devshell
];
mkDerivation = {

View File

@ -1,12 +1,13 @@
{
lib,
config,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/nodejs-node-modules
dream2nix.modules.drv-parts.nodejs-node-modules
];
mkDerivation = {

View File

@ -1,13 +1,14 @@
{
lib,
config,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/nodejs-package-lock
../../drv-parts/nodejs-granular
dream2nix.modules.drv-parts.nodejs-package-lock
dream2nix.modules.drv-parts.nodejs-granular
];
mkDerivation = {

View File

@ -1,12 +1,13 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/pip
dream2nix.modules.drv-parts.pip
];
deps = {nixpkgs, ...}: {

View File

@ -1,13 +1,14 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
python = config.deps.python;
in {
imports = [
../../drv-parts/pip
dream2nix.modules.drv-parts.pip
];
deps = {

View File

@ -7,14 +7,15 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/nodejs-package-lock
../../drv-parts/nodejs-granular
../../drv-parts/pip
dream2nix.modules.drv-parts.nodejs-package-lock
dream2nix.modules.drv-parts.nodejs-granular
dream2nix.modules.drv-parts.pip
];
name = "isso";

View File

@ -1,6 +1,7 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
@ -14,7 +15,7 @@
};
in {
imports = [
../../drv-parts/pip
dream2nix.modules.drv-parts.pip
];
deps = {nixpkgs, ...}: {

View File

@ -3,12 +3,13 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
in {
imports = [
../../drv-parts/pip
dream2nix.modules.drv-parts.pip
];
deps = {nixpkgs, ...}: {

View File

@ -13,20 +13,22 @@
}: let
inherit
(lib)
mapAttrs'
filterAttrs
flip
foldl
hasPrefix
mapAttrs'
mapAttrsToList
removePrefix
;
inherit
(builtins)
mapAttrs
readDir
;
# A module imported into every package setting up the eval cache
setup = {config, ...}: {
lock.lockFileRel = "/modules/drvs/${config.name}/lock-${system}.json";
lock.repoRoot = self;
eval-cache.cacheFileRel = "/modules/drvs/${config.name}/cache-${system}.json";
eval-cache.repoRoot = self;
eval-cache.enable = true;
deps.npm = inputs.nixpkgs.legacyPackages.${system}.nodejs.pkgs.npm.override (old: rec {
@ -39,13 +41,9 @@
};
# evaluates the package behind a given module
makeDrv = module: let
makeDrv = modules: let
evaled = lib.evalModules {
modules = [
self.modules.drv-parts.core
module
setup
];
modules = modules ++ [self.modules.drv-parts.core];
specialArgs.packageSets = {
nixpkgs = inputs.nixpkgs.legacyPackages.${system};
writers = config.writers;
@ -55,22 +53,44 @@
in
evaled.config.public;
examples = readDir (self + /examples/dream2nix-packages);
examplePackagesDirs =
filterAttrs
(name: _: hasPrefix "dream2nix-packages" name)
(readDir (self + "/examples"));
exampleModules =
flip mapAttrs examples
(name: _: self + /examples/dream2nix-packages + "/${name}");
readExamples = dirName: let
prefix = removePrefix "dream2nix-packages-" dirName;
examplesPath = self + /examples + "/${dirName}";
examples = readDir examplesPath;
in
flip mapAttrs' examples
(name: _: {
name = "example-package-${prefix}-${name}";
value = examplesPath + "/${name}";
});
allModules' = self.modules.drvs // exampleModules;
allExamples = mapAttrsToList (dirName: _: readExamples dirName) examplePackagesDirs;
exampleModules = foldl (a: b: a // b) {} allExamples;
# TODO: remove this line once everything is migrated to the new structure
allModules' = self.modules.drvs or {} // exampleModules;
allModules = flip mapAttrs' allModules' (name: module: {
name = "example-package-${name}";
value = module;
inherit name;
value = [
module
setup
{
lock.lockFileRel = "/locks/${name}/lock-${system}.json";
eval-cache.cacheFileRel = "/locks/${name}/cache-${system}.json";
}
];
});
in {
# map all modules in ../drvs to a package output in the flake.
# map all modules in /examples to a package output in the flake.
checks =
lib.mapAttrs (_: drvModule: makeDrv drvModule)
lib.mapAttrs (_: drvModules: makeDrv drvModules)
allModules;
};
}