mirror of
https://github.com/Jokiller230/puzzlevision.git
synced 2025-09-10 04:40:05 +00:00
✨ finalize home configuration loading as nixos module, and more stuffs :3
This commit is contained in:
parent
f89cbcc552
commit
dc87b2c186
16 changed files with 192 additions and 87 deletions
|
@ -52,6 +52,7 @@ Parts of this flake were inspired by the likes of:
|
||||||
|
|
||||||
- [isabelroses](https://github.com/isabelroses)
|
- [isabelroses](https://github.com/isabelroses)
|
||||||
- [uncenter](https://github.com/uncenter)
|
- [uncenter](https://github.com/uncenter)
|
||||||
|
- [xaiyadev](https://github.com/xaiyadev)
|
||||||
|
|
||||||
and documentations such as:
|
and documentations such as:
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"nix-command"
|
"nix-command"
|
||||||
];
|
];
|
||||||
extra-substituters = [
|
extra-substituters = [
|
||||||
|
"https://cache.nixos.org"
|
||||||
"https://nix-community.cachix.org"
|
"https://nix-community.cachix.org"
|
||||||
];
|
];
|
||||||
extra-trusted-public-keys = [
|
extra-trusted-public-keys = [
|
||||||
|
|
3
homes/nixos/jo/default.nix
Normal file
3
homes/nixos/jo/default.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{ ... }: {
|
||||||
|
home.stateVersion = "25.05";
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
{lib, ...}: {
|
{ lib, self, ... }: {
|
||||||
# Create a NixOS module option on a single line.
|
# Create a NixOS module option on a single line.
|
||||||
mkOpt = type: default: description:
|
mkOpt = type: default: description:
|
||||||
lib.mkOption {inherit type default description;};
|
lib.mkOption {inherit type default description;};
|
||||||
|
@ -9,5 +9,21 @@
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Todo: add mkIfElse function
|
# Create a module compliant with the NixOS module system.
|
||||||
|
mkModule =
|
||||||
|
{
|
||||||
|
name ? "puzzlevision",
|
||||||
|
class,
|
||||||
|
modules,
|
||||||
|
}: {
|
||||||
|
_class = class;
|
||||||
|
|
||||||
|
# Template: "[path-to-flake]/flake.nix#[class-name]Modules.[module-name]"
|
||||||
|
# Example: "[path-to-flake]/flake.nix#nixosModules.system.audio"
|
||||||
|
_file = "${self.outPath}/flake.nix#${class}Modules.${name}";
|
||||||
|
|
||||||
|
imports = modules;
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: add mkIfElse function
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
{config, ...}: {
|
|
||||||
# Apply some useful module arguments.
|
|
||||||
_module.args = {
|
|
||||||
namespace = config.flake.namespace;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,18 +1,18 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
# Applies some useful arguments, like namespace, to all flake modules.
|
# Exposes nixosModules and homeModules on flake outputs.
|
||||||
./arguments.nix
|
./modules.nix
|
||||||
|
|
||||||
# Automagically imports libs from "/lib/lib-name" and applies them to the `lib.${namespace}` or `puzzlevision.lib` module argument.
|
# Automagically imports libs from "/lib/lib-name" and exposes them to the `flake.lib` output.
|
||||||
./lib.nix
|
./lib.nix
|
||||||
|
|
||||||
# Recursively imports overlays from "/overlays/overlay-name" and applies them to the `pkgs` or `puzzlevision.pkgs` module argument.
|
# Recursively imports overlays from "/overlays/overlay-name" and exposes them to the `flake.overlays` output.
|
||||||
# ./overlays.nix
|
#./overlays.nix
|
||||||
|
|
||||||
# Automagically imports systems from "/systems/arch-classname/system-name".
|
# Automagically imports systems from "/systems/arch-classname/system-name".
|
||||||
./systems.nix
|
./systems.nix
|
||||||
|
|
||||||
# Automagically imports homes from "/homes/user-name".
|
# Automagically imports homes from "/homes/user-name".
|
||||||
./homes.nix
|
#./homes.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
puzzlelib,
|
self,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
# Utility function to read a directory and return its contents.
|
# Utility function to read a directory and return its contents.
|
||||||
|
@ -41,10 +41,9 @@
|
||||||
# Files return attribute sets with their resulting expressions, directories return the result of multiple file handling operations.
|
# 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))
|
acc // (filesystemEntityToAttrSet directory importArgs name (builtins.getAttr name readDir))
|
||||||
) {} (builtins.attrNames readDir);
|
) {} (builtins.attrNames readDir);
|
||||||
|
|
||||||
|
puzzlelib = dirToAttrSet ../../lib {inherit lib self;} // {inherit dirToAttrSet dirToModuleList filesystemEntityToList filesystemEntityToAttrSet;};
|
||||||
in {
|
in {
|
||||||
# Add lib.${namespace} attribute to module arguments, for easy access.
|
# Expose custom library on flake "lib" output
|
||||||
# Additionally, pass on dirToAttrSet method on lib.${namespace} for reusability in other modules.
|
flake.lib = puzzlelib;
|
||||||
_module.args = {
|
|
||||||
puzzlelib = dirToAttrSet ../../lib {inherit lib puzzlelib;} // {inherit dirToAttrSet dirToModuleList filesystemEntityToList filesystemEntityToAttrSet;};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
14
modules/flake/modules.nix
Normal file
14
modules/flake/modules.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{ self, ... }:
|
||||||
|
{
|
||||||
|
flake = {
|
||||||
|
nixosModules.puzzlevision = self.lib.mkModule {
|
||||||
|
class = "nixos";
|
||||||
|
modules = self.lib.dirToModuleList ../nixos;
|
||||||
|
};
|
||||||
|
|
||||||
|
homeModules.puzzlevision = self.lib.mkModule {
|
||||||
|
class = "home";
|
||||||
|
modules = self.lib.dirToModuleList ../home;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,28 +1,21 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
inputs,
|
inputs,
|
||||||
namespace,
|
self,
|
||||||
puzzlelib,
|
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
imports = [inputs.easy-hosts.flakeModule];
|
imports = [ inputs.easy-hosts.flakeModule ];
|
||||||
|
|
||||||
easyHosts = {
|
easyHosts = {
|
||||||
autoConstruct = true;
|
autoConstruct = true;
|
||||||
path = ../../systems;
|
path = ../../systems;
|
||||||
|
|
||||||
shared = {
|
|
||||||
specialArgs = {
|
|
||||||
inherit namespace puzzlelib;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
perClass = class: {
|
perClass = class: {
|
||||||
modules =
|
modules =
|
||||||
(lib.optionals (class == "nixos") [
|
(lib.optionals (class == "nixos") [
|
||||||
inputs.home-manager.nixosModules.default
|
inputs.home-manager.nixosModules.default
|
||||||
])
|
])
|
||||||
++ (puzzlelib.dirToModuleList ../${class}); # Import modules based on current classname.
|
++ (self.lib.dirToModuleList ../${class}); # Import modules based on current classname.
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
{}: {
|
|
||||||
}
|
|
33
modules/home/desktop/gnome/default.nix
Normal file
33
modules/home/desktop/gnome/default.nix
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
self,
|
||||||
|
config,
|
||||||
|
osConfig,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib) mkIf mkOption;
|
||||||
|
inherit (self) namespace;
|
||||||
|
|
||||||
|
cfg = config.${namespace}.desktop.gnome;
|
||||||
|
in {
|
||||||
|
options.${namespace}.desktop.gnome = with lib.types; {
|
||||||
|
enabled-extensions = mkOption {
|
||||||
|
type = listOf package;
|
||||||
|
default = with pkgs.gnomeExtensions; [dash-to-dock user-themes blur-my-shell appindicator unite color-picker clipboard-history];
|
||||||
|
example = [dash-to-dock blur-my-shell];
|
||||||
|
description = "Specify gnome extensions to install.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf osConfig.${namespace}.desktop.gnome.enable {
|
||||||
|
home.packages = cfg.enabled-extensions;
|
||||||
|
|
||||||
|
dconf.settings = {
|
||||||
|
"org/gnome/shell" = {
|
||||||
|
enabled-extensions = lib.forEach cfg.enabled-extensions (x: x.extensionUuid);
|
||||||
|
disabled-extensions = []; # Make sure none of our extensions are disabled on system rebuild
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
namespace,
|
self,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkEnableOption mkIf;
|
inherit (lib) mkEnableOption mkIf;
|
||||||
|
inherit (self) namespace;
|
||||||
|
|
||||||
cfg = config.${namespace}.desktop.gnome;
|
cfg = config.${namespace}.desktop.gnome;
|
||||||
in {
|
in {
|
||||||
options.${namespace}.desktop.gnome = {enable = mkEnableOption "Enable the gnome desktop environment ${namespace}";};
|
options.${namespace}.desktop.gnome = {enable = mkEnableOption "Enable the gnome desktop environment ${namespace}";};
|
||||||
|
|
86
modules/nixos/users/default.nix
Normal file
86
modules/nixos/users/default.nix
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib) mkEnableOption mkIf mkOption types;
|
||||||
|
inherit (self) namespace;
|
||||||
|
inherit (self.lib) mkOpt dirToModuleList;
|
||||||
|
|
||||||
|
cfg = config.${namespace}.users;
|
||||||
|
|
||||||
|
system = builtins.currentSystem;
|
||||||
|
systemClass =
|
||||||
|
if builtins.match ".*-linux" system != null then "nixos"
|
||||||
|
else if builtins.match ".*-darwin" system != null then "darwin"
|
||||||
|
else "nixos"; # Default fallback
|
||||||
|
|
||||||
|
# Type for a user configuration
|
||||||
|
userType = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "Enable this user";
|
||||||
|
initialPassword = mkOpt (types.nullOr types.str) null "Initial password for the user";
|
||||||
|
hashedPassword = mkOpt (types.nullOr types.str) null "Hashed password for the user";
|
||||||
|
isNormalUser = mkOpt types.bool true "Whether this user is a normal user";
|
||||||
|
extraGroups = mkOpt (types.listOf types.str) [] "Extra groups for the user";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Function to get home configuration path for a username
|
||||||
|
getHomeConfigPath = username: "${self.outPath}/homes/${systemClass}/${username}";
|
||||||
|
|
||||||
|
# Function to check if a home configuration exists for a username
|
||||||
|
homeConfigExists = username:
|
||||||
|
let path = getHomeConfigPath username;
|
||||||
|
in builtins.pathExists "${path}/default.nix";
|
||||||
|
|
||||||
|
# Import all home-manager modules
|
||||||
|
homeModules = dirToModuleList "${self.outPath}/modules/home";
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
# Import home-manager NixOS module
|
||||||
|
# This assumes home-manager is available as a flake input
|
||||||
|
self.inputs.home-manager.nixosModules.home-manager
|
||||||
|
];
|
||||||
|
|
||||||
|
options.${namespace}.users = mkOption {
|
||||||
|
type = types.attrsOf userType;
|
||||||
|
default = {};
|
||||||
|
description = "User configurations with auto-imported home-manager setup";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
# Create the actual users
|
||||||
|
users.users = lib.mapAttrs (username: userConfig:
|
||||||
|
mkIf userConfig.enable {
|
||||||
|
name = username;
|
||||||
|
isNormalUser = userConfig.isNormalUser;
|
||||||
|
inherit (userConfig) extraGroups;
|
||||||
|
initialPassword = userConfig.initialPassword;
|
||||||
|
hashedPassword = userConfig.hashedPassword;
|
||||||
|
}
|
||||||
|
) cfg;
|
||||||
|
|
||||||
|
# Configure home-manager with auto-imported configs
|
||||||
|
home-manager = {
|
||||||
|
useGlobalPkgs = true;
|
||||||
|
useUserPackages = true;
|
||||||
|
|
||||||
|
extraSpecialArgs = {
|
||||||
|
inherit self;
|
||||||
|
namespace = self.namespace;
|
||||||
|
};
|
||||||
|
|
||||||
|
users = lib.mapAttrs (username: userConfig:
|
||||||
|
mkIf (userConfig.enable && homeConfigExists username) (
|
||||||
|
{ ... }: {
|
||||||
|
imports = [
|
||||||
|
(getHomeConfigPath username) # Import the user's specific home configuration
|
||||||
|
] ++ homeModules; # Include all home modules from /modules/home
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) cfg;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,44 +1,26 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
namespace,
|
self,
|
||||||
puzzlelib,
|
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkIf mkMerge;
|
inherit (lib) mkIf;
|
||||||
inherit (puzzlelib) mkOpt mkBool;
|
inherit (self) namespace;
|
||||||
|
|
||||||
cfg = config.${namespace}.utils.vm;
|
cfg = config.${namespace}.utils.vm;
|
||||||
in {
|
in {
|
||||||
options.${namespace}.utils.vm = {
|
options.${namespace}.utils.vm = {
|
||||||
enable = mkBool true "Whether to enable custom vm presets";
|
enable = self.lib.mkBool true "Whether to enable custom vm presets";
|
||||||
preset = mkOpt lib.types.str "performance" "Specify the prefered vm settings preset: performance, balance or powersave";
|
preset = self.lib.mkOpt lib.types.str "performance" "Specify the prefered vm settings preset: performance, balance or powersave";
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
virtualisation.vmVariant = mkMerge [
|
virtualisation.vmVariant = {
|
||||||
(mkIf cfg.preset
|
virtualisation = {
|
||||||
== "performance" {
|
cores = 6;
|
||||||
virtualisation = {
|
memorySize = 4096;
|
||||||
cores = 6;
|
graphics = true;
|
||||||
memorySize = 4096;
|
};
|
||||||
graphics = true;
|
};
|
||||||
};
|
|
||||||
})
|
|
||||||
(mkIf cfg.preset
|
|
||||||
== "balance" {
|
|
||||||
virtualisation = {
|
|
||||||
cores = 4;
|
|
||||||
memorySize = 2048;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(mkIf cfg.preset
|
|
||||||
== "powersave" {
|
|
||||||
virtualisation = {
|
|
||||||
cores = 2;
|
|
||||||
memorySize = 1024;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,13 @@
|
||||||
|
|
||||||
# System configuration
|
# System configuration
|
||||||
puzzlevision = {
|
puzzlevision = {
|
||||||
# Todo: pass a set of users to enable from within easy-hosts and automatically map the corresponding home-manager configurations
|
# TODO: improve home-manager configuration loading as development continues and make sure everything works correctly.
|
||||||
# users = [ "jo" ];
|
users = {
|
||||||
|
jo = {
|
||||||
|
enable = true;
|
||||||
|
initialPassword = "balls";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
desktop.gnome.enable = true;
|
desktop.gnome.enable = true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue