chore: reformat codebase

This commit is contained in:
Gabriel Arazas 2024-02-02 12:40:16 +08:00
parent 2f389641cd
commit 44090d6257
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
12 changed files with 345 additions and 327 deletions

View File

@ -22,5 +22,6 @@
boot.loader.efi.canTouchEfiVariables = true;
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
hardware.cpu.intel.updateMicrocode =
lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View File

@ -1,31 +1,31 @@
return {
s(
"today",
f(function()
return os.date("%F")
end)
),
s(
"today",
f(function()
return os.date("%F")
end)
),
s(
"retrieve",
f(function()
return string.format("(retrieved %s)", os.date("%F"))
end)
),
s(
"retrieve",
f(function()
return string.format("(retrieved %s)", os.date("%F"))
end)
),
s(
{ trig = 'reldate (-?%d+) "(.+)"', regTrig = true },
f(function(_, snip)
-- The point is in number of days.
local point = 60 * 60 * 24 * snip.captures[1]
s(
{ trig = 'reldate (-?%d+) "(.+)"', regTrig = true },
f(function(_, snip)
-- The point is in number of days.
local point = 60 * 60 * 24 * snip.captures[1]
local now = os.time()
return os.date(snip.captures[2], now + point)
end)
),
local now = os.time()
return os.date(snip.captures[2], now + point)
end)
),
s("#!", fmt("#!{}", i(1, "/usr/bin/env bash"))),
s("#!", fmt("#!{}", i(1, "/usr/bin/env bash"))),
parse("ie", "(i.e., $1)"),
parse("eg", "(e.g., $1)"),
parse("ie", "(i.e., $1)"),
parse("eg", "(e.g., $1)"),
}

View File

@ -1,170 +1,170 @@
function max_asciidoc_header(level)
return math.min(level, 6)
return math.min(level, 6)
end
return {
parse("bf", "**$1**"),
parse("it", "__$1__"),
parse("sp", "^$1^"),
parse("sb", "~$1~"),
s(
"tt",
fmt("{}{}{}", {
c(1, { t("`"), t("`+") }),
i(2, "TEXT"),
rep(1),
})
),
parse("bf", "**$1**"),
parse("it", "__$1__"),
parse("sp", "^$1^"),
parse("sb", "~$1~"),
s(
"tt",
fmt("{}{}{}", {
c(1, { t("`"), t("`+") }),
i(2, "TEXT"),
rep(1),
})
),
parse("foot", "footnote:[$1]"),
parse("foot", "footnote:[$1]"),
s(
"link",
fmt("link:{}[{}]", {
i(1, "LINK"),
rep(1),
})
),
s(
"link",
fmt("link:{}[{}]", {
i(1, "LINK"),
rep(1),
})
),
parse("var", ":$1: $2"),
parse("var", ":$1: $2"),
parse("audio", "audio::$1[$2]"),
parse("video", "video::$1[$2]"),
parse("audio", "audio::$1[$2]"),
parse("video", "video::$1[$2]"),
s(
"img",
fmt(
[[
s(
"img",
fmt(
[[
.{}
image::{}[{}, {}]
{}
]],
{
i(1, "CAPTION"),
i(2, "IMAGE_PATH"),
i(3, "ALT_TEXT"),
i(4, "width=100%,height=100%"),
i(0),
}
)
),
{
i(1, "CAPTION"),
i(2, "IMAGE_PATH"),
i(3, "ALT_TEXT"),
i(4, "width=100%,height=100%"),
i(0),
}
)
),
s(
"fmt",
fmt("{}{}{}", {
c(1, {
t("**"),
t("__"),
t("`"),
}),
i(2),
rep(1),
})
),
s(
"fmt",
fmt("{}{}{}", {
c(1, {
t("**"),
t("__"),
t("`"),
}),
i(2),
rep(1),
})
),
s(
"dt",
fmt(
[[
s(
"dt",
fmt(
[[
{}::
{}
]],
{
i(1, "TERM"),
i(2, "DEFINITION"),
}
)
),
{
i(1, "TERM"),
i(2, "DEFINITION"),
}
)
),
s(
"src",
fmt(
[[
s(
"src",
fmt(
[[
[source, {}]
----
{}
----
{}
]],
{
i(1, "LANGUAGE"),
i(2, "CODE"),
i(0),
}
)
),
{
i(1, "LANGUAGE"),
i(2, "CODE"),
i(0),
}
)
),
s(
{ trig = "h(%d)", regTrig = true },
fmt(
[[
s(
{ trig = "h(%d)", regTrig = true },
fmt(
[[
{} {}
{}
{}
]],
{
f(function(_, snip)
local level = max_asciidoc_header(snip.captures[1])
return string.rep("=", level)
end),
i(1, "CHAPTER"),
d(2, function(_, snip)
local nodes = {}
table.insert(nodes, t(""))
{
f(function(_, snip)
local level = max_asciidoc_header(snip.captures[1])
return string.rep("=", level)
end),
i(1, "CHAPTER"),
d(2, function(_, snip)
local nodes = {}
table.insert(nodes, t(""))
local level = max_asciidoc_header(snip.captures[1])
local level = max_asciidoc_header(snip.captures[1])
if level == 1 then
table.insert(nodes, t(":toc:"))
end
if level == 1 then
table.insert(nodes, t(":toc:"))
end
local parent = c(1, nodes)
if level > 1 then
parent = t("")
end
local parent = c(1, nodes)
if level > 1 then
parent = t("")
end
return sn(nil, parent)
end, {}),
i(0),
}
)
),
return sn(nil, parent)
end, {}),
i(0),
}
)
),
s(
"admon",
fmt("{}: {}", {
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(0),
})
),
s(
"admon",
fmt("{}: {}", {
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(0),
})
),
s(
"admonB",
fmt(
[[
s(
"admonB",
fmt(
[[
[{}]
====
{}
====
{}
]],
{
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(2, "BODY"),
i(0),
}
)
),
{
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(2, "BODY"),
i(0),
}
)
),
}

View File

@ -60,10 +60,10 @@ in
query = "@${query}.outer";
};
in
lib.mapAttrs' mkQueryMappings {
"function" = "f";
"class" = "F";
};
lib.mapAttrs' mkQueryMappings {
"function" = "f";
"class" = "F";
};
};
move = lib.mkMerge ([{
enable = true;
@ -100,8 +100,9 @@ in
# A set of bindings to be used for each jump direction.
bindings:
let
mappings = builtins.map (motion:
let
mappings = builtins.map
(motion:
let
inherit (motion) region jumpDirection variant;
jumpDirection' = lib.strings.toLower jumpDirection;
@ -115,19 +116,21 @@ in
query = "@${query}.${variant}";
};
};
}) motions;
in
acc ++ mappings;
})
motions;
in
acc ++ mappings;
in
lib.foldlAttrs mkQueryMappings [ ] {
"function" = { previous = "M"; next = "m"; };
"function" = { previous = "M"; next = "m"; };
"block" = { previous = "B"; next = "b"; };
"call" = { previous = "F"; next = "f"; };
"class" = { previous = "C"; next = "c"; };
"conditional" = { previous = "D"; next = "d"; };
"statement" = { previous = "S"; next = "s"; };
"loop" = { previous = "L"; next = "l"; };
}));
}
));
select = {
enable = true;
lookahead = true;
@ -161,16 +164,17 @@ in
let
mappingsList =
builtins.map (variant:
let
prefixMap' = prefixMap.${variant};
in
lib.nameValuePair "${prefixMap'.key}${binding}" {
query = "@${query}.${variant}";
desc = prefixMap'.desc query;
}) [ "outer" "inner" ];
builtins.map
(variant:
let
prefixMap' = prefixMap.${variant};
in
lib.nameValuePair "${prefixMap'.key}${binding}" {
query = "@${query}.${variant}";
desc = prefixMap'.desc query;
}) [ "outer" "inner" ];
in
lib.listToAttrs mappingsList;
lib.listToAttrs mappingsList;
in
lib.concatMapAttrs mkQueryMappings {
"function" = "m";
@ -203,29 +207,33 @@ in
mkQueryMappings = acc: query: bindings:
let
mappings = builtins.map (motion:
let
inherit (motion) jumpDirection variant;
jumpDirection' = lib.strings.toLower jumpDirection;
binding' = bindings.${jumpDirection'};
bindingPrefix = motionMap."${variant}${jumpDirection}";
in
{
"swap${jumpDirection}" = {
"${bindingPrefix}${binding'}" = {
desc = actionDesc variant jumpDirection' query;
query = "@${query}.${variant}";
mappings = builtins.map
(motion:
let
inherit (motion) jumpDirection variant;
jumpDirection' = lib.strings.toLower jumpDirection;
binding' = bindings.${jumpDirection'};
bindingPrefix = motionMap."${variant}${jumpDirection}";
in
{
"swap${jumpDirection}" = {
"${bindingPrefix}${binding'}" = {
desc = actionDesc variant jumpDirection' query;
query = "@${query}.${variant}";
};
};
};
}) motions;
})
motions;
in
acc ++ mappings;
acc ++ mappings;
in
lib.foldlAttrs mkQueryMappings [ ] {
"function" = { next = "f"; previous = "F"; };
"parameter" = { next = "a"; previous = "A"; };
"conditional" = { next = "d"; previous = "D"; };
}));
lib.foldlAttrs mkQueryMappings [ ] {
"function" = { next = "f"; previous = "F"; };
"parameter" = { next = "a"; previous = "A"; };
"conditional" = { next = "d"; previous = "D"; };
}
)
);
};
};
}

View File

@ -7,7 +7,12 @@ let
partsConfig = config;
# A thin wrapper around the home-manager configuration function.
mkHome = { system, nixpkgsBranch ? "nixpkgs", homeManagerBranch ? "home-manager", extraModules ? [ ] }:
mkHome =
{ system
, nixpkgsBranch ? "nixpkgs"
, homeManagerBranch ? "home-manager"
, extraModules ? [ ]
}:
let
pkgs = inputs.${nixpkgsBranch}.legacyPackages.${system};
in

View File

@ -41,7 +41,12 @@ let
};
# A very very thin wrapper around `mkHost` to build with the given format.
mkImage = { system, nixpkgsBranch ? "nixpkgs", extraModules ? [ ], format ? "iso" }:
mkImage =
{ system
, nixpkgsBranch ? "nixpkgs"
, extraModules ? [ ]
, format ? "iso"
}:
let
extraModules' =
extraModules ++ [ inputs.nixos-generators.nixosModules.${format} ];
@ -295,72 +300,71 @@ let
};
};
config = {
modules = [
# Bring in the required modules.
inputs.${config.homeManagerBranch}.nixosModules.home-manager
../../../configs/nixos/${name}
config.modules = [
# Bring in the required modules.
inputs.${config.homeManagerBranch}.nixosModules.home-manager
../../../configs/nixos/${name}
# Mapping the declarative home-manager users (if it has one) into NixOS
# users.
(lib.mkIf (config.homeManagerUsers.users != { })
(
let
setupConfig = config;
hasHomeManagerUsers = config.homeManagerUsers.users != { };
inherit (config.homeManagerUsers) nixpkgsInstance;
isNixpkgs = state: hasHomeManagerUsers && nixpkgsInstance == state;
in
{ config, lib, pkgs, ... }: {
config = lib.mkMerge [
(lib.mkIf hasHomeManagerUsers {
users.users =
lib.mkMerge
(lib.mapAttrsToList
(name: hmUser: { ${name} = hmUser.userConfig; })
setupConfig.homeManagerUsers.users);
home-manager.users = lib.mkMerge
# Mapping the declarative home-manager users (if it has one) into NixOS
# users.
(lib.mkIf (config.homeManagerUsers.users != { })
(
let
setupConfig = config;
hasHomeManagerUsers = config.homeManagerUsers.users != { };
inherit (config.homeManagerUsers) nixpkgsInstance;
isNixpkgs = state: hasHomeManagerUsers && nixpkgsInstance == state;
in
{ config, lib, pkgs, ... }: {
config = lib.mkMerge [
(lib.mkIf hasHomeManagerUsers {
users.users =
lib.mkMerge
(lib.mapAttrsToList
(name: hmUser: {
${name} = { lib, ... }: {
imports =
partsConfig.setups.home-manager.configs.${name}.modules
++ hmUser.additionalModules;
(name: hmUser: { ${name} = hmUser.userConfig; })
setupConfig.homeManagerUsers.users);
home-manager.users = lib.mkMerge
(lib.mapAttrsToList
(name: hmUser: {
${name} = { lib, ... }: {
imports =
partsConfig.setups.home-manager.configs.${name}.modules
++ hmUser.additionalModules;
};
})
setupConfig.homeManagerUsers.users);
})
(lib.mkIf (isNixpkgs "global") {
home-manager.useGlobalPkgs = lib.mkForce true;
# Disable all options that are going to be blocked once
# `home-manager.useGlobalPkgs` is used.
home-manager.users =
lib.mkMerge
(lib.mapAttrsToList
(name: _: {
${name} = {
nixpkgs.overlays = lib.mkForce null;
nixpkgs.config = lib.mkForce null;
};
})
setupConfig.homeManagerUsers.users);
})
(lib.mkIf (isNixpkgs "global") {
home-manager.useGlobalPkgs = lib.mkForce true;
# Then apply all of the user overlays into the nixpkgs instance
# of the NixOS system.
nixpkgs.overlays =
let
hmUsersOverlays =
lib.mapAttrsToList
(name: _:
partsConfig.setups.home-manager.configs.${name}.overlays)
setupConfig.homeManagerUsers.users;
# Disable all options that are going to be blocked once
# `home-manager.useGlobalPkgs` is used.
home-manager.users =
lib.mkMerge
(lib.mapAttrsToList
(name: _: {
${name} = {
nixpkgs.overlays = lib.mkForce null;
nixpkgs.config = lib.mkForce null;
};
})
setupConfig.homeManagerUsers.users);
# Then apply all of the user overlays into the nixpkgs instance
# of the NixOS system.
nixpkgs.overlays =
let
hmUsersOverlays =
lib.mapAttrsToList
(name: _:
partsConfig.setups.home-manager.configs.${name}.overlays)
setupConfig.homeManagerUsers.users;
overlays = lib.lists.flatten hmUsersOverlays;
in
# Most of the overlays are going to be imported from a
overlays = lib.lists.flatten hmUsersOverlays;
in
# Most of the overlays are going to be imported from a
# variable anyways. This should massively reduce the step
# needed for nixpkgs to do its thing.
#
@ -368,64 +372,64 @@ let
# overlay list is constructed. However, this is much more
# preferable than letting a massive list with duplicated
# overlays from different home-manager users to be applied.
lib.lists.unique overlays;
})
lib.lists.unique overlays;
})
(lib.mkIf (isNixpkgs "separate") {
home-manager.useGlobalPkgs = lib.mkForce false;
home-manager.users =
lib.mkMerge
(lib.mapAttrsToList
(name: _: {
${name} = {
nixpkgs.overlays =
partsConfig.setups.home-manager.configs.${name}.overlays;
};
})
setupConfig.homeManagerUsers.users);
})
];
}))
(lib.mkIf (isNixpkgs "separate") {
home-manager.useGlobalPkgs = lib.mkForce false;
home-manager.users =
lib.mkMerge
(lib.mapAttrsToList
(name: _: {
${name} = {
nixpkgs.overlays =
partsConfig.setups.home-manager.configs.${name}.overlays;
};
})
setupConfig.homeManagerUsers.users);
})
];
}
))
# Next, we include the chosen NixVim configuration into NixOS.
(lib.mkIf (config.nixvim.instance != null)
(
let
setupConfig = config;
in
{ config, lib, ... }: {
imports = [ inputs.nixvim.nixosModules.nixvim ];
programs.nixvim = {
enable = true;
imports =
partsConfig.setups.nixvim.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ setupConfig.nixvim.additionalModules;
};
}
))
# Setting up the typical configuration.
# Next, we include the chosen NixVim configuration into NixOS.
(lib.mkIf (config.nixvim.instance != null)
(
let
setupConfig = config;
in
{ config, lib, ... }: {
config = lib.mkMerge [
{
nixpkgs.overlays = setupConfig.overlays;
networking.hostName = lib.mkDefault setupConfig.hostname;
}
imports = [ inputs.nixvim.nixosModules.nixvim ];
(lib.mkIf (setupConfig.domain != null) {
networking.domain = lib.mkDefault setupConfig.domain;
})
];
programs.nixvim = {
enable = true;
imports =
partsConfig.setups.nixvim.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ setupConfig.nixvim.additionalModules;
};
}
)
];
};
))
# Setting up the typical configuration.
(
let
setupConfig = config;
in
{ config, lib, ... }: {
config = lib.mkMerge [
{
nixpkgs.overlays = setupConfig.overlays;
networking.hostName = lib.mkDefault setupConfig.hostname;
}
(lib.mkIf (setupConfig.domain != null) {
networking.domain = lib.mkDefault setupConfig.domain;
})
];
}
)
];
};
in
{

View File

@ -11,7 +11,7 @@ let
cfg = config.setups.nixvim;
nixvimModules = ../../nixvim;
mkNixvimConfig = { system, pkgs, modules ? [] }:
mkNixvimConfig = { system, pkgs, modules ? [ ] }:
inputs.nixvim.legacyPackages.${system}.makeNixvimWithModule {
inherit pkgs;
module = {
@ -24,7 +24,7 @@ let
modulesOption = lib.mkOption {
type = with lib.types; listOf raw;
default = [];
default = [ ];
};
modulesOption' = configEnv: modulesOption // {
description = ''
@ -84,7 +84,7 @@ in
configType
];
});
default = {};
default = { };
description = ''
A set of NixVim configurations to be integrated into the declarative
setups configuration. Each of them will be available as part of
@ -101,14 +101,15 @@ in
standaloneConfigModules = modulesOption' "standalone configuration";
};
config = lib.mkIf (cfg.configs != {}) {
config = lib.mkIf (cfg.configs != { }) {
setups.nixvim.sharedModules = [ nixvimModules ];
perSystem = { system, config, lib, ... }:
(
let
validConfigs = lib.filterAttrs
(_: metadata: lib.elem system metadata.systems) cfg.configs;
(_: metadata: lib.elem system metadata.systems)
cfg.configs;
nixvimConfigurations =
let
@ -135,7 +136,7 @@ in
cfg.sharedModules
++ cfg.standaloneConfigModules
++ metadata.modules
++ [ { package = neovimPkg; } ];
++ [{ package = neovimPkg; }];
});
in
builtins.map mkNixvimConfig' neovimPackages;
@ -157,8 +158,8 @@ in
lib.nameValuePair
"nixvim-check-${name}"
(inputs.nixvim.lib.${system}.check.mkTestDerivationFromNvim {
inherit nvim;
name = "${name} configuration";
inherit nvim;
name = "${name} configuration";
}))
nixvimConfigurations;
}

View File

@ -4,7 +4,7 @@
{
fonts.enableDefaultPackages = lib.mkDefault true;
fonts.fontDir.enable = lib.mkDefault true;
fonts.fontconfig = {
enable = lib.mkDefault true;
includeUserConf = true;

View File

@ -142,7 +142,7 @@ in
socketOptions
unitConfig
]);
};
};
pathUnit = optionalSystemdUnitOption "path" "paths" // {
type =
@ -205,8 +205,9 @@ in
TODO: Is `Type=notify` a good default?
* `Service.Type=` is obviously not included since not all desktop
components are the same either. Some of them could be a D-Bus service,
some of them are oneshots, etc. Not to mention, this is already implied
to be `Type=simple` by systemd anyways which is enough for most cases.
some of them are oneshots, etc. Though, it might be better to have this
as an explicit option set by the user instead of setting `Type=notify` as
a default.
TODO: A good balance for this value, probably?
* `Service.OOMScoreAdjust=` have different values for different

View File

@ -45,7 +45,7 @@ let
inherit (utils.systemdUtils.lib)
pathToUnit serviceToUnit targetToUnit timerToUnit socketToUnit;
sessionComponents =
sessionComponents =
lib.foldlAttrs
(acc: name: component:
acc // {
@ -61,10 +61,10 @@ let
{ }
session.components;
in
sessionComponents // {
"${name}.service" = serviceToUnit name session.serviceUnit;
"${name}.target" = targetToUnit name session.targetUnit;
}
sessionComponents // {
"${name}.service" = serviceToUnit name session.serviceUnit;
"${name}.target" = targetToUnit name session.targetUnit;
}
)
cfg.sessions;
in
@ -173,12 +173,10 @@ in
environment.
::: {.tip}
While you can make identifiers in any way, it is
encouraged to stick to a naming scheme. Here's two common ways to name
a desktop environment.
* Reverse DNS-like scheme (e.g., `com.example.MoseyBranch`).
* Kebab-case (e.g., `mosey-branch`).
While you can make identifiers in any way, it is encouraged to stick to
a naming scheme. The recommended method is a reverse DNS-like scheme
preferably with a domain name you own (e.g.,
`com.example.MoseyBranch`).
:::
'';
default = { };

View File

@ -3,7 +3,7 @@
let
cfg = config.keyunmaps;
keyunmapOption = { config, lib, ...}: {
keyunmapOption = { config, lib, ... }: {
options = {
key = lib.mkOption {
type = lib.types.str;

View File

@ -9,7 +9,7 @@ in
package = helpers.mkPackageOption "firenvim" pkgs.vimPlugins.firenvim;
extraConfig = lib.mkOption {
type = with lib.types; attrsOf anything;
default = {};
default = { };
example = {
globalSettings = { alt = "all"; };
localSettings = {