at master 5.0 kB view raw
1{ 2 lib, 3 systemdUtils, 4 pkgs, 5}: 6 7let 8 inherit (systemdUtils.lib) 9 automountConfig 10 makeUnit 11 mountConfig 12 pathConfig 13 sliceConfig 14 socketConfig 15 stage1ServiceConfig 16 stage2ServiceConfig 17 targetConfig 18 timerConfig 19 unitConfig 20 ; 21 22 inherit (systemdUtils.unitOptions) 23 concreteUnitOptions 24 stage1AutomountOptions 25 stage1CommonUnitOptions 26 stage1MountOptions 27 stage1PathOptions 28 stage1ServiceOptions 29 stage1SliceOptions 30 stage1SocketOptions 31 stage1TimerOptions 32 stage2AutomountOptions 33 stage2CommonUnitOptions 34 stage2MountOptions 35 stage2PathOptions 36 stage2ServiceOptions 37 stage2SliceOptions 38 stage2SocketOptions 39 stage2TimerOptions 40 ; 41 42 inherit (lib) 43 mkDefault 44 mkDerivedConfig 45 mkEnableOption 46 mkIf 47 mkOption 48 ; 49 50 inherit (lib.types) 51 attrsOf 52 coercedTo 53 enum 54 lines 55 listOf 56 nullOr 57 oneOf 58 package 59 path 60 singleLineStr 61 submodule 62 ; 63 64 initrdStorePathModule = 65 { config, ... }: 66 { 67 options = { 68 enable = (mkEnableOption "copying of this file and symlinking it") // { 69 default = true; 70 }; 71 72 target = mkOption { 73 type = nullOr path; 74 description = '' 75 Path of the symlink. 76 ''; 77 default = null; 78 }; 79 80 source = mkOption { 81 type = path; 82 description = "Path of the source file."; 83 }; 84 85 dlopen = { 86 usePriority = mkOption { 87 type = enum [ 88 "required" 89 "recommended" 90 "suggested" 91 ]; 92 default = "recommended"; 93 description = '' 94 Priority of dlopen ELF notes to include. "required" is 95 minimal, "recommended" includes "required", and 96 "suggested" includes "recommended". 97 98 See: <https://systemd.io/ELF_DLOPEN_METADATA/> 99 ''; 100 }; 101 102 features = mkOption { 103 type = listOf singleLineStr; 104 default = [ ]; 105 description = '' 106 Features to enable via dlopen ELF notes. These will be in 107 addition to anything included via 'usePriority', 108 regardless of their priority. 109 ''; 110 }; 111 }; 112 }; 113 }; 114 115in 116 117{ 118 units = attrsOf ( 119 submodule ( 120 { name, config, ... }: 121 { 122 options = concreteUnitOptions; 123 config = { 124 name = mkDefault name; 125 unit = mkDefault (makeUnit name config); 126 }; 127 } 128 ) 129 ); 130 131 services = attrsOf (submodule [ 132 stage2ServiceOptions 133 unitConfig 134 stage2ServiceConfig 135 ]); 136 initrdServices = attrsOf (submodule [ 137 stage1ServiceOptions 138 unitConfig 139 stage1ServiceConfig 140 ]); 141 142 targets = attrsOf (submodule [ 143 stage2CommonUnitOptions 144 unitConfig 145 targetConfig 146 ]); 147 initrdTargets = attrsOf (submodule [ 148 stage1CommonUnitOptions 149 unitConfig 150 targetConfig 151 ]); 152 153 sockets = attrsOf (submodule [ 154 stage2SocketOptions 155 unitConfig 156 socketConfig 157 ]); 158 initrdSockets = attrsOf (submodule [ 159 stage1SocketOptions 160 unitConfig 161 socketConfig 162 ]); 163 164 timers = attrsOf (submodule [ 165 stage2TimerOptions 166 unitConfig 167 timerConfig 168 ]); 169 initrdTimers = attrsOf (submodule [ 170 stage1TimerOptions 171 unitConfig 172 timerConfig 173 ]); 174 175 paths = attrsOf (submodule [ 176 stage2PathOptions 177 unitConfig 178 pathConfig 179 ]); 180 initrdPaths = attrsOf (submodule [ 181 stage1PathOptions 182 unitConfig 183 pathConfig 184 ]); 185 186 slices = attrsOf (submodule [ 187 stage2SliceOptions 188 unitConfig 189 sliceConfig 190 ]); 191 initrdSlices = attrsOf (submodule [ 192 stage1SliceOptions 193 unitConfig 194 sliceConfig 195 ]); 196 197 mounts = listOf (submodule [ 198 stage2MountOptions 199 unitConfig 200 mountConfig 201 ]); 202 initrdMounts = listOf (submodule [ 203 stage1MountOptions 204 unitConfig 205 mountConfig 206 ]); 207 208 automounts = listOf (submodule [ 209 stage2AutomountOptions 210 unitConfig 211 automountConfig 212 ]); 213 initrdAutomounts = attrsOf (submodule [ 214 stage1AutomountOptions 215 unitConfig 216 automountConfig 217 ]); 218 219 initrdStorePath = listOf ( 220 coercedTo (oneOf [ 221 singleLineStr 222 package 223 ]) (source: { inherit source; }) (submodule initrdStorePathModule) 224 ); 225 226 initrdContents = attrsOf ( 227 submodule ( 228 { 229 config, 230 options, 231 name, 232 ... 233 }: 234 { 235 imports = [ initrdStorePathModule ]; 236 options = { 237 text = mkOption { 238 default = null; 239 type = nullOr lines; 240 description = "Text of the file."; 241 }; 242 }; 243 244 config = { 245 target = mkDefault name; 246 source = mkIf (config.text != null) ( 247 let 248 name' = "initrd-" + baseNameOf name; 249 in 250 mkDerivedConfig options.text (pkgs.writeText name') 251 ); 252 }; 253 } 254 ) 255 ); 256}