Merge pull request #152372 from symphorien/systemd-validate-after

nixos/systemd: validate the values of systemd.services.<name>.after

authored by

Guillaume Girol and committed by
GitHub
d6f45aa6 27d57625

+15 -12
+3
nixos/lib/systemd-lib.nix
··· 11 11 12 12 mkPathSafeName = lib.replaceChars ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""]; 13 13 14 + # a type for options that take a unit name 15 + unitNameType = types.strMatching "[a-zA-Z0-9@%:_.\\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)"; 16 + 14 17 makeUnit = name: unit: 15 18 if unit.enable then 16 19 pkgs.runCommand "unit-${mkPathSafeName name}"
+12 -12
nixos/lib/systemd-unit-options.nix
··· 45 45 46 46 requiredBy = mkOption { 47 47 default = []; 48 - type = types.listOf types.str; 48 + type = types.listOf unitNameType; 49 49 description = '' 50 50 Units that require (i.e. depend on and need to go down with) 51 51 this unit. The discussion under <literal>wantedBy</literal> ··· 56 56 57 57 wantedBy = mkOption { 58 58 default = []; 59 - type = types.listOf types.str; 59 + type = types.listOf unitNameType; 60 60 description = '' 61 61 Units that want (i.e. depend on) this unit. The standard way 62 62 to make a unit start by default at boot is to set this option ··· 73 73 74 74 aliases = mkOption { 75 75 default = []; 76 - type = types.listOf types.str; 76 + type = types.listOf unitNameType; 77 77 description = "Aliases of that unit."; 78 78 }; 79 79 ··· 110 110 111 111 requires = mkOption { 112 112 default = []; 113 - type = types.listOf types.str; 113 + type = types.listOf unitNameType; 114 114 description = '' 115 115 Start the specified units when this unit is started, and stop 116 116 this unit when the specified units are stopped or fail. ··· 119 119 120 120 wants = mkOption { 121 121 default = []; 122 - type = types.listOf types.str; 122 + type = types.listOf unitNameType; 123 123 description = '' 124 124 Start the specified units when this unit is started. 125 125 ''; ··· 127 127 128 128 after = mkOption { 129 129 default = []; 130 - type = types.listOf types.str; 130 + type = types.listOf unitNameType; 131 131 description = '' 132 132 If the specified units are started at the same time as 133 133 this unit, delay this unit until they have started. ··· 136 136 137 137 before = mkOption { 138 138 default = []; 139 - type = types.listOf types.str; 139 + type = types.listOf unitNameType; 140 140 description = '' 141 141 If the specified units are started at the same time as 142 142 this unit, delay them until this unit has started. ··· 145 145 146 146 bindsTo = mkOption { 147 147 default = []; 148 - type = types.listOf types.str; 148 + type = types.listOf unitNameType; 149 149 description = '' 150 150 Like ‘requires’, but in addition, if the specified units 151 151 unexpectedly disappear, this unit will be stopped as well. ··· 154 154 155 155 partOf = mkOption { 156 156 default = []; 157 - type = types.listOf types.str; 157 + type = types.listOf unitNameType; 158 158 description = '' 159 159 If the specified units are stopped or restarted, then this 160 160 unit is stopped or restarted as well. ··· 163 163 164 164 conflicts = mkOption { 165 165 default = []; 166 - type = types.listOf types.str; 166 + type = types.listOf unitNameType; 167 167 description = '' 168 168 If the specified units are started, then this unit is stopped 169 169 and vice versa. ··· 172 172 173 173 requisite = mkOption { 174 174 default = []; 175 - type = types.listOf types.str; 175 + type = types.listOf unitNameType; 176 176 description = '' 177 177 Similar to requires. However if the units listed are not started, 178 178 they will not be started and the transaction will fail. ··· 203 203 204 204 onFailure = mkOption { 205 205 default = []; 206 - type = types.listOf types.str; 206 + type = types.listOf unitNameType; 207 207 description = '' 208 208 A list of one or more units that are activated when 209 209 this unit enters the "failed" state.