mirror of
https://github.com/Jokiller230/puzzlevision.git
synced 2025-05-16 16:39:47 +02:00
✨ (modules/flake) improve library loading and implement system class module mappings
This commit is contained in:
parent
7d16e19c8b
commit
f139b88c0b
9 changed files with 144 additions and 73 deletions
lib/module
modules
flake
nixos
systems/x86_64-nixos/puzzlevision
|
@ -3,14 +3,14 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
## Create a NixOS module option as a one-liner.
|
# Create a NixOS module option on a single line.
|
||||||
##
|
|
||||||
## ```nix
|
|
||||||
## lib.mkOpt nixpkgs.lib.types.str "My default" "Option description"
|
|
||||||
## ```
|
|
||||||
##
|
|
||||||
#@ Type -> Any -> String
|
|
||||||
mkOpt =
|
mkOpt =
|
||||||
type: default: description:
|
type: default: description:
|
||||||
lib.mkOption { inherit type default description; };
|
lib.mkOption { inherit type default description; };
|
||||||
|
|
||||||
|
mkBool =
|
||||||
|
default: description:
|
||||||
|
lib.mkOption { inherit default description; type = lib.types.bool; };
|
||||||
|
|
||||||
|
# Todo: add mkIfElse function
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +1,10 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
inputs,
|
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
## Recursive loading of libraries, similar to snowfall lib.
|
|
||||||
## Logical flow: read files => merge all file outputs to single attr. set
|
|
||||||
## The directory in question is flake-root => lib
|
|
||||||
## The directory structure is:
|
|
||||||
## lib/
|
|
||||||
## => libname
|
|
||||||
## => default.nix
|
|
||||||
## => libname2
|
|
||||||
## => default.nix
|
|
||||||
##
|
|
||||||
## The structure of multiple libs is simply for organization and the attrs. of all default.nix files should still be merged
|
|
||||||
## into a single set.
|
|
||||||
loadLibs = directory:
|
|
||||||
builtins.foldl' (acc: name:
|
|
||||||
let
|
|
||||||
path = "${directory}/${name}";
|
|
||||||
isDir = (builtins.getAttr name (builtins.readDir directory)) == "directory";
|
|
||||||
in
|
|
||||||
if isDir then
|
|
||||||
lib.mergeAttrs acc (loadLibs path)
|
|
||||||
else if name == "default.nix" then
|
|
||||||
lib.mergeAttrs acc (import path { inherit lib; })
|
|
||||||
else
|
|
||||||
acc
|
|
||||||
) {} (builtins.attrNames (builtins.readDir directory));
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
# Overwrite and add new arguments to all flake modules.
|
# Apply some useful module arguments.
|
||||||
_module.args = {
|
_module.args = {
|
||||||
namespace = config.flake.namespace;
|
namespace = config.flake.namespace;
|
||||||
|
|
||||||
puzzlelib = loadLibs ../../lib;
|
|
||||||
|
|
||||||
# Initialize nixpkgs instance with custom overlays.
|
|
||||||
pkgs = import inputs.nixpkgs {
|
|
||||||
overlays = [
|
|
||||||
(final: prev: {
|
|
||||||
# Todo: actually append overlays from "/overlays/overlay-name/default.nix" files.
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
# Automagically imports overlays from "/overlays/overlay-name" and applies them to pkgs.
|
# Applies some useful arguments, like namespace, to all flake modules.
|
||||||
# Also applies some other useful arguments, like namespace, to all flake modules.
|
|
||||||
./arguments.nix
|
./arguments.nix
|
||||||
|
|
||||||
|
# Automagically imports libs from "/lib/lib-name" and applies them to the `lib.${namespace}` or `puzzlevision.lib` module argument.
|
||||||
|
./lib.nix
|
||||||
|
|
||||||
|
# Recursively imports overlays from "/overlays/overlay-name" and applies them to the `pkgs` or `puzzlevision.pkgs` module argument.
|
||||||
|
# ./overlays.nix
|
||||||
|
|
||||||
# Automagically imports systems from "/systems/arch-classname/system-name".
|
# Automagically imports systems from "/systems/arch-classname/system-name".
|
||||||
./systems.nix
|
./systems.nix
|
||||||
];
|
];
|
||||||
|
|
54
modules/flake/lib.nix
Normal file
54
modules/flake/lib.nix
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
puzzlelib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
# Utility function to read a directory and return its contents.
|
||||||
|
readDirectory = directory: builtins.readDir directory;
|
||||||
|
|
||||||
|
# Utility function to handle each filesystem entity (file or directory).
|
||||||
|
filesystemEntityToAttrSet = directory: importArgs: name: type:
|
||||||
|
if type == "directory" then
|
||||||
|
dirToAttrSet "${directory}/${name}" importArgs
|
||||||
|
else if name == "default.nix" then
|
||||||
|
import "${directory}/${name}" importArgs
|
||||||
|
else
|
||||||
|
{};
|
||||||
|
|
||||||
|
filesystemEntityToList = directory: name: type:
|
||||||
|
if type == "directory" then
|
||||||
|
dirToModuleList "${directory}/${name}"
|
||||||
|
else if name == "default.nix" then
|
||||||
|
[ "${directory}/${name}" ]
|
||||||
|
else
|
||||||
|
[];
|
||||||
|
|
||||||
|
dirToModuleList = directory:
|
||||||
|
let
|
||||||
|
readDir = readDirectory directory;
|
||||||
|
in
|
||||||
|
builtins.foldl' (acc: name:
|
||||||
|
acc ++ (filesystemEntityToList directory name (builtins.getAttr name readDir))
|
||||||
|
) [] (builtins.attrNames readDir);
|
||||||
|
|
||||||
|
# Utility function to recursively load modules from a directory.
|
||||||
|
dirToAttrSet = directory: importArgs:
|
||||||
|
let
|
||||||
|
# Read provided directory only once at the very start and save the result.
|
||||||
|
readDir = readDirectory directory;
|
||||||
|
in
|
||||||
|
# Iterate over the attr names of a readDir operation.
|
||||||
|
builtins.foldl' (acc: name:
|
||||||
|
# Merge outputs of handling a filesystem entity (file or directory) into accumulator.
|
||||||
|
# Files return attribute sets with their resulting expressions, directories return the result of multiple file handling operations.
|
||||||
|
acc // (filesystemEntityToAttrSet directory importArgs name (builtins.getAttr name readDir))
|
||||||
|
) {} (builtins.attrNames readDir);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# Add lib.${namespace} attribute to module arguments, for easy access.
|
||||||
|
# Additionally, pass on dirToAttrSet method on lib.${namespace} for reusability in other modules.
|
||||||
|
_module.args = {
|
||||||
|
puzzlelib = dirToAttrSet ../../lib { inherit lib puzzlelib; } // { inherit dirToAttrSet dirToModuleList filesystemEntityToList filesystemEntityToAttrSet; };
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
|
lib,
|
||||||
inputs,
|
inputs,
|
||||||
namespace,
|
namespace,
|
||||||
|
puzzlelib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
|
@ -12,19 +14,16 @@
|
||||||
|
|
||||||
shared = {
|
shared = {
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit namespace;
|
inherit namespace puzzlelib;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
perClass = class: {
|
perClass = class: {
|
||||||
modules = [
|
modules = [
|
||||||
# Import modules based on current classname.
|
(lib.optionals (class == "nixos") [
|
||||||
../${class}
|
|
||||||
|
|
||||||
(inputs.nixpkgs.lib.optionals (class == "nixos") [
|
|
||||||
inputs.home-manager.nixosModules.default
|
inputs.home-manager.nixosModules.default
|
||||||
])
|
])
|
||||||
];
|
] ++ (puzzlelib.dirToModuleList ../${class}); # Import modules based on current classname.
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
19
modules/nixos/desktop/gnome/default.nix
Normal file
19
modules/nixos/desktop/gnome/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
namespace,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkEnableOption mkIf;
|
||||||
|
cfg = config.${namespace}.desktop.gnome;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.${namespace}.desktop.gnome = { enable = mkEnableOption "Enable the gnome desktop environment ${namespace}"; };
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
services.xserver.enable = true;
|
||||||
|
services.xserver.displayManager.gdm.enable = true;
|
||||||
|
services.xserver.desktopManager.gnome.enable = true;
|
||||||
|
};
|
||||||
|
}
|
43
modules/nixos/utils/vm/default.nix
Normal file
43
modules/nixos/utils/vm/default.nix
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
namespace,
|
||||||
|
puzzlelib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkIf mkMerge;
|
||||||
|
inherit (puzzlelib) mkOpt mkBool;
|
||||||
|
|
||||||
|
cfg = config.${namespace}.utils.vm;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.${namespace}.utils.vm = {
|
||||||
|
enable = mkBool true "Whether to enable custom vm presets";
|
||||||
|
preset = mkOpt lib.types.str "performance" "Specify the prefered vm settings preset: performance, balance or powersave";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
virtualisation.vmVariant = mkMerge [
|
||||||
|
(mkIf cfg.preset == "performance" {
|
||||||
|
virtualisation = {
|
||||||
|
cores = 6;
|
||||||
|
memorySize = 4096;
|
||||||
|
graphics = true;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(mkIf cfg.preset == "balance" {
|
||||||
|
virtualisation = {
|
||||||
|
cores = 4;
|
||||||
|
memorySize = 2048;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(mkIf cfg.preset == "powersave" {
|
||||||
|
virtualisation = {
|
||||||
|
cores = 2;
|
||||||
|
memorySize = 1024;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
|
@ -7,26 +7,18 @@
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
virtualisation.vmVariant = {
|
|
||||||
virtualisation = {
|
|
||||||
cores = 6;
|
|
||||||
memorySize = 2048;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# Todo: pass a set of users to enable from within easy-hosts and automatically map the corresponding home-manager configurations
|
|
||||||
# ${namespace} = {
|
|
||||||
# mainUser = "jo";
|
|
||||||
# users = [ "jo" ];
|
|
||||||
# };
|
|
||||||
users.users.jo.isNormalUser = true;
|
users.users.jo.isNormalUser = true;
|
||||||
users.users.jo.initialPassword = "balls";
|
users.users.jo.initialPassword = "balls";
|
||||||
users.users.jo.createHome = true;
|
users.users.jo.createHome = true;
|
||||||
|
|
||||||
# Enable Plasma6
|
# System configuration
|
||||||
services.xserver.enable = true;
|
puzzlevision = {
|
||||||
services.displayManager.sddm.enable = true;
|
# Todo: pass a set of users to enable from within easy-hosts and automatically map the corresponding home-manager configurations
|
||||||
services.desktopManager.plasma6.enable = true;
|
# mainUser = "jo";
|
||||||
|
# users = [ "jo" ];
|
||||||
|
|
||||||
|
desktop.gnome.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
ghostty
|
ghostty
|
||||||
|
|
Loading…
Add table
Reference in a new issue