🚧 Initial work on generating homeConfigurations output + syntax changes

This commit is contained in:
Jo 2025-03-25 23:46:13 +01:00
parent f139b88c0b
commit f89cbcc552
12 changed files with 131 additions and 106 deletions
flake.lockflake.nix
lib/module
modules
systems/x86_64-nixos/puzzlevision

28
flake.lock generated
View file

@ -2,15 +2,15 @@
"nodes": {
"easy-hosts": {
"locked": {
"lastModified": 1736680851,
"narHash": "sha256-KUkO4H0W+1u5piwAzIzCuVhamQ0L3io8vR61NrODtHs=",
"owner": "isabelroses",
"lastModified": 1739315072,
"narHash": "sha256-m0Lzdrj95GbdmKhqlTKkr4vvHy2Ghdi1GxISOKqUeSA=",
"owner": "tgirlcloud",
"repo": "easy-hosts",
"rev": "450d2ae463bb8fb55194f33073ebdd83b8b7ddaa",
"rev": "e96af44cae1f48a1a94f2471faee92caf22aa45f",
"type": "github"
},
"original": {
"owner": "isabelroses",
"owner": "tgirlcloud",
"repo": "easy-hosts",
"type": "github"
}
@ -22,11 +22,11 @@
]
},
"locked": {
"lastModified": 1736143030,
"narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=",
"lastModified": 1741352980,
"narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de",
"rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9",
"type": "github"
},
"original": {
@ -42,11 +42,11 @@
]
},
"locked": {
"lastModified": 1736785676,
"narHash": "sha256-TY0jUwR3EW0fnS0X5wXMAVy6h4Z7Y6a3m+Yq++C9AyE=",
"lastModified": 1742305478,
"narHash": "sha256-iYCinzZnnUeCkZ031qGRwPdwRsqW6o9Y0MgGpA7Zva4=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "fc52a210b60f2f52c74eac41a8647c1573d2071d",
"rev": "fb74bb76d94a6c55632376c931fc108131260ee9",
"type": "github"
},
"original": {
@ -57,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1736701207,
"narHash": "sha256-jG/+MvjVY7SlTakzZ2fJ5dC3V1PrKKrUEOEE30jrOKA=",
"lastModified": 1742069588,
"narHash": "sha256-C7jVfohcGzdZRF6DO+ybyG/sqpo1h6bZi9T56sxLy+k=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ed4a395ea001367c1f13d34b1e01aa10290f67d6",
"rev": "c80f6a7e10b39afcc1894e02ef785b1ad0b0d7e5",
"type": "github"
},
"original": {

View file

@ -1,9 +1,23 @@
{
description = "Jo's dotfiles";
nixConfig = {
experimental-features = [
"flakes"
"nix-command"
];
extra-substituters = [
"https://nix-community.cachix.org"
];
extra-trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
easy-hosts.url = "github:isabelroses/easy-hosts";
easy-hosts.url = "github:tgirlcloud/easy-hosts";
flake-parts = {
url = "github:hercules-ci/flake-parts";
@ -16,15 +30,15 @@
};
};
outputs = { flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
outputs = {flake-parts, ...} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
debug = true;
imports = [
./modules/flake
];
systems = [ "x86_64-linux" ];
systems = ["x86_64-linux"];
flake = {
# Exposing the flake namespace
namespace = "puzzlevision";

View file

@ -1,16 +1,13 @@
{
lib,
...
}:
{
{lib, ...}: {
# Create a NixOS module option on a single line.
mkOpt =
type: default: description:
lib.mkOption { inherit type default description; };
mkOpt = type: default: description:
lib.mkOption {inherit type default description;};
mkBool =
default: description:
lib.mkOption { inherit default description; type = lib.types.bool; };
mkBool = default: description:
lib.mkOption {
inherit default description;
type = lib.types.bool;
};
# Todo: add mkIfElse function
}

View file

@ -1,8 +1,4 @@
{
config,
...
}:
{
{config, ...}: {
# Apply some useful module arguments.
_module.args = {
namespace = config.flake.namespace;

View file

@ -11,5 +11,8 @@
# Automagically imports systems from "/systems/arch-classname/system-name".
./systems.nix
# Automagically imports homes from "/homes/user-name".
./homes.nix
];
}

22
modules/flake/homes.nix Normal file
View file

@ -0,0 +1,22 @@
{
lib,
inputs,
puzzlelib,
...
}: let
HomeConfiguration = args: let
nixpkgs = inputs.nixpkgs;
in
inputs.home-manager.lib.homeManagerConfiguration {
modules = (puzzlelib.dirToModuleList ../home) ++ args.modules;
extraSpecialArgs =
{
inherit (args) nixpkgs;
}
// args.extraSpecialArgs;
};
in {
perSystem = {
# TODO Dynamically export homeConfigurations by consuming contents of /homes/user-name
};
}

View file

@ -2,53 +2,49 @@
lib,
puzzlelib,
...
}:
let
}: 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
{};
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
[];
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:
dirToModuleList = directory: let
readDir = readDirectory directory;
in
builtins.foldl' (
acc: name:
acc ++ (filesystemEntityToList directory name (builtins.getAttr name readDir))
) [] (builtins.attrNames 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.
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
{
) {} (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; };
puzzlelib = dirToAttrSet ../../lib {inherit lib puzzlelib;} // {inherit dirToAttrSet dirToModuleList filesystemEntityToList filesystemEntityToAttrSet;};
};
}

View file

@ -4,9 +4,8 @@
namespace,
puzzlelib,
...
}:
{
imports = [ inputs.easy-hosts.flakeModule ];
}: {
imports = [inputs.easy-hosts.flakeModule];
easyHosts = {
autoConstruct = true;
@ -19,11 +18,11 @@
};
perClass = class: {
modules = [
modules =
(lib.optionals (class == "nixos") [
inputs.home-manager.nixosModules.default
])
] ++ (puzzlelib.dirToModuleList ../${class}); # Import modules based on current classname.
++ (puzzlelib.dirToModuleList ../${class}); # Import modules based on current classname.
};
};
}

View file

@ -0,0 +1,2 @@
{}: {
}

View file

@ -3,13 +3,11 @@
config,
namespace,
...
}:
let
}: let
inherit (lib) mkEnableOption mkIf;
cfg = config.${namespace}.desktop.gnome;
in
{
options.${namespace}.desktop.gnome = { enable = mkEnableOption "Enable the gnome desktop environment ${namespace}"; };
in {
options.${namespace}.desktop.gnome = {enable = mkEnableOption "Enable the gnome desktop environment ${namespace}";};
config = mkIf cfg.enable {
services.xserver.enable = true;

View file

@ -4,14 +4,12 @@
namespace,
puzzlelib,
...
}:
let
}: let
inherit (lib) mkIf mkMerge;
inherit (puzzlelib) mkOpt mkBool;
cfg = config.${namespace}.utils.vm;
in
{
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";
@ -19,25 +17,28 @@ in
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;
};
})
(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;
};
})
];
};
}

View file

@ -1,8 +1,4 @@
{
pkgs,
...
}:
{
{pkgs, ...}: {
imports = [
./hardware.nix
];
@ -14,7 +10,6 @@
# System configuration
puzzlevision = {
# Todo: pass a set of users to enable from within easy-hosts and automatically map the corresponding home-manager configurations
# mainUser = "jo";
# users = [ "jo" ];
desktop.gnome.enable = true;
@ -22,6 +17,8 @@
environment.systemPackages = with pkgs; [
ghostty
firefox
vscodium
];
system.stateVersion = "25.05";