From c322461fe1dcfa2ebd9f093ce2f42869c7d190a8 Mon Sep 17 00:00:00 2001 From: Jo Date: Thu, 23 Jan 2025 00:07:39 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20(modules/flake)=20implement=20r?= =?UTF-8?q?ecursively=20loaded=20libraries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 2 +- lib/module/default.nix | 16 ++++++++++ modules/flake/arguments.nix | 31 +++++++++++++++++++ systems/x86_64-nixos/puzzlevision/default.nix | 9 +++++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/module/default.nix diff --git a/flake.nix b/flake.nix index c6fc6b7..fb99f26 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,7 @@ }; }; - outputs = inputs@{ flake-parts, ... }: + outputs = { flake-parts, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { debug = true; diff --git a/lib/module/default.nix b/lib/module/default.nix new file mode 100644 index 0000000..3f58942 --- /dev/null +++ b/lib/module/default.nix @@ -0,0 +1,16 @@ +{ + lib, + ... +}: +{ + ## Create a NixOS module option as a one-liner. + ## + ## ```nix + ## lib.mkOpt nixpkgs.lib.types.str "My default" "Option description" + ## ``` + ## + #@ Type -> Any -> String + mkOpt = + type: default: description: + lib.mkOption { inherit type default description; }; +} diff --git a/modules/flake/arguments.nix b/modules/flake/arguments.nix index a7b2aa2..24e4a91 100644 --- a/modules/flake/arguments.nix +++ b/modules/flake/arguments.nix @@ -1,13 +1,44 @@ { + lib, inputs, config, ... }: +let + # Recursive function to load all `default.nix` files and merge them into a single attr. 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. _module.args = { namespace = config.flake.namespace; + ## 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. + puzzlelib = loadLibs ../../lib; + # Initialize nixpkgs instance with custom overlays. pkgs = import inputs.nixpkgs { overlays = [ diff --git a/systems/x86_64-nixos/puzzlevision/default.nix b/systems/x86_64-nixos/puzzlevision/default.nix index d0874c5..09a52fd 100644 --- a/systems/x86_64-nixos/puzzlevision/default.nix +++ b/systems/x86_64-nixos/puzzlevision/default.nix @@ -7,6 +7,13 @@ ./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"; @@ -18,7 +25,7 @@ # Enable Plasma6 services.xserver.enable = true; - services.displayManager.sddm.wayland.enable = true; + services.displayManager.sddm.enable = true; services.desktopManager.plasma6.enable = true; environment.systemPackages = with pkgs; [ From b559e046b76ebd27d156fa411b81931c5a332f55 Mon Sep 17 00:00:00 2001 From: Jo Date: Thu, 23 Jan 2025 00:09:01 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20(modules/flake)=20move=20com?= =?UTF-8?q?ment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/flake/arguments.nix | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/flake/arguments.nix b/modules/flake/arguments.nix index 24e4a91..5a2f886 100644 --- a/modules/flake/arguments.nix +++ b/modules/flake/arguments.nix @@ -5,7 +5,18 @@ ... }: let - # Recursive function to load all `default.nix` files and merge them into a single attr. set + ## 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 @@ -25,18 +36,7 @@ in _module.args = { namespace = config.flake.namespace; - ## 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. + puzzlelib = loadLibs ../../lib; # Initialize nixpkgs instance with custom overlays. From 7d16e19c8b91ab77774f10ea59f7f60db761cf59 Mon Sep 17 00:00:00 2001 From: Jo Date: Thu, 23 Jan 2025 00:09:29 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20(modules/flake)=20remove=20w?= =?UTF-8?q?hitespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/flake/arguments.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/flake/arguments.nix b/modules/flake/arguments.nix index 5a2f886..d335adf 100644 --- a/modules/flake/arguments.nix +++ b/modules/flake/arguments.nix @@ -36,7 +36,6 @@ in _module.args = { namespace = config.flake.namespace; - puzzlelib = loadLibs ../../lib; # Initialize nixpkgs instance with custom overlays.