From d47f242103528ac54963163107dfc834c8a009f2 Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 8 Dec 2024 11:12:00 -0500 Subject: [PATCH] General: turn templates into actual templates --- flake.nix | 12 +++++++----- lib/default.nix | 1 + .../module/default.nix | 17 +++++++++++------ .../systems/default.nix | 9 ++------- .../systems/hardware-configuration.nix | 3 +-- 5 files changed, 22 insertions(+), 20 deletions(-) rename modules/nixos/module.nix.template => templates/module/default.nix (74%) rename systems/default.nix.template => templates/systems/default.nix (85%) rename systems/hardware-configuration.nix.template => templates/systems/hardware-configuration.nix (98%) diff --git a/flake.nix b/flake.nix index 6ceabdf..efe9f64 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,7 @@ }; in lib.mkFlake { - # Configure Nix channels + # Allow unfree packages in Nix config channels-config.allowUnfree = true; # Define systems @@ -103,10 +103,6 @@ # Individual host configurations hosts = { - Dimaga.modules = with inputs; [ - nixos-hardware.nixosModules.common-cpu-intel - ]; - Hevana.modules = with inputs; [ nixos-hardware.nixosModules.common-cpu-amd-pstate nixos-hardware.nixosModules.common-gpu-amd @@ -126,6 +122,12 @@ }; }; + # Define .nix file templates + templates = { + module.description = "Template for creating a new module."; + systems.description = "Template for defining a new system."; + }; + # Use treefmt to format project repo outputs-builder = channels: diff --git a/lib/default.nix b/lib/default.nix index 5659da8..eee1619 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,3 +1,4 @@ +# Extra utility functions { lib, }: diff --git a/modules/nixos/module.nix.template b/templates/module/default.nix similarity index 74% rename from modules/nixos/module.nix.template rename to templates/module/default.nix index 196573e..918696d 100644 --- a/modules/nixos/module.nix.template +++ b/templates/module/default.nix @@ -1,5 +1,10 @@ # This is an example of a blank module. -{ config, lib, ... }: +{ + config, + lib, + namespace, + ... +}: let cfg = config.${namespace}.services.myModule; @@ -23,9 +28,9 @@ in type = lib.types.listOf lib.types.int; description = "An example of a list (of integers) option."; }; - enum = mkOption { + enum = lib.mkOption { default = "one"; - type = types.enum [ + type = lib.types.enum [ "one" "two" ]; @@ -36,14 +41,14 @@ in }; config = lib.mkIf cfg.enable { - # Add changes applied by this module here. + # Define the changes applied by this module here. }; systemd.services = { - # Forces systemd to wait for the module's configuration directory to be available before starting the service. + # Tell systemd to wait for the module's configuration directory to be available before starting the service. myModule.unitConfig.RequiresMountsFor = cfg.home; - # Tells Nginx to wait for the service to be available before coming online. + # Tell Nginx to wait for the service to be available before coming online. nginx.wants = [ config.systemd.services.myModule.name ]; }; } diff --git a/systems/default.nix.template b/templates/systems/default.nix similarity index 85% rename from systems/default.nix.template rename to templates/systems/default.nix index 84933f7..80fb025 100644 --- a/systems/default.nix.template +++ b/templates/systems/default.nix @@ -1,16 +1,11 @@ # Template file for configuring a new host { - pkgs, - home-manager, - lib, - config, namespace, ... }: let # Do not change this value! This tracks when NixOS was installed on your system. stateVersion = "24.11"; - # The hostname for this system. hostName = "myHost"; in @@ -22,7 +17,7 @@ in system.stateVersion = stateVersion; networking.hostName = hostName; - # Configure the system here. + # Main system configuration happens here. config.${namespace} = { apps = { # Define applications here @@ -39,5 +34,5 @@ in }; }; - # Additional host-specific configuration options go here + # Additional configuration options go here } diff --git a/systems/hardware-configuration.nix.template b/templates/systems/hardware-configuration.nix similarity index 98% rename from systems/hardware-configuration.nix.template rename to templates/systems/hardware-configuration.nix index b57548f..9c08451 100644 --- a/systems/hardware-configuration.nix.template +++ b/templates/systems/hardware-configuration.nix @@ -1,8 +1,7 @@ # Template for setting a new host's hardware configuration { - config, - lib, modulesPath, + namespace, ... }: let