This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

remove make-wrapper-module

-108
-108
lib/make-wrapper-module.nix
··· 1 - { 2 - lib, 3 - superlib, 4 - pkgs, 5 - }: 6 - let 7 - makeWrapper = (import ./make-wrapper.nix { inherit lib superlib pkgs; }).makeWrapper; 8 - in 9 - { 10 - /** 11 - Create a wrapper module that combines NixOS module evaluation with makeWrapper functionality. 12 - 13 - This function creates a reusable wrapper configuration that can be instantiated 14 - with different settings using the NixOS module system. 15 - 16 - # Arguments 17 - 18 - - `name`: String identifier for the wrapper module 19 - - `options`: Attribute set of `lib.mkOption` definitions for configurable settings 20 - - `module`: Function that receives the evaluated config and returns: 21 - - `package`: The base package to wrap (required) 22 - - All other makeWrapper parameters (wrapper, env, runtimeInputs, etc.) 23 - 24 - # Returns 25 - 26 - A function that takes settings and returns the wrapped package. 27 - 28 - # Example 29 - 30 - ```nix 31 - # Define the wrapper module 32 - muttWrapperModule = makeWrapperModule { 33 - name = "mutt"; 34 - options = { 35 - muttrc = lib.mkOption { 36 - type = lib.types.lines; 37 - default = ""; 38 - description = "Mutt configuration"; 39 - }; 40 - editor = lib.mkOption { 41 - type = lib.types.str; 42 - default = "vim"; 43 - description = "Editor to use for composing emails"; 44 - }; 45 - }; 46 - module = { config, pkgs, ... }: { 47 - package = pkgs.mutt; 48 - env = { 49 - EDITOR = config.editor; 50 - }; 51 - wrapper = { exePath, ... }: '' 52 - exec ${exePath} -F ${pkgs.writeText "muttrc" config.muttrc} "$@" 53 - ''; 54 - }; 55 - }; 56 - 57 - # Use with settings 58 - packages.mutt = muttWrapperModule { 59 - muttrc = '' 60 - set editor = "nvim" 61 - set sort = threads 62 - ''; 63 - editor = "nvim"; 64 - }; 65 - ``` 66 - */ 67 - makeWrapperModule = 68 - { 69 - name, 70 - options, 71 - module, 72 - }: 73 - # Return a function that takes settings 74 - settings: 75 - let 76 - # Evaluate the module with the provided settings 77 - evaluated = lib.evalModules { 78 - modules = [ 79 - # Base module with options 80 - { 81 - options = options; 82 - } 83 - # The wrapper module definition 84 - module 85 - # User settings 86 - { 87 - config = settings; 88 - } 89 - ]; 90 - # Provide standard module arguments 91 - specialArgs = { 92 - inherit pkgs lib; 93 - }; 94 - }; 95 - 96 - # Extract the evaluated config 97 - config = evaluated.config; 98 - 99 - # The module must provide a package 100 - package = 101 - config.package or (throw "makeWrapperModule '${name}': module must define a 'package' attribute"); 102 - 103 - # Extract makeWrapper parameters from config (excluding 'package') 104 - wrapperArgs = lib.filterAttrs (n: _v: n != "package") config; 105 - in 106 - # Call makeWrapper with the package and extracted arguments 107 - makeWrapper package wrapperArgs; 108 - }