|
| 1 | +--- |
| 2 | +feature: Decouple filesystem from categorization |
| 3 | +start-date: 2023-04-23 |
| 4 | +author: Anderson Torres |
| 5 | +co-authors: (find a buddy later to help out with the RFC) |
| 6 | +shepherd-team: (names, to be nominated and accepted by RFC steering committee) |
| 7 | +shepherd-leader: (name to be appointed by RFC steering committee) |
| 8 | +related-issues: (will contain links to implementation PRs) |
| 9 | +--- |
| 10 | + |
| 11 | +# Summary |
| 12 | +[summary]: #summary |
| 13 | + |
| 14 | +Deploy a new method of categorization for the packages maintained by Nixpkgs, |
| 15 | +not relying on filesystem idiosyncrasies. |
| 16 | + |
| 17 | +# Motivation |
| 18 | +[motivation]: #motivation |
| 19 | + |
| 20 | +Currently, Nixpkgs uses the filesystem, or more accurately, the directory tree |
| 21 | +layout in order to informally categorize the softwares it packages, as described |
| 22 | +in the [Hierarchy](https://nixos.org/manual/nixpkgs/stable/#sec-hierarchy) |
| 23 | +section of Nixpkgs manual. |
| 24 | + |
| 25 | +This is a simple, easy to understand and consecrated-by-use method of |
| 26 | +categorization, partially employed by many other package managers like GNU Guix |
| 27 | +and NetBSD pkgsrc. |
| 28 | + |
| 29 | +However this system of categorization has serious problems: |
| 30 | + |
| 31 | +1. It is bounded by the constraints imposed by the filesystem. |
| 32 | + |
| 33 | + - Restrictions on filenames, subdirectory tree depth, permissions, inodes, |
| 34 | + quotas, and many other things. |
| 35 | + - Some of these restrictions are not well documented and are found simply |
| 36 | + by "bumping" on them. |
| 37 | + - The restrictions can vary on an implementation basis. |
| 38 | + - Some filesystems have more restrictions or less features than others, |
| 39 | + forcing an uncomfortable lowest common denominator. |
| 40 | + - Some operating systems can impose additional constraints over otherwise |
| 41 | + full-featured filesystems because of backwards compatibility (8 dot |
| 42 | + 3,anyone?). |
| 43 | + |
| 44 | +2. It requires a local checkout of the tree. |
| 45 | + |
| 46 | + Certainly this checkout can be "cached" using some form of `find . > |
| 47 | + /tmp/pkgs-listing.txt`, or more sophisticated solutions like `locate + |
| 48 | + updatedb`. Nonetheless such solutions still require access to a fresh, |
| 49 | + updated copy of the Nixpkgs tree. |
| 50 | + |
| 51 | +3. The creation of a new category - and more generally the manipulation of |
| 52 | + categories - requires an unpleaseant task of renaming and eventually patching |
| 53 | + many seemingly unrelated files. |
| 54 | + |
| 55 | + - Moving files around Nixpkgs codebase requires updating their forward and |
| 56 | + backward references. |
| 57 | + - Especially in some auxiliary tools like editor plugins, testing suites, |
| 58 | + autoupdate scripts and so on. |
| 59 | + - Rewriting `all-packages.nix` can be error-prone (even using Metapad) and it |
| 60 | + can generate huge, noisy patches. |
| 61 | + |
| 62 | +4. There is no convenient way to use multivalued categorization. |
| 63 | + |
| 64 | + A piece of software can fulfill many categories; e.g. |
| 65 | + - an educational game |
| 66 | + - a console emulator (vs. a PC emulator) |
| 67 | + - and a special-purpose programming language (say, a smart-contracts one). |
| 68 | + |
| 69 | + The current one-size-fits-all restriction is artificial, imposes unreasonable |
| 70 | + limitations and results in incomplete and confusing information. |
| 71 | + |
| 72 | + - No, symlinks or hardlinks are not convenient for this purpose; not all |
| 73 | + environments support them (falling on the "less features than others" |
| 74 | + problem expressed before) and they convey nothing besides confusion - just |
| 75 | + think about writing the corresponding entry in `all-packages.nix`. |
| 76 | + |
| 77 | +5. It puts over the (possibly human) package writer the mental load of where to |
| 78 | + put the files on the filesystem hierarchy, deviating them from the job of |
| 79 | + really writing them. |
| 80 | + |
| 81 | + - Or just taking the shortest path and throw it on a folder under `misc`. |
| 82 | + |
| 83 | +6. It "locks" the filesystem, preventing its usage for other, more sensible |
| 84 | + purposes. |
| 85 | + |
| 86 | +7. The most important: the categorization is not discoverable via Nix language |
| 87 | + infrastructure. |
| 88 | + |
| 89 | + Indeed there is no higher level way to query about such categories besides |
| 90 | + the one described in the bullet 2 above. |
| 91 | + |
| 92 | +In light of such a bunch of problems, this RFC proposes a novel alternative to |
| 93 | +the above mess: new `meta` attributes. |
| 94 | + |
| 95 | +# Detailed design |
| 96 | +[design]: #detailed-design |
| 97 | + |
| 98 | +A new attribute, `meta.categories`, will be included for every Nix expression |
| 99 | +living inside Nixpkgs. |
| 100 | + |
| 101 | +This attribute will be a list, whose elements are one of the possible elements |
| 102 | +of the `lib.categories` set. |
| 103 | + |
| 104 | +A typical snippet of `lib.categories` will be similar to: |
| 105 | + |
| 106 | +```nix |
| 107 | +{ |
| 108 | + assembler = { |
| 109 | + name = "Assembler"; |
| 110 | + description = '' |
| 111 | + A program that converts text written in assembly language to binary code. |
| 112 | + ''; |
| 113 | + }; |
| 114 | +
|
| 115 | + compiler = { |
| 116 | + name = "Compiler"; |
| 117 | + description = '' |
| 118 | + A program that converts a source from a language to another, usually from |
| 119 | + a higher, human-readable level to a lower, machine level. |
| 120 | + ''; |
| 121 | + }; |
| 122 | +
|
| 123 | + font = { |
| 124 | + name = "Font"; |
| 125 | + description = '' |
| 126 | + A set of files that defines a set of graphically-related glyphs. |
| 127 | + ''; |
| 128 | + }; |
| 129 | +
|
| 130 | + game = { |
| 131 | + name = "Game"; |
| 132 | + description = '' |
| 133 | + A program developed with entertainment in mind. |
| 134 | + ''; |
| 135 | + }; |
| 136 | +
|
| 137 | + interpreter = { |
| 138 | + name = "Interpreter"; |
| 139 | + description = '' |
| 140 | + A program that directly executes instructions written in a programming |
| 141 | + language, without requiring compilation into the native machine language. |
| 142 | + ''; |
| 143 | + }; |
| 144 | +
|
| 145 | +``` |
| 146 | + |
| 147 | +# Examples and Interactions |
| 148 | +[examples-and-interactions]: #examples-and-interactions |
| 149 | + |
| 150 | +In file bochs/default.nix: |
| 151 | + |
| 152 | +```nix |
| 153 | +stdenv.mkDerivation { |
| 154 | +
|
| 155 | +. . . |
| 156 | +
|
| 157 | + meta = { |
| 158 | + . . . |
| 159 | + categories = with lib.categories; [ emulator debugger ]; |
| 160 | + . . . |
| 161 | + }; |
| 162 | + }; |
| 163 | +} |
| 164 | +
|
| 165 | +``` |
| 166 | + |
| 167 | +# Drawbacks |
| 168 | +[drawbacks]: #drawbacks |
| 169 | + |
| 170 | +The most immediate drawbacks are: |
| 171 | + |
| 172 | +1. A huge treewide edit of Nixpkgs |
| 173 | + |
| 174 | + On the other hand, this is easily sprintable and amenable to automation. |
| 175 | + |
| 176 | +2. Bikeshedding |
| 177 | + |
| 178 | + How many and which categories we should create? Can we expand them later? |
| 179 | + |
| 180 | +# Alternatives |
| 181 | +[alternatives]: #alternatives |
| 182 | + |
| 183 | +1. Do nothing |
| 184 | + |
| 185 | +2. Ignore/nuke the categorization completely |
| 186 | + |
| 187 | + This is not an idea as bad as it appear. After all, categorization has a |
| 188 | + non-negligible propensity to bikeshedding. Removing it removes all problems. |
| 189 | + |
| 190 | + Nonetheless, other good software collections do this just fine, and we can |
| 191 | + easily imitate them. Indeed, we can follow/take a peek at how Repology keeps |
| 192 | + the categorizations defined by those software collections. |
| 193 | + |
| 194 | +# Unresolved questions |
| 195 | +[unresolved]: #unresolved-questions |
| 196 | + |
| 197 | +Still unsolved is what data structure is better suited to represent a category. |
| 198 | + |
| 199 | +# Future work |
| 200 | +[future]: #future-work |
| 201 | + |
| 202 | +- Curation of categories. |
| 203 | +- Update documentation. |
| 204 | + |
0 commit comments