145 lines
4.0 KiB
Nix
145 lines
4.0 KiB
Nix
# 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
|
|
};
|
|
}
|