first
This commit is contained in:
144
templates/home-manager-module/default.nix
Normal file
144
templates/home-manager-module/default.nix
Normal file
@@ -0,0 +1,144 @@
|
||||
# Home Manager Module Template
|
||||
# This is a template for creating new Home Manager modules in m3ta-nixpkgs
|
||||
# Copy this template and modify it for your specific module
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.programs.myProgram; # Replace 'myProgram' with your program/module name
|
||||
# Common locations: config.programs.*, config.services.*, config.m3ta.*
|
||||
in {
|
||||
# Define options that users can set in their Home Manager configuration
|
||||
options.programs.myProgram = {
|
||||
enable = mkEnableOption "my custom program"; # Replace with your program description
|
||||
|
||||
# Example: Package option
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.hello; # Replace with your package
|
||||
defaultText = literalExpression "pkgs.hello";
|
||||
description = "The package to use";
|
||||
};
|
||||
|
||||
# Example: String option
|
||||
configDir = mkOption {
|
||||
type = types.str;
|
||||
default = "${config.xdg.configHome}/myprogram";
|
||||
defaultText = literalExpression ''"''${config.xdg.configHome}/myprogram"'';
|
||||
description = "Directory to store configuration";
|
||||
};
|
||||
|
||||
# Example: Boolean option
|
||||
enableBashIntegration = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Whether to enable Bash integration";
|
||||
};
|
||||
|
||||
# Example: Attribute set for settings
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = literalExpression ''
|
||||
{
|
||||
theme = "dark";
|
||||
fontSize = 12;
|
||||
}
|
||||
'';
|
||||
description = "Configuration settings written to config file";
|
||||
};
|
||||
|
||||
# Example: Lines of text (for config files)
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
# Custom configuration
|
||||
option = value
|
||||
'';
|
||||
description = "Extra configuration to append to the config file";
|
||||
};
|
||||
|
||||
# Example: Environment variables
|
||||
environmentVariables = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
default = {};
|
||||
example = {MY_VAR = "value";};
|
||||
description = "Environment variables to set";
|
||||
};
|
||||
};
|
||||
|
||||
# Define what happens when the module is enabled
|
||||
config = mkIf cfg.enable {
|
||||
# Add package to user profile
|
||||
home.packages = [cfg.package];
|
||||
|
||||
# Set environment variables
|
||||
home.sessionVariables = cfg.environmentVariables;
|
||||
|
||||
# Create configuration file
|
||||
# Method 1: Using xdg.configFile
|
||||
xdg.configFile."myprogram/config.conf" = {
|
||||
text = ''
|
||||
# Generated by Home Manager
|
||||
${builtins.toJSON cfg.settings}
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
# Method 2: Using home.file for non-XDG locations
|
||||
# home.file.".myprogramrc".text = ''
|
||||
# # Configuration here
|
||||
# '';
|
||||
|
||||
# Example: Bash integration
|
||||
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
|
||||
# My program bash integration
|
||||
eval "$(${cfg.package}/bin/myprogram init bash)"
|
||||
'';
|
||||
|
||||
# Example: Zsh integration
|
||||
programs.zsh.initExtra = mkIf cfg.enableBashIntegration ''
|
||||
# My program zsh integration
|
||||
eval "$(${cfg.package}/bin/myprogram init zsh)"
|
||||
'';
|
||||
|
||||
# Example: Fish integration
|
||||
# programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
||||
# ${cfg.package}/bin/myprogram init fish | source
|
||||
# '';
|
||||
|
||||
# Example: Systemd user service
|
||||
systemd.user.services.myprogram = {
|
||||
Unit = {
|
||||
Description = "My Program Service";
|
||||
After = ["graphical-session.target"];
|
||||
};
|
||||
|
||||
Service = {
|
||||
Type = "simple";
|
||||
ExecStart = "${cfg.package}/bin/myprogram daemon";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = ["default.target"];
|
||||
};
|
||||
};
|
||||
|
||||
# Example: Create directories
|
||||
# home.file."${cfg.configDir}/.keep".text = "";
|
||||
|
||||
# Example: Manage symlinks
|
||||
# home.file."bin/myprogram".source = "${cfg.package}/bin/myprogram";
|
||||
};
|
||||
|
||||
# Module metadata (optional)
|
||||
meta = {
|
||||
maintainers = with lib.maintainers; []; # Add your name if in nixpkgs
|
||||
};
|
||||
}
|
136
templates/nixos-module/default.nix
Normal file
136
templates/nixos-module/default.nix
Normal file
@@ -0,0 +1,136 @@
|
||||
# NixOS Module Template
|
||||
# This is a template for creating new NixOS modules in m3ta-nixpkgs
|
||||
# Copy this template and modify it for your specific module
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.m3ta.myModule; # Replace 'myModule' with your module name
|
||||
in {
|
||||
# Define options that users can set in their configuration
|
||||
options.m3ta.myModule = {
|
||||
enable = mkEnableOption "my custom module"; # Replace with your module description
|
||||
|
||||
# Example: String option
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.hello; # Replace with your default package
|
||||
defaultText = literalExpression "pkgs.hello";
|
||||
description = "The package to use for this module";
|
||||
};
|
||||
|
||||
# Example: String option
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/mymodule";
|
||||
description = "Directory where data will be stored";
|
||||
};
|
||||
|
||||
# Example: Port number
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 8080;
|
||||
description = "Port to listen on";
|
||||
};
|
||||
|
||||
# Example: String option
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "mymodule";
|
||||
description = "User account under which the service runs";
|
||||
};
|
||||
|
||||
# Example: Group option
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "mymodule";
|
||||
description = "Group under which the service runs";
|
||||
};
|
||||
|
||||
# Example: Boolean option
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether to open the firewall for the service port";
|
||||
};
|
||||
|
||||
# Example: List of strings
|
||||
extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
example = ["--verbose" "--debug"];
|
||||
description = "Additional command-line arguments to pass";
|
||||
};
|
||||
|
||||
# Example: Attribute set (key-value pairs)
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = literalExpression ''
|
||||
{
|
||||
logLevel = "info";
|
||||
timeout = 30;
|
||||
}
|
||||
'';
|
||||
description = "Configuration settings as attribute set";
|
||||
};
|
||||
};
|
||||
|
||||
# Define what happens when the module is enabled
|
||||
config = mkIf cfg.enable {
|
||||
# Create a system user
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
createHome = true;
|
||||
description = "My module service user";
|
||||
};
|
||||
|
||||
users.groups.${cfg.group} = {};
|
||||
|
||||
# Define a systemd service
|
||||
systemd.services.mymodule = {
|
||||
description = "My Custom Module Service";
|
||||
wantedBy = ["multi-user.target"];
|
||||
after = ["network.target"];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
WorkingDirectory = cfg.dataDir;
|
||||
ExecStart = "${cfg.package}/bin/myprogram ${concatStringsSep " " cfg.extraArgs}";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
|
||||
# Security hardening
|
||||
PrivateTmp = true;
|
||||
NoNewPrivileges = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
ReadWritePaths = [cfg.dataDir];
|
||||
};
|
||||
};
|
||||
|
||||
# Open firewall if requested
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [cfg.port];
|
||||
};
|
||||
|
||||
# Add package to system packages (optional)
|
||||
environment.systemPackages = [cfg.package];
|
||||
|
||||
# Example: Create configuration file
|
||||
# environment.etc."mymodule/config.json".text = builtins.toJSON cfg.settings;
|
||||
};
|
||||
|
||||
# Module metadata
|
||||
meta = {
|
||||
maintainers = with lib.maintainers; []; # Add your name if in nixpkgs
|
||||
doc = ./default.md; # Optional: Link to documentation
|
||||
};
|
||||
}
|
85
templates/package/default.nix
Normal file
85
templates/package/default.nix
Normal file
@@ -0,0 +1,85 @@
|
||||
# Package Template
|
||||
# This is a template for creating new packages in m3ta-nixpkgs
|
||||
# Copy this template and modify it for your specific package
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
fetchFromGitHub,
|
||||
# Add build dependencies here
|
||||
# pkg-config,
|
||||
# cmake,
|
||||
# rustPlatform,
|
||||
# python3,
|
||||
# nodejs,
|
||||
# Add runtime dependencies here
|
||||
# openssl,
|
||||
# libxml2,
|
||||
}:
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "package-name"; # Replace with your package name
|
||||
version = "0.1.0"; # Replace with actual version
|
||||
|
||||
# Source fetching - choose one method:
|
||||
|
||||
# Method 1: From GitHub
|
||||
src = fetchFromGitHub {
|
||||
owner = "owner-name";
|
||||
repo = "repo-name";
|
||||
rev = "v${version}"; # or use a specific commit hash
|
||||
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||
# To get the correct hash, first set it to lib.fakeHash, then run:
|
||||
# nix build .#package-name
|
||||
# The error message will show the correct hash
|
||||
};
|
||||
|
||||
# Method 2: From URL
|
||||
# src = fetchurl {
|
||||
# url = "https://example.com/package-${version}.tar.gz";
|
||||
# hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||
# };
|
||||
|
||||
# Build-time dependencies (tools needed to build the package)
|
||||
nativeBuildInputs = [
|
||||
# pkg-config
|
||||
# cmake
|
||||
# makeWrapper
|
||||
];
|
||||
|
||||
# Runtime dependencies (libraries needed at runtime)
|
||||
buildInputs = [
|
||||
# openssl
|
||||
# libxml2
|
||||
];
|
||||
|
||||
# Build phase (optional, only if you need custom build steps)
|
||||
# buildPhase = ''
|
||||
# make
|
||||
# '';
|
||||
|
||||
# Install phase (optional, only if you need custom install steps)
|
||||
# installPhase = ''
|
||||
# mkdir -p $out/bin
|
||||
# cp binary $out/bin/
|
||||
# '';
|
||||
|
||||
# Post-install hook (optional, for wrapping binaries, etc.)
|
||||
# postInstall = ''
|
||||
# wrapProgram $out/bin/program \
|
||||
# --prefix PATH : ${lib.makeBinPath [ dependency ]}
|
||||
# '';
|
||||
|
||||
# Metadata - REQUIRED
|
||||
meta = with lib; {
|
||||
description = "A short description of the package";
|
||||
longDescription = ''
|
||||
A longer, more detailed description of what the package does.
|
||||
This can span multiple lines.
|
||||
'';
|
||||
homepage = "https://github.com/owner/repo";
|
||||
changelog = "https://github.com/owner/repo/releases/tag/v${version}";
|
||||
license = licenses.mit; # Change to appropriate license
|
||||
maintainers = with maintainers; []; # Add your name if you're in nixpkgs
|
||||
platforms = platforms.linux; # or platforms.unix, platforms.all, etc.
|
||||
mainProgram = "program-name"; # The main executable name
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user