Skip to content

Commit

Permalink
metadata stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzleutgeb committed Apr 15, 2024
1 parent bea3a7e commit 969cf7f
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 51 deletions.
47 changes: 35 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
importProjects = {
pkgs ? {},
lib ? inputs.nixpkgs.lib,
sources ? {},
sources ? {
configurations = rawNixosConfigs;
modules = extendedModules;
},
}:
import ./projects {inherit lib pkgs sources;};

Expand All @@ -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;}
Expand Down Expand Up @@ -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 =
Expand All @@ -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];
Expand All @@ -170,7 +190,8 @@
inherit self;
inherit (pkgs) lib;
ngipkgs = importPack;
options = optionsDoc.optionsNix;
packages = pickPackages importedProjects;
options = optionsDoc (pickNixosModules importedProjects); #.optionsNix;
};
};
} ''
Expand All @@ -187,7 +208,9 @@
mkdir $out
cp $build/share/doc/nixos/options.json $out/
'';
};
}
*/
;

formatter = treefmtEval.config.build.wrapper;
checks = mapAttrs' toplevel nixosConfigurations;
Expand Down
4 changes: 4 additions & 0 deletions projects/Flarum/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{pkgs, ...}: {
packages = {inherit (pkgs) flarum;};
nixos.module.service = ./service.nix;
}
7 changes: 0 additions & 7 deletions projects/Flarum/project.nix

This file was deleted.

2 changes: 1 addition & 1 deletion projects/Kbin/project.nix → projects/Kbin/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
pkgs,
lib,
...
sources,
} @ args: {
packages = {inherit (pkgs) kbin kbin-frontend kbin-backend;};
nixos = rec {
Expand Down
1 change: 0 additions & 1 deletion projects/Kbin/service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
mapAttrsToList
optional
getExe
strings
concatLines
generators
;
Expand Down
5 changes: 0 additions & 5 deletions projects/LiberaForms-E2EE/README.md

This file was deleted.

4 changes: 4 additions & 0 deletions projects/LiberaForms-E2EE/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{...}: {
# https://github.com/ngi-nix/ngipkgs/issues/40
broken = true;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{pkgs, ...} @ args: {
{
pkgs,
lib,
sources,
} @ args: {
packages = {
inherit (pkgs) pretalx-full;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{pkgs, ...} @ args: {
{
pkgs,
lib,
sources,
} @ args: {
packages = {inherit (pkgs) rosenpass rosenpass-tools;};
nixos = {
modules = {};
Expand Down
47 changes: 25 additions & 22 deletions projects/default.nix
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
{
lib,
pkgs ? {},
...
} @ args: let
baseDirectory = ./.;

sources,
}: let
inherit
(builtins)
pathExists
elem
readDir
trace
;

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))
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{pkgs, ...} @ args: {
{
pkgs,
lib,
sources,
} @ args: {
packages = {inherit (pkgs) mcaptcha mcaptcha-cache;};
nixos = {
modules.service = ./service.nix;
Expand Down

0 comments on commit 969cf7f

Please sign in to comment.