feasible config for the beginning
This commit is contained in:
parent
b4c2ba8174
commit
25d5980e6c
13 changed files with 563 additions and 203 deletions
103
helperLib/default.nix
Normal file
103
helperLib/default.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
{inputs}: let
|
||||
helperLib = (import ./default.nix) {inherit inputs;};
|
||||
outputs = inputs.self.outputs;
|
||||
in rec {
|
||||
# ================================================================ #
|
||||
# = My Lib = #
|
||||
# ================================================================ #
|
||||
|
||||
# ======================= Package Helpers ======================== #
|
||||
|
||||
pkgsFor = sys: inputs.nixpkgs.legacyPackages.${sys};
|
||||
|
||||
# ========================== Buildables ========================== #
|
||||
|
||||
mkSystem = config:
|
||||
inputs.nixpkgs.lib.nixosSystem {
|
||||
specialArgs = {
|
||||
inherit inputs outputs helperLib;
|
||||
};
|
||||
modules = [
|
||||
config
|
||||
outputs.nixosModules.default
|
||||
];
|
||||
};
|
||||
|
||||
mkHome = sys: config:
|
||||
inputs.home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = pkgsFor sys;
|
||||
extraSpecialArgs = {
|
||||
inherit inputs helperLib outputs;
|
||||
};
|
||||
modules = [
|
||||
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});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue