Skip to content

Commit

Permalink
New lib.makeOverridable scheme makes stuff cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Mar 12, 2024
1 parent 050e665 commit 1ae75dc
Show file tree
Hide file tree
Showing 29 changed files with 553 additions and 556 deletions.
5 changes: 1 addition & 4 deletions codedown.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ rec {

languages = languagesFn false;
languagesSearcher = common.searcher' {
packages = let
filterOverrideKeys = lib.filterAttrs (k: _: !(lib.hasPrefix "override") k);
in
filterOverrideKeys (lib.mapAttrs (n: v: v.build {}) (languagesFn true));
packages = languagesFn true;
};
languagesIcons = common.searcherIcons' {
packages = languagesFn true;
Expand Down
2 changes: 1 addition & 1 deletion codedown/mkCodeDownEnvironment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let
languagesCommon = callPackage ../languages/common.nix {};
shellsCommon = callPackage ../shells/common.nix {};

builtKernels = map (x: let kernel = (getAttr x.name languages).build x.args; in
builtKernels = map (x: let kernel = (getAttr x.name languages).override x.args; in
kernel.overrideAttrs (old: {
passthru = old.passthru // {
name = x.name;
Expand Down
24 changes: 11 additions & 13 deletions languages/bash/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let
chooseLanguageServers = settings: kernelName:
[]
++ lib.optionals (common.isTrue settings "lsp.bash-language-server.enable") [(callPackage ./language_server_bash { inherit kernelName; })]
;
;

settingsSchema = [
{
Expand All @@ -42,22 +42,20 @@ lib.listToAttrs (map (x:
icon = ./bash-logo-128x128.png;
inherit settingsSchema;
};
versions = {
bash = bash.version;
bash-language-server = nodePackages.bash-language-server.version;
};
in
{
name = x;
value = rec {
inherit packageOptions packageSearch;
versions = {
bash = bash.version;
bash-language-server = nodePackages.bash-language-server.version;
};

build = args@{
value =
lib.makeOverridable ({
packages ? []
, attrs ? ["bash"]
, extensions ? ["sh" "bash"]
, settings ? {}
}:
}@args:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;
in symlinkJoin {
Expand All @@ -72,14 +70,14 @@ lib.listToAttrs (map (x:

passthru = {
args = args // { baseName = x; };
inherit meta packageOptions;
inherit meta packageOptions packageSearch versions;
inherit settingsSchema settings;
modes = {
inherit attrs extensions;
code_mirror_mode = "shell";
};
};
};
};
}
) {};
}
) (lib.filter (x: lib.hasAttr x pkgs) baseCandidates))
72 changes: 36 additions & 36 deletions languages/clojure/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ let
clojure-lsp = (builtins.getFlake "github:clojure-lsp/clojure-lsp/5e3584014f2ac9c13a877dfd7984383346d81609").packages.x86_64-linux.default;

chooseLanguageServers = settings: kernelName:
[]
++ lib.optionals (common.isTrue settings "lsp.clojure-lsp.enable") [(callPackage ./language-server.nix { inherit clojure-lsp kernelName; })]
[]
++ lib.optionals (common.isTrue settings "lsp.clojure-lsp.enable") [(callPackage ./language-server.nix { inherit clojure-lsp kernelName; })]
;

in
Expand All @@ -58,45 +58,45 @@ listToAttrs (map (x:
inherit settingsSchema;
};

packageOptions = getAttr x packagesLookup;
packageSearch = common.searcher packageOptions;
versions = {
clojure = clojure.version;
clojure-lsp = clojure-lsp.version;
};

in {
name = x;
value = rec {
packageOptions = getAttr x packagesLookup;
packageSearch = common.searcher packageOptions;
versions = {
clojure = clojure.version;
clojure-lsp = clojure-lsp.version;
};
value = lib.makeOverridable (args@{
packages ? []
, settings ? {}
, attrs ? ["clojure"]
, extensions ? ["clj"]
}:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;
in symlinkJoin {
name = "clojure";
paths = [
(callPackage ./kernel.nix { inherit attrs extensions version; })
clojure
]
++ (chooseLanguageServers settingsToUse x)
;

build = args@{
packages ? []
, settings ? {}
, attrs ? ["clojure"]
, extensions ? ["clj"]
}:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;
in symlinkJoin {
name = "clojure";
paths = [
(callPackage ./kernel.nix { inherit attrs extensions version; })
clojure
]
++ (chooseLanguageServers settingsToUse x)
;

passthru = {
inherit meta packageOptions settingsSchema;
inherit settings;
args = args // { baseName = x; };
repls = repls clojure;
modes = {
inherit attrs extensions;
code_mirror_mode = "clojure";
};
passthru = {
inherit meta packageOptions packageSearch versions;
inherit settingsSchema settings;
args = args // { baseName = x; };
repls = repls clojure;
modes = {
inherit attrs extensions;
code_mirror_mode = "clojure";
};
};
};
}
) {}
;
}

) (filter (x: (common.hasAttrSafe x pkgs) && !(attrByPath [x "meta" "broken"] false pkgs)) baseCandidates))
108 changes: 54 additions & 54 deletions languages/coq/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,68 @@ let

chooseLanguageServers = settings: coq: kernelName:
[]
;
;

in

lib.listToAttrs (map (x:
let coqPackages = lib.getAttr x pkgs;
baseCoq = coqPackages.coq;
baseName = with builtins; (substring 0 3 x) + (substring 11 (stringLength x - 11) x);
displayName = "Coq";
meta = baseCoq.meta // {
inherit baseName displayName settingsSchema;
version = baseCoq.version;
icon = coq_jupyter.sizedLogo "64";
lessCommon = isLessCommon x;
};
let
coqPackages = lib.getAttr x pkgs;
baseCoq = coqPackages.coq;
baseName = with builtins; (substring 0 3 x) + (substring 11 (stringLength x - 11) x);
displayName = "Coq";
meta = baseCoq.meta // {
inherit baseName displayName settingsSchema;
version = baseCoq.version;
icon = coq_jupyter.sizedLogo "64";
lessCommon = isLessCommon x;
};

packageOptions = coqPackages;
packageSearch = common.searcher packageOptions;
versions = {
coq = baseCoq.version;
};

in {
name = baseName;
value = rec {
packageOptions = coqPackages;
packageSearch = common.searcher packageOptions;
versions = {
coq = baseCoq.version;
};

build = args@{
packages ? []
, attrs ? [baseName "coq"]
, extensions ? ["v"]
, settings ? {}
}:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;

coq = baseCoq;

in symlinkJoin {
name = baseName;

paths = [
(callPackage ./kernel.nix {
inherit coq displayName attrs extensions;
enableVariableInspector = settingsToUse.enableVariableInspector;
chosenPackages = map (x: builtins.getAttr x packageOptions) packages;
})

coq
]
++ (chooseLanguageServers settingsToUse coq baseName)
;

passthru = {
inherit meta packageOptions;
inherit settings settingsSchema;
args = args // { inherit baseName; };
repls = repls coq;
modes = {
inherit attrs extensions;
code_mirror_mode = "coq";
};
value = lib.makeOverridable ({
packages ? []
, attrs ? [baseName "coq"]
, extensions ? ["v"]
, settings ? {}
}@args:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;

coq = baseCoq;

in symlinkJoin {
name = baseName;

paths = [
(callPackage ./kernel.nix {
inherit coq displayName attrs extensions;
enableVariableInspector = settingsToUse.enableVariableInspector;
chosenPackages = map (x: builtins.getAttr x packageOptions) packages;
})

coq
]
++ (chooseLanguageServers settingsToUse coq baseName)
;

passthru = {
inherit meta packageOptions packageSearch versions;
inherit settings settingsSchema;
args = args // { inherit baseName; };
repls = repls coq;
modes = {
inherit attrs extensions;
code_mirror_mode = "coq";
};
};
};
}
) {};
}
) (lib.filter (x: lib.hasAttr x pkgs) baseCandidates))
81 changes: 40 additions & 41 deletions languages/cpp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,49 @@ if cling == null then {} else

xeus-cling = callPackage ./xeus-cling/xeus-cling.nix { inherit cling; };

packageOptions = {};
packageSearch = common.searcher packageOptions;
versions = {
clang = clang.version;
cling = cling.unwrapped.version;
xeus-cling = xeus-cling.version;
std = std;
};

in {
name = x;
value = rec {
packageOptions = {};
packageSearch = common.searcher packageOptions;
versions = {
clang = clang.version;
cling = cling.unwrapped.version;
xeus-cling = xeus-cling.version;
std = std;
};

build = args@{
packages ? []
, settings ? {}
, attrs ? [x "cpp"]
, extensions ? ["cpp" "hpp" "cxx" "hxx" "c" "h"]
}:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;
in symlinkJoin {
name = x;
paths = [
((callPackage ./kernel_xeus.nix {
inherit cling xeus-cling;
inherit attrs displayName extensions std;
attrName = x;
}))
cling
]
;

passthru = {
inherit meta packageOptions;
inherit settings settingsSchema;
args = args // { baseName = x; };
repls = repls (getAttr x icons);
modes = {
inherit attrs extensions;
code_mirror_mode = "clike";
code_mirror_mime_type = "text/x-c++src";
};
value = lib.makeOverridable ({
packages ? []
, settings ? {}
, attrs ? [x "cpp"]
, extensions ? ["cpp" "hpp" "cxx" "hxx" "c" "h"]
}@args:
let
settingsToUse = (common.makeDefaultSettings settingsSchema) // settings;
in symlinkJoin {
name = x;
paths = [
((callPackage ./kernel_xeus.nix {
inherit cling xeus-cling;
inherit attrs displayName extensions std;
attrName = x;
}))
cling
]
;

passthru = {
inherit meta packageOptions packageSearch versions;
inherit settings settingsSchema;
args = args // { baseName = x; };
repls = repls (getAttr x icons);
modes = {
inherit attrs extensions;
code_mirror_mode = "clike";
code_mirror_mime_type = "text/x-c++src";
};
};
};
}
) {};
}
) baseCandidates)
Loading

0 comments on commit 1ae75dc

Please sign in to comment.