Skip to content

Commit

Permalink
Working on UI metadata output
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Sep 20, 2024
1 parent 983d4c1 commit 5ca2917
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
5 changes: 5 additions & 0 deletions modules/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ with lib;
default = {};
};

builtLanguageServers = mkOption {
type = types.attrsOf types.package;
default = {};
};

builtShells = mkOption {
type = types.attrsOf types.package;
default = {};
Expand Down
4 changes: 1 addition & 3 deletions modules/language_servers/markdown-spellcheck-lsp/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ with lib;
};

config = mkIf config.language-servers.spellchecker.enable {
packages = [
(config.pkgs.callPackage ./default.nix {})
];
builtLanguageServers.spellchecker = config.pkgs.callPackage ./default.nix {};
};
}
65 changes: 47 additions & 18 deletions nix/makeEnvironment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ with lib;
let
evaluated = (callPackage ./evaluate-config.nix { inherit pkgsStable pkgsMaster; }) config;

builtExporters = evaluated.config.builtExporters;
builtKernels = mapAttrs (_: kernel:
kernel.overrideAttrs (old: {
passthru = old.passthru // {
name = kernel.name;
name = "kernels." + kernel.name;
# channel = kernel.channel;
channel = "codedown";
};
})) evaluated.config.builtKernels;
builtLanguageServers = evaluated.config.builtLanguageServers;
builtShells = evaluated.config.builtShells;
builtExporters = evaluated.config.builtExporters;

repls = let
shellToReplInfo = shell: {
Expand All @@ -44,12 +45,38 @@ let

exporters = concatMap (exporter: exporter.meta.exporterInfos) (attrValues builtExporters);

uiMetadata = callPackage ./uiMetadata.nix {};

mkPackageUiMetadata = let
# This is duplicated from languages/common.nix, which we'd rather not import here
packageName = p: if lib.isString p then p else p.name;

mkSubPackageMetadata = pkg: p: {
name = packageName p;
meta = if lib.hasAttrByPath ["packageOptions" (packageName p)] pkg then uiMetadata.chooseInterestingMeta (pkg.packageOptions.${packageName p}) else {};
} // (lib.optionalAttrs (lib.isAttrs p && p ? "settings") {
inherit (p) settings;
});
in
pkg: {
# Dry
name = pkg.name;
settings = if pkg ? "settings" then pkg.settings else {};

# Different for hydrated
packages = map (p: mkSubPackageMetadata pkg p) (pkg.args.packages or []);

# Hydrated
meta = uiMetadata.chooseInterestingMeta pkg;
};

in

symlinkJoin {
inherit name;
paths =
attrValues (evaluated.config.builtKernels)
++ attrValues (evaluated.config.builtLanguageServers)
++ lib.optionals (builtins.length repls > 0) [(writeTextDir "lib/codedown/repls.yaml" (lib.generators.toYAML {} repls))]
++ lib.optionals (builtins.length exporters > 0) [(writeTextDir "lib/codedown/exporters.yaml" (lib.generators.toYAML {} exporters))]
++ evaluated.config.packages
Expand All @@ -61,22 +88,24 @@ symlinkJoin {

inherit channels;

ui_metadata = let
uiMetadata = callPackage ./uiMetadata.nix {};
in
{
channels = lib.mapAttrsToList (name: channel: channel // {
name = name;
}) evaluated.config.channels;

kernels = map uiMetadata.mkKernelUiMetadata (attrValues builtKernels);

other_packages = map (p: {
channel = p.channel;
attr = p.attr;
meta = if p.contents ? "meta" then uiMetadata.chooseInterestingMeta p.contents else {};
}) evaluated.config.labeledPackages;
};
ui_metadata = {
channels = lib.mapAttrsToList (name: channel: channel // {
name = name;
}) evaluated.config.channels;

packages =
(mapAttrs' (n: v: nameValuePair "exporters.${n}" (mkPackageUiMetadata v)) builtExporters)
// (mapAttrs' (n: v: nameValuePair "kernels.${n}" (mkPackageUiMetadata v)) builtKernels)
// (mapAttrs' (n: v: nameValuePair "language-servers.${n}" (mkPackageUiMetadata v)) builtLanguageServers)
// (mapAttrs' (n: v: nameValuePair "shells.${n}" (mkPackageUiMetadata v)) builtShells)
;

other_packages = map (p: {
channel = p.channel;
attr = p.attr;
meta = if p.contents ? "meta" then uiMetadata.chooseInterestingMeta p.contents else {};
}) evaluated.config.labeledPackages;
};

ui_metadata_yaml = writeText "ui-metadata.yaml" (lib.generators.toYAML {} ui_metadata);
};
Expand Down
23 changes: 0 additions & 23 deletions nix/uiMetadata.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,4 @@ rec {
}) // (lib.optionalAttrs (contents ? "languageServerNames") {
language_server_names = contents.languageServerNames;
});

mkKernelUiMetadata = let
# This is duplicated from languages/common.nix, which we'd rather not import here
packageName = p: if lib.isString p then p else p.name;

mkKernelPackageMetadata = kernel: p: {
name = packageName p;
meta = if lib.hasAttrByPath ["packageOptions" (packageName p)] kernel then chooseInterestingMeta (kernel.packageOptions.${packageName p}) else {};
} // (lib.optionalAttrs (lib.isAttrs p && p ? "settings") {
inherit (p) settings;
});
in
kernel: {
# Dry
name = kernel.name;
settings = if kernel ? "settings" then kernel.settings else {};

# Different for hydrated
packages = map (p: mkKernelPackageMetadata kernel p) kernel.args.packages;

# Hydrated
meta = chooseInterestingMeta kernel;
};
}

0 comments on commit 5ca2917

Please sign in to comment.