diff --git a/modules/drvs/nodejs-no-lock/app.ts b/examples/dream2nix-packages-nodejs/no-lock/app.ts similarity index 100% rename from modules/drvs/nodejs-no-lock/app.ts rename to examples/dream2nix-packages-nodejs/no-lock/app.ts diff --git a/modules/drvs/nodejs-no-lock/default.nix b/examples/dream2nix-packages-nodejs/no-lock/default.nix similarity index 78% rename from modules/drvs/nodejs-no-lock/default.nix rename to examples/dream2nix-packages-nodejs/no-lock/default.nix index ffe30094..c1fe268e 100644 --- a/modules/drvs/nodejs-no-lock/default.nix +++ b/examples/dream2nix-packages-nodejs/no-lock/default.nix @@ -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"; } diff --git a/modules/drvs/nodejs-no-lock/package.json b/examples/dream2nix-packages-nodejs/no-lock/package.json similarity index 100% rename from modules/drvs/nodejs-no-lock/package.json rename to examples/dream2nix-packages-nodejs/no-lock/package.json diff --git a/modules/drvs/prettier-devshell/default.nix b/examples/dream2nix-packages-nodejs/prettier-devshell/default.nix similarity index 90% rename from modules/drvs/prettier-devshell/default.nix rename to examples/dream2nix-packages-nodejs/prettier-devshell/default.nix index aaf1a5dd..2f006919 100644 --- a/modules/drvs/prettier-devshell/default.nix +++ b/examples/dream2nix-packages-nodejs/prettier-devshell/default.nix @@ -1,12 +1,13 @@ { lib, config, + dream2nix, ... }: let l = lib // builtins; in { imports = [ - ../../drv-parts/nodejs-devshell + dream2nix.modules.drv-parts.nodejs-devshell ]; mkDerivation = { diff --git a/modules/drvs/prettier-node-modules/default.nix b/examples/dream2nix-packages-nodejs/prettier-node-modules/default.nix similarity index 88% rename from modules/drvs/prettier-node-modules/default.nix rename to examples/dream2nix-packages-nodejs/prettier-node-modules/default.nix index 1f5f83ff..2e2afea6 100644 --- a/modules/drvs/prettier-node-modules/default.nix +++ b/examples/dream2nix-packages-nodejs/prettier-node-modules/default.nix @@ -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 = { diff --git a/modules/drvs/prettier/default.nix b/examples/dream2nix-packages-nodejs/prettier/default.nix similarity index 80% rename from modules/drvs/prettier/default.nix rename to examples/dream2nix-packages-nodejs/prettier/default.nix index 9c3eb4a7..0006f65a 100644 --- a/modules/drvs/prettier/default.nix +++ b/examples/dream2nix-packages-nodejs/prettier/default.nix @@ -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 = { diff --git a/modules/drvs/ansible/default.nix b/examples/dream2nix-packages-python/ansible/default.nix similarity index 88% rename from modules/drvs/ansible/default.nix rename to examples/dream2nix-packages-python/ansible/default.nix index 488b0837..20367119 100644 --- a/modules/drvs/ansible/default.nix +++ b/examples/dream2nix-packages-python/ansible/default.nix @@ -1,12 +1,13 @@ { config, lib, + dream2nix, ... }: let l = lib // builtins; in { imports = [ - ../../drv-parts/pip + dream2nix.modules.drv-parts.pip ]; deps = {nixpkgs, ...}: { diff --git a/modules/drvs/apache-airflow/default.nix b/examples/dream2nix-packages-python/apache-airflow/default.nix similarity index 97% rename from modules/drvs/apache-airflow/default.nix rename to examples/dream2nix-packages-python/apache-airflow/default.nix index 7b766508..9b810bb3 100644 --- a/modules/drvs/apache-airflow/default.nix +++ b/examples/dream2nix-packages-python/apache-airflow/default.nix @@ -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 = { diff --git a/modules/drvs/isso/default.nix b/examples/dream2nix-packages-python/isso/default.nix similarity index 91% rename from modules/drvs/isso/default.nix rename to examples/dream2nix-packages-python/isso/default.nix index b581c2d0..fabfa420 100644 --- a/modules/drvs/isso/default.nix +++ b/examples/dream2nix-packages-python/isso/default.nix @@ -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"; diff --git a/modules/drvs/odoo/default.nix b/examples/dream2nix-packages-python/odoo/default.nix similarity index 97% rename from modules/drvs/odoo/default.nix rename to examples/dream2nix-packages-python/odoo/default.nix index 51f551d4..f5e6164e 100644 --- a/modules/drvs/odoo/default.nix +++ b/examples/dream2nix-packages-python/odoo/default.nix @@ -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, ...}: { diff --git a/modules/drvs/pillow/default.nix b/examples/dream2nix-packages-python/pillow/default.nix similarity index 94% rename from modules/drvs/pillow/default.nix rename to examples/dream2nix-packages-python/pillow/default.nix index c715cd92..0d455707 100644 --- a/modules/drvs/pillow/default.nix +++ b/examples/dream2nix-packages-python/pillow/default.nix @@ -3,12 +3,13 @@ { config, lib, + dream2nix, ... }: let l = lib // builtins; in { imports = [ - ../../drv-parts/pip + dream2nix.modules.drv-parts.pip ]; deps = {nixpkgs, ...}: { diff --git a/examples/dream2nix-packages/derivation/default.nix b/examples/dream2nix-packages-simple/derivation/default.nix similarity index 100% rename from examples/dream2nix-packages/derivation/default.nix rename to examples/dream2nix-packages-simple/derivation/default.nix diff --git a/examples/dream2nix-packages/htop-with-flags/default.nix b/examples/dream2nix-packages-simple/htop-with-flags/default.nix similarity index 100% rename from examples/dream2nix-packages/htop-with-flags/default.nix rename to examples/dream2nix-packages-simple/htop-with-flags/default.nix diff --git a/examples/dream2nix-packages/mkDerivation/default.nix b/examples/dream2nix-packages-simple/mkDerivation/default.nix similarity index 100% rename from examples/dream2nix-packages/mkDerivation/default.nix rename to examples/dream2nix-packages-simple/mkDerivation/default.nix diff --git a/modules/drvs/nodejs-no-lock/lock-x86_64-linux.json b/locks/example-package-nodejs-no-lock/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/nodejs-no-lock/lock-x86_64-linux.json rename to locks/example-package-nodejs-no-lock/lock-x86_64-linux.json diff --git a/modules/drvs/ansible/lock-x86_64-linux.json b/locks/example-package-python-ansible/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/ansible/lock-x86_64-linux.json rename to locks/example-package-python-ansible/lock-x86_64-linux.json diff --git a/modules/drvs/apache-airflow/cache-x86_64-linux.json b/locks/example-package-python-apache-airflow/cache-x86_64-linux.json similarity index 100% rename from modules/drvs/apache-airflow/cache-x86_64-linux.json rename to locks/example-package-python-apache-airflow/cache-x86_64-linux.json diff --git a/modules/drvs/apache-airflow/lock-x86_64-linux.json b/locks/example-package-python-apache-airflow/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/apache-airflow/lock-x86_64-linux.json rename to locks/example-package-python-apache-airflow/lock-x86_64-linux.json diff --git a/modules/drvs/isso/lock-x86_64-linux.json b/locks/example-package-python-isso/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/isso/lock-x86_64-linux.json rename to locks/example-package-python-isso/lock-x86_64-linux.json diff --git a/modules/drvs/odoo/lock-x86_64-linux.json b/locks/example-package-python-odoo/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/odoo/lock-x86_64-linux.json rename to locks/example-package-python-odoo/lock-x86_64-linux.json diff --git a/modules/drvs/pillow/lock-x86_64-linux.json b/locks/example-package-python-pillow/lock-x86_64-linux.json similarity index 100% rename from modules/drvs/pillow/lock-x86_64-linux.json rename to locks/example-package-python-pillow/lock-x86_64-linux.json diff --git a/modules/flake-parts/checks.nix b/modules/flake-parts/checks.nix index 4a687dfb..7cf5fa9c 100644 --- a/modules/flake-parts/checks.nix +++ b/modules/flake-parts/checks.nix @@ -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; }; }