From 969cf7f759df3bb8054b34d27bc9cad6713821ac Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 15 Apr 2024 21:09:49 +0200 Subject: [PATCH] metadata stuff --- flake.nix | 47 ++++++++++++++----- projects/Flarum/default.nix | 4 ++ projects/Flarum/project.nix | 7 --- projects/Kbin/{project.nix => default.nix} | 2 +- projects/Kbin/service.nix | 1 - projects/LiberaForms-E2EE/README.md | 5 -- projects/LiberaForms-E2EE/default.nix | 4 ++ projects/Pretalx/{project.nix => default.nix} | 6 ++- .../Rosenpass/{project.nix => default.nix} | 6 ++- projects/default.nix | 47 ++++++++++--------- .../mCaptcha/{project.nix => default.nix} | 6 ++- 11 files changed, 84 insertions(+), 51 deletions(-) create mode 100644 projects/Flarum/default.nix delete mode 100644 projects/Flarum/project.nix rename projects/Kbin/{project.nix => default.nix} (97%) delete mode 100644 projects/LiberaForms-E2EE/README.md create mode 100644 projects/LiberaForms-E2EE/default.nix rename projects/Pretalx/{project.nix => default.nix} (95%) rename projects/Rosenpass/{project.nix => default.nix} (77%) rename projects/mCaptcha/{project.nix => default.nix} (87%) diff --git a/flake.nix b/flake.nix index f08b932f0..1104603eb 100644 --- a/flake.nix +++ b/flake.nix @@ -72,7 +72,10 @@ importProjects = { pkgs ? {}, lib ? inputs.nixpkgs.lib, - sources ? {}, + sources ? { + configurations = rawNixosConfigs; + modules = extendedModules; + }, }: import ./projects {inherit lib pkgs sources;}; @@ -87,12 +90,7 @@ pickNixosConfigurations = x: mapAttrs (_: v: mapAttrs (_: v: v.path) v) (mapAttrByPath ["nixos" "configurations"] {} x); importPackages = pkgs: let - nixosTests = pickNixosTests (importProjects { - inherit pkgs; - lib = inputs.nixpkgs.lib; - sources.configurations = rawNixosConfigs; - sources.modules = extendedModules; - }); + nixosTests = pickNixosTests (importProjects {pkgs = pkgs // allPackages;}); callPackage = pkgs.newScope ( allPackages // {inherit callPackage nixosTests;} @@ -137,11 +135,32 @@ eachDefaultSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let pkgs = importNixpkgs system [rust-overlay.overlays.default]; + + importedProjects = importProjects { + inherit pkgs; + lib = inputs.nixpkgs.lib; + sources.configurations = rawNixosConfigs; + sources.modules = extendedModules; + }; + treefmtEval = loadTreefmt pkgs; toplevel = name: config: nameValuePair "nixosConfigurations/${name}" config.config.system.build.toplevel; importPack = importPackages pkgs; + optionsDoc = nixosModules: + mapAttrs ( + _: v: let + eval = import (nixpkgs + "/nixos/lib/eval-config.nix") { + baseModules = []; + modules = attrValues v; + }; + in + pkgs.nixosOptionsDoc { + inherit (eval) options; + } + ); + dummy = import (nixpkgs + "/nixos/lib/eval-config.nix") { inherit system; modules = @@ -155,12 +174,13 @@ } ]; }; - options = builtins.mapAttrs (name: _: dummy.options.services.${name} or {}) self.nixosModules; - optionsDoc = pkgs.nixosOptionsDoc {inherit options;}; + #options = builtins.mapAttrs (name: _: dummy.options.services.${name} or {}) self.nixosModules; + #optionsDoc = pkgs.nixosOptionsDoc {inherit options;}; in { packages = importPack - // { + /* + // { overview = pkgs.runCommand "overview" { nativeBuildInputs = with pkgs; [jq pandoc validator-nu]; @@ -170,7 +190,8 @@ inherit self; inherit (pkgs) lib; ngipkgs = importPack; - options = optionsDoc.optionsNix; + packages = pickPackages importedProjects; + options = optionsDoc (pickNixosModules importedProjects); #.optionsNix; }; }; } '' @@ -187,7 +208,9 @@ mkdir $out cp $build/share/doc/nixos/options.json $out/ ''; - }; + } + */ + ; formatter = treefmtEval.config.build.wrapper; checks = mapAttrs' toplevel nixosConfigurations; diff --git a/projects/Flarum/default.nix b/projects/Flarum/default.nix new file mode 100644 index 000000000..5920e84fb --- /dev/null +++ b/projects/Flarum/default.nix @@ -0,0 +1,4 @@ +{pkgs, ...}: { + packages = {inherit (pkgs) flarum;}; + nixos.module.service = ./service.nix; +} diff --git a/projects/Flarum/project.nix b/projects/Flarum/project.nix deleted file mode 100644 index d8ffe154d..000000000 --- a/projects/Flarum/project.nix +++ /dev/null @@ -1,7 +0,0 @@ -{pkgs, ...}: { - packages = - if pkgs == {} - then builtins.throw "wut?" - else {inherit (pkgs) flarum;}; - nixos.module.service = ./service.nix; -} diff --git a/projects/Kbin/project.nix b/projects/Kbin/default.nix similarity index 97% rename from projects/Kbin/project.nix rename to projects/Kbin/default.nix index 92d20166e..1a40f6716 100644 --- a/projects/Kbin/project.nix +++ b/projects/Kbin/default.nix @@ -1,7 +1,7 @@ { pkgs, lib, - ... + sources, } @ args: { packages = {inherit (pkgs) kbin kbin-frontend kbin-backend;}; nixos = rec { diff --git a/projects/Kbin/service.nix b/projects/Kbin/service.nix index e30241fc5..adbc410fc 100644 --- a/projects/Kbin/service.nix +++ b/projects/Kbin/service.nix @@ -22,7 +22,6 @@ mapAttrsToList optional getExe - strings concatLines generators ; diff --git a/projects/LiberaForms-E2EE/README.md b/projects/LiberaForms-E2EE/README.md deleted file mode 100644 index 7ce17c64e..000000000 --- a/projects/LiberaForms-E2EE/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# LiberaForms - -Intentionally disabled. - -Refer to . \ No newline at end of file diff --git a/projects/LiberaForms-E2EE/default.nix b/projects/LiberaForms-E2EE/default.nix new file mode 100644 index 000000000..6d5828242 --- /dev/null +++ b/projects/LiberaForms-E2EE/default.nix @@ -0,0 +1,4 @@ +{...}: { + # https://github.com/ngi-nix/ngipkgs/issues/40 + broken = true; +} diff --git a/projects/Pretalx/project.nix b/projects/Pretalx/default.nix similarity index 95% rename from projects/Pretalx/project.nix rename to projects/Pretalx/default.nix index 36f072562..18fc47394 100644 --- a/projects/Pretalx/project.nix +++ b/projects/Pretalx/default.nix @@ -1,4 +1,8 @@ -{pkgs, ...} @ args: { +{ + pkgs, + lib, + sources, +} @ args: { packages = { inherit (pkgs) pretalx-full; }; diff --git a/projects/Rosenpass/project.nix b/projects/Rosenpass/default.nix similarity index 77% rename from projects/Rosenpass/project.nix rename to projects/Rosenpass/default.nix index 98f574d75..ab00e9c6d 100644 --- a/projects/Rosenpass/project.nix +++ b/projects/Rosenpass/default.nix @@ -1,4 +1,8 @@ -{pkgs, ...} @ args: { +{ + pkgs, + lib, + sources, +} @ args: { packages = {inherit (pkgs) rosenpass rosenpass-tools;}; nixos = { modules = {}; diff --git a/projects/default.nix b/projects/default.nix index 23d84fa25..6e80044ee 100644 --- a/projects/default.nix +++ b/projects/default.nix @@ -1,13 +1,11 @@ { lib, pkgs ? {}, - ... -} @ args: let - baseDirectory = ./.; - + sources, +}: let inherit (builtins) - pathExists + elem readDir trace ; @@ -15,28 +13,33 @@ inherit (lib.attrsets) mapAttrs - concatMapAttrs recursiveUpdate + filterAttrs ; - names = name: type: - if type != "directory" - then assert name == "README.md" || name == "default.nix"; {} - else {${name} = baseDirectory + "/${name}";}; + baseDirectory = ./.; - allProjectDirectories = concatMapAttrs names (readDir baseDirectory); + allowedFiles = ["README.md" "default.nix"]; - projectDirectories = lib.filterAttrs (_: directory: - if pathExists (directory + "/project.nix") - then true - else trace "No project.nix found in ${directory}, skipping." false) - allProjectDirectories; + isMarkedBroken = project: project.broken or false; + + filter = name: type: + if type != "directory" + then assert elem name allowedFiles; false + else true; + + hydrate = project: + recursiveUpdate + project + {nixos.tests = mapAttrs (_: pkgs.nixosTest) project.nixos.tests or {};}; in mapAttrs ( - _: directory: let - imported = import (directory + "/project.nix") args; + name: type: let + project = import (baseDirectory + "/${name}") { + inherit lib pkgs sources; + }; in - recursiveUpdate - imported {nixos.tests = mapAttrs (_: pkgs.nixosTest) imported.nixos.tests or {};} - ) - projectDirectories + if isMarkedBroken project + then trace "Project '${name}' marked as broken (for system '${pkgs.system or "undefined"}'). Skipping." {} + else hydrate project + ) (filterAttrs filter (readDir baseDirectory)) diff --git a/projects/mCaptcha/project.nix b/projects/mCaptcha/default.nix similarity index 87% rename from projects/mCaptcha/project.nix rename to projects/mCaptcha/default.nix index 75082d157..2990a07cd 100644 --- a/projects/mCaptcha/project.nix +++ b/projects/mCaptcha/default.nix @@ -1,4 +1,8 @@ -{pkgs, ...} @ args: { +{ + pkgs, + lib, + sources, +} @ args: { packages = {inherit (pkgs) mcaptcha mcaptcha-cache;}; nixos = { modules.service = ./service.nix;