Skip to content

Commit

Permalink
treewide: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Nov 6, 2023
1 parent 84fc8eb commit c1f4491
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 194 deletions.
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
types = import ./types {inherit lib;};
languages = import ./languages.nix {inherit lib;};
lua = import ./lua.nix {inherit lib;};
vim = import ./vim.nix {inherit lib;};
}
51 changes: 44 additions & 7 deletions lib/lua.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Helpers for converting values to lua
{lib}: rec {
# yes? no.
yesNo = value:
if value
then "yes"
else "no";

{lib}: let
inherit (lib) mapAttrsToList filterAttrs concatStringsSep concatMapStringsSep stringToCharacters boolToString;
inherit (builtins) hasAttr head;
in rec {
# Convert a null value to lua's nil
nullString = value:
if value == null
Expand Down Expand Up @@ -46,4 +43,44 @@
+ " }";
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';

toLuaObject = args:
if builtins.isAttrs args
then
if hasAttr "__raw" args
then args.__raw
else if hasAttr "__empty" args
then "{ }"
else
"{"
+ (concatStringsSep ","
(mapAttrsToList
(n: v:
if head (stringToCharacters n) == "@"
then toLuaObject v
else "[${toLuaObject n}] = " + (toLuaObject v))
(filterAttrs
(
_: v:
(v != null) && (toLuaObject v != "{}")
)
args)))
+ "}"
else if builtins.isList args
then "{" + concatMapStringsSep "," toLuaObject args + "}"
else if builtins.isString args
then
# This should be enough!
builtins.toJSON args
else if builtins.isPath args
then builtins.toJSON (toString args)
else if builtins.isBool args
then "${boolToString args}"
else if builtins.isFloat args
then "${toString args}"
else if builtins.isInt args
then "${toString args}"
else if (args != null)
then "nil"
else "";
}
26 changes: 26 additions & 0 deletions lib/vim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{lib}: let
inherit (builtins) isInt isBool toJSON;
in rec {
# yes? no.
yesNo = value:
if value
then "yes"
else "no";

# convert a boolean to a vim compliant boolean string
mkVimBool = val:
if val
then "1"
else "0";

# convert a literal value to a vim compliant value
valToVim = val:
if (isInt val)
then (builtins.toString val)
else
(
if (isBool val)
then (mkVimBool val)
else (toJSON val)
);
}
27 changes: 0 additions & 27 deletions modules/assertions.nix

This file was deleted.

8 changes: 4 additions & 4 deletions modules/basic/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
lib,
config,
...
}:
with lib;
with builtins; let
}: let
inherit (lib) optionalString mkIf nvim;

cfg = config.vim;
in {
config = {
Expand Down Expand Up @@ -57,8 +57,8 @@ in {
};

vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] ''
" Debug mode settings
${optionalString cfg.debugMode.enable ''
" Debug mode settings
set verbose=${toString cfg.debugMode.level}
set verbosefile=${cfg.debugMode.logFile}
''}
Expand Down
7 changes: 4 additions & 3 deletions modules/basic/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pkgs,
lib,
...
}:
with lib;
with builtins; {
}: let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) types;
in {
options.vim = {
package = mkOption {
type = types.package;
Expand Down
Loading

0 comments on commit c1f4491

Please sign in to comment.