populate.nix 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. { lib }: rec {
  2. source = lib.types.submodule ({ config, ... }: {
  3. options = {
  4. type = let
  5. known-types = lib.attrNames source-types;
  6. type-candidates = lib.filter (k: config.${k} != null) known-types;
  7. in lib.mkOption {
  8. default = if lib.length type-candidates == 1
  9. then lib.head type-candidates
  10. else throw "cannot determine type";
  11. type = lib.types.enum known-types;
  12. };
  13. derivation = lib.mkOption {
  14. apply = x:
  15. if lib.types.str.check x
  16. then { text = x; }
  17. else x;
  18. default = null;
  19. type = lib.types.nullOr (lib.types.either lib.types.str source-types.derivation);
  20. };
  21. file = lib.mkOption {
  22. apply = x:
  23. if lib.types.absolute-pathname.check x
  24. then { path = x; }
  25. else x;
  26. default = null;
  27. type = lib.types.nullOr (lib.types.either lib.types.absolute-pathname source-types.file);
  28. };
  29. git = lib.mkOption {
  30. default = null;
  31. type = lib.types.nullOr source-types.git;
  32. };
  33. pass = lib.mkOption {
  34. default = null;
  35. type = lib.types.nullOr source-types.pass;
  36. };
  37. pipe = lib.mkOption {
  38. apply = x:
  39. if lib.types.absolute-pathname.check x
  40. then { command = x; }
  41. else x;
  42. default = null;
  43. type = lib.types.nullOr (lib.types.either lib.types.absolute-pathname source-types.pipe);
  44. };
  45. symlink = lib.mkOption {
  46. apply = x:
  47. if lib.types.pathname.check x
  48. then { target = x; }
  49. else x;
  50. default = null;
  51. type = lib.types.nullOr (lib.types.either lib.types.pathname source-types.symlink);
  52. };
  53. };
  54. });
  55. filter = lib.types.submodule {
  56. options = {
  57. type = lib.mkOption {
  58. type = lib.types.enum ["include" "exclude"];
  59. default = "exclude";
  60. };
  61. pattern = lib.mkOption {
  62. type = lib.types.str;
  63. };
  64. };
  65. };
  66. source-types = {
  67. derivation = lib.types.submodule {
  68. options = {
  69. text = lib.mkOption {
  70. type = lib.types.str;
  71. };
  72. };
  73. };
  74. file = lib.types.submodule {
  75. options = {
  76. path = lib.mkOption {
  77. type = lib.types.absolute-pathname;
  78. };
  79. useChecksum = lib.mkOption {
  80. default = false;
  81. type = lib.types.bool;
  82. };
  83. exclude = lib.mkOption {
  84. apply = x:
  85. if x != [] then
  86. lib.warn
  87. "file.*.exclude is deprecated in favor of file.*.filters"
  88. x
  89. else
  90. x;
  91. description = ''
  92. DEPRECATED, use `filters`.
  93. '';
  94. type = lib.types.listOf lib.types.str;
  95. default = [];
  96. example = [".git"];
  97. };
  98. filters = lib.mkOption {
  99. type = lib.types.listOf filter;
  100. default = [];
  101. example = [
  102. {
  103. type = "include";
  104. pattern = "*.nix";
  105. }
  106. {
  107. type = "include";
  108. pattern = "*/";
  109. }
  110. {
  111. type = "exclude";
  112. pattern = "*";
  113. }
  114. ];
  115. };
  116. deleteExcluded = lib.mkOption {
  117. default = true;
  118. type = lib.types.bool;
  119. };
  120. };
  121. };
  122. git = lib.types.submodule {
  123. options = {
  124. clean = {
  125. exclude = lib.mkOption {
  126. default = [];
  127. type = lib.types.listOf lib.types.str;
  128. };
  129. };
  130. fetchAlways = lib.mkOption {
  131. type = lib.types.bool;
  132. default = false;
  133. };
  134. ref = lib.mkOption {
  135. type = lib.types.str; # TODO lib.types.git.ref
  136. };
  137. url = lib.mkOption {
  138. type = lib.types.str; # TODO lib.types.git.url
  139. };
  140. shallow = lib.mkOption {
  141. default = false;
  142. type = lib.types.bool;
  143. };
  144. };
  145. };
  146. pass = lib.types.submodule {
  147. options = {
  148. dir = lib.mkOption {
  149. type = lib.types.absolute-pathname;
  150. };
  151. name = lib.mkOption {
  152. type = lib.types.pathname; # TODO relative-pathname
  153. };
  154. };
  155. };
  156. pipe = lib.types.submodule {
  157. options = {
  158. command = lib.mkOption {
  159. type = lib.types.absolute-pathname;
  160. };
  161. };
  162. };
  163. symlink = lib.types.submodule {
  164. options = {
  165. target = lib.mkOption {
  166. type = lib.types.pathname; # TODO relative-pathname
  167. };
  168. };
  169. };
  170. };
  171. }