Skip to content

Commit

Permalink
Change settings and settingsSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Sep 25, 2024
1 parent 1e98605 commit 21c5e4c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/base/convert-type.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, ... }:
{ lib, ... }:

let
convertType = target: type:
Expand Down
21 changes: 10 additions & 11 deletions modules/base/nixos-options-to-settings-schema.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, ... }@args:
{ lib, ... }@args:

{
componentsToDrop ? 0
Expand All @@ -14,16 +14,15 @@ let
convert = v: let
defaultItem = { type = { name = "unknown"; }; };
loc = lib.drop componentsToDrop v.loc;

value = { inherit loc; }
// convertType v.name (lib.attrByPath loc defaultItem options).type
// lib.optionalAttrs (lib.hasAttr "default" v) { defaultValue = convertDefaultValue v.default; }
// (let example = (lib.attrByPath loc null options).example or null; in lib.optionalAttrs (builtins.typeOf example == "string") { title = example; })
// lib.optionalAttrs (lib.hasAttr "description" v && builtins.typeOf v.description == "string") { inherit (v) description; }
// lib.optionalAttrs (lib.hasAttr "visible" v && v.visible == false) { hidden = true; };
in
{
target = loc;
}
// convertType v.name (lib.attrByPath loc defaultItem options).type
// lib.optionalAttrs (lib.hasAttr "default" v) { defaultValue = convertDefaultValue v.default; }
// (let example = (lib.attrByPath loc null options).example or null; in lib.optionalAttrs (builtins.typeOf example == "string") { title = example; })
// lib.optionalAttrs (lib.hasAttr "description" v && builtins.typeOf v.description == "string") { inherit (v) description; }
// lib.optionalAttrs (lib.hasAttr "visible" v && v.visible == false) { hidden = true; }
;
{ name = lib.concatStringsSep "." loc; inherit value; };

evalString = str: builtins.scopedImport {} (builtins.toFile "expr.nix" str);

Expand All @@ -33,4 +32,4 @@ let

in

map convert flattened
lib.listToAttrs (map convert flattened)
1 change: 1 addition & 0 deletions nix/makeEnvironment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let
channel = "codedown";

settings = removeNonDefaultSettings kernel.settingsSchema kernel.settings;
settingsSchema = mapAttrs (_: v: removeAttrs v ["loc"]) kernel.settingsSchema;
};
})) evaluated.config.builtKernels;
builtLanguageServers = evaluated.config.builtLanguageServers;
Expand Down
10 changes: 5 additions & 5 deletions nix/remove-non-default-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ let
evalString = str: builtins.scopedImport {} (builtins.toFile "expr.nix" str);

getSettingsRow = schemaItem: value:
if value != schemaItem.defaultValue
then { name = concatStringsSep "." schemaItem.target; inherit value; }
if value != schemaItem.value.defaultValue
then { name = schemaItem.name; inherit value; }
else null
;

tryGetSettingsRow = schemaItem:
if hasAttrByPath schemaItem.target settings
then getSettingsRow schemaItem (getAttrFromPath schemaItem.target settings)
if hasAttrByPath schemaItem.value.loc settings
then getSettingsRow schemaItem (getAttrFromPath schemaItem.value.loc settings)
else null
;

in

listToAttrs (filter (x: x != null) (map tryGetSettingsRow settingsSchema))
listToAttrs (filter (x: x != null) (map tryGetSettingsRow (attrsToList settingsSchema)))

0 comments on commit 21c5e4c

Please sign in to comment.