This repository has no description
0

Configure Feed

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

superconfig / wrapperModules / flake-module.nix
5.1 kB 153 lines
1{ self, lib, ... }: 2{ 3 imports = [ 4 ./mpv/default.nix 5 ./notmuch/default.nix 6 ]; 7 flake.options.wrapperModules = lib.mkOption { 8 type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); 9 default = { }; 10 description = "Wrapper modules"; 11 }; 12 /** 13 A function to create a wrapper module. 14 returns an attribute set with options and apply function. 15 16 Example usage: 17 helloWrapper = mkWrapper (wlib: { config, ... }: { 18 options.greeting = lib.mkOption { 19 type = lib.types.str; 20 default = "hello"; 21 }; 22 config.package = config.pkgs.hello; 23 config.flags = { 24 "--greeting" = config.greeting; 25 }; 26 }; 27 28 helloWrapper.apply { 29 pkgs = pkgs; 30 greeting = "hi"; 31 }; 32 33 # This will return a derivation that wraps the hello package with the --greeting flag set to "hi". 34 */ 35 flake.config.wrapLib.mkWrapper = 36 declarationArgs: 37 let 38 declaration = declarationArgs wrapperLib; 39 40 wrapperLib = { 41 types = { 42 inherit file; 43 }; 44 }; 45 file = 46 # we need to pass pkgs here, because writeText is in pkgs 47 pkgs: 48 lib.types.submodule ( 49 { name, config, ... }: 50 { 51 options = { 52 content = lib.mkOption { 53 type = lib.types.lines; 54 description = '' 55 content of file 56 ''; 57 }; 58 path = lib.mkOption { 59 type = lib.types.path; 60 description = '' 61 the path to the file 62 ''; 63 default = pkgs.writeText name config.content; 64 defaultText = "pkgs.writeText name <content>"; 65 }; 66 }; 67 } 68 ); 69 evalArgs = cfg: { 70 modules = [ 71 declaration 72 cfg 73 { 74 options = { 75 pkgs = lib.mkOption { 76 description = '' 77 The nixpkgs pkgs instance to use. 78 We want to have this, so wrapper modules can be system agnostic. 79 ''; 80 }; 81 package = lib.mkOption { 82 type = lib.types.package; 83 description = '' 84 The base package to wrap. 85 This means we inherit all other files from this package 86 (like man page, /share, ...) 87 ''; 88 }; 89 extraPackages = lib.mkOption { 90 type = lib.types.listOf lib.types.package; 91 default = [ ]; 92 description = '' 93 Additional packages to add to the wrapper's runtime dependencies. 94 This is useful if the wrapped program needs additional libraries or tools to function correctly. 95 These packages will be added to the wrapper's runtime dependencies, ensuring they are available when the wrapped program is executed. 96 ''; 97 }; 98 flags = lib.mkOption { 99 type = lib.types.attrsOf lib.types.unspecified; # TODO add list handling 100 default = { }; 101 description = '' 102 Flags to pass to the wrapper. 103 The key is the flag name, the value is the flag value. 104 If the value is true, the flag will be passed without a value. 105 If the value is false or null, the flag will not be passed. 106 If the value is a list, the flag will be passed multiple times with each value. 107 ''; 108 }; 109 env = lib.mkOption { 110 type = lib.types.attrsOf lib.types.str; 111 default = { }; 112 description = '' 113 Environment variables to set in the wrapper. 114 ''; 115 }; 116 passthru = lib.mkOption { 117 type = lib.types.attrs; 118 default = { }; 119 description = '' 120 Additional attributes to add to the resulting derivation's passthru. 121 This can be used to add additional metadata or functionality to the wrapped package. 122 This will always contain options, config and settings, so these are reserved names and cannot be used here. 123 ''; 124 }; 125 }; 126 } 127 ]; 128 }; 129 in 130 { 131 # expose options to generate documentation of available modules 132 options = (lib.evalModules (evalArgs { })).options; 133 apply = 134 settings: 135 let 136 eval = lib.evalModules (evalArgs { 137 config = settings; 138 }); 139 options = eval.options; 140 config = eval.config; 141 in 142 self.libWithPkgs.${config.pkgs.system}.makeWrapper config.package { 143 runtimeInputs = config.extraPackages; 144 flagSeparator = "="; 145 flags = config.flags; 146 env = config.env; 147 passthru = { 148 inherit options config settings; 149 } 150 // config.passthru; 151 }; 152 }; 153}