Claude Code Plugins

Community-maintained marketplace

Feedback

nix-conditionals

@khaneliman/khanelinix
298
1

Nix conditional patterns: mkIf, optionals, optionalString, mkMerge. Use when writing conditional configuration, avoiding if-then-else, or combining multiple conditional blocks.

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

name nix-conditionals
description Nix conditional patterns: mkIf, optionals, optionalString, mkMerge. Use when writing conditional configuration, avoiding if-then-else, or combining multiple conditional blocks.

Conditional Patterns

Prefer lib Functions Over if-then-else

Need Use
Conditional config block lib.mkIf
Conditional list items lib.optionals
Conditional string lib.optionalString
Combine conditionals lib.mkMerge

mkIf - Conditional Config Blocks

config = lib.mkIf cfg.enable {
  programs.git.enable = true;
  home.packages = [ pkgs.git ];
};

# Nested conditional
programs.vim = lib.mkIf cfg.enableVim {
  enable = true;
};

optionals - Conditional List Items

home.packages = [
  pkgs.coreutils
] ++ lib.optionals cfg.enableTools [
  pkgs.ripgrep
  pkgs.fd
] ++ lib.optionals pkgs.stdenv.isLinux [
  pkgs.linuxTool
];

optionalString - Conditional Strings

programs.bash.initExtra = '''
  # Always included
  export EDITOR=vim
''' + lib.optionalString cfg.enableAliases '''
  alias ll='ls -la'
''';

mkMerge - Combine Conditional Blocks

config = lib.mkMerge [
  # Always applied
  {
    programs.bash.enable = true;
  }

  # Conditionally applied
  (lib.mkIf cfg.enableGit {
    programs.git.enable = true;
  })

  (lib.mkIf cfg.enableVim {
    programs.vim.enable = true;
  })
];

When if-then-else is OK

Only use when lib functions make it too complicated:

# OK - simple value selection
theme = if isDark then "dark" else "light";

# Prefer mkIf for config blocks