nixvimConfig/helperLib/default.nix
2024-07-03 00:37:56 +02:00

121 lines
3.3 KiB
Nix

{inputs}: let
helperLib = (import ./default.nix) {inherit inputs;};
outputs = inputs.self.outputs;
overlay-stable = final: prev: {
stable = inputs.nixpkgs-stable.legacyPackages.${prev.system};
};
in rec {
# imports = [
# ./syncthing.nix
# ];
# ================================================================ #
# = My Lib = #
# ================================================================ #
# ======================= Package Helpers ======================== #
pkgsFor = sys: inputs.nixpkgs.legacyPackages.${sys};
# ========================== Buildables ========================== #
mkSystem = config:
inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs outputs helperLib;
};
modules = [
({
config,
pkgs,
...
}: {nixpkgs.overlays = [overlay-stable];})
config
outputs.nixosModules.default
];
};
mkHome = sys: config:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = pkgsFor sys;
extraSpecialArgs = {
inherit inputs helperLib outputs;
};
modules = [
({
config,
pkgs,
...
}: {nixpkgs.overlays = [overlay-stable];})
config
outputs.homeManagerModules.default
];
};
# =========================== Helpers ============================ #
filesIn = dir: (map (fname: dir + "/${fname}")
(builtins.attrNames (builtins.readDir dir)));
dirsIn = dir:
inputs.nixpkgs.lib.filterAttrs (name: value: value == "directory")
(builtins.readDir dir);
fileNameOf = path: (builtins.head (builtins.split "\\." (baseNameOf path)));
# ========================== Extenders =========================== #
# Evaluates nixos/home-manager module and extends it's options / config
extendModule = {path, ...} @ args: {pkgs, ...} @ margs: let
eval =
if (builtins.isString path) || (builtins.isPath path)
then import path margs
else path margs;
evalNoImports = builtins.removeAttrs eval ["imports" "options"];
extra =
if (builtins.hasAttr "extraOptions" args) || (builtins.hasAttr "extraConfig" args)
then [
({...}: {
options = args.extraOptions or {};
config = args.extraConfig or {};
})
]
else [];
in {
imports =
(eval.imports or [])
++ extra;
options =
if builtins.hasAttr "optionsExtension" args
then (args.optionsExtension (eval.options or {}))
else (eval.options or {});
config =
if builtins.hasAttr "configExtension" args
then (args.configExtension (eval.config or evalNoImports))
else (eval.config or evalNoImports);
};
# Applies extendModules to all modules
# modules can be defined in the same way
# as regular imports, or taken from "filesIn"
extendModules = extension: modules:
map
(f: let
name = fileNameOf f;
in (extendModule ((extension name) // {path = f;})))
modules;
# ============================ Shell ============================= #
forAllSystems =
# pkgs:
inputs.nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# (system: pkgs inputs.nixpkgs.legacyPackages.${system});
}