fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1[[ch-contributing]] 2== Contributing 3 4: open-issues : https://github.com/nix-community/home-manager/issues 5: new-issue : https://github.com/nix-community/home-manager/issues/new 6: fork-a-repo : https://help.github.com/articles/fork-a-repo/ 7:create-a-pull-request: https://help.github.com/articles/creating-a-pull-request/ 8:seven-rules: https://chris.beams.io/posts/git-commit/#seven-rules 9: news-nix : https://github.com/nix-community/home-manager/blob/master/modules/misc/news.nix 10: nixfmt : https://github.com/serokell/nixfmt/ 11:example-commit-message: https://github.com/nix-community/home-manager/commit/69f8e47e9e74c8d3d060ca22e18246b7f7d988ef 12 13Contributions to Home Manager are very welcome. To make the process as smooth as possible for both you and the Home Manager maintainers we provide some guidelines that we ask you to follow. See <<sec-contrib-getting-started>> for information on how to set up a suitable development environment and <<sec-guidelines>> for the actual guidelines. 14 15This text is mainly directed at those who would like to make code contributions to Home Manager. If you just want to report a bug then first look among the already {open-issues}[open issues], if you find one matching yours then feel free to comment on it to add any additional information you may have. If no matching issue exists then go to the {new-issue}[new issue] page and write a description of your problem. Include as much information as you can, ideally also include relevant excerpts from your Home Manager configuration. 16 17[[sec-contrib-getting-started]] 18=== Getting started 19 20If you have not previously forked Home Manager then you need to do that first. Have a look at GitHub's {fork-a-repo}[Fork a repo] for instructions on how to do this. 21 22Once you have a fork of Home Manager you should create a branch starting at the most recent `master` branch. Give your branch a reasonably descriptive name. Commit your changes to this branch and when you are happy with the result and it fulfills <<sec-guidelines>> then push the branch to GitHub and {create-a-pull-request}[create a pull request]. 23 24Assuming your clone is at `$HOME/devel/home-manager` then you can make the `home-manager` command use it by either 25 261. overriding the default path by using the `-I` command line option: 27+ 28[ source,console ] 29$ home-manager -I home-manager=$HOME/devel/home-manager 30+ 31or, if using <<sec-flakes-standalone,flakes>>: 32+ 33[ source,console ] 34$ home-manager --override-input home-manager ~/devel/home-manager 35+ 36or 37 382. changing the default path by ensuring your configuration includes 39+ 40[ source,nix ] 41---- 42programs.home-manager.enable = true; 43programs.home-manager.path = "$HOME/devel/home-manager"; 44---- 45+ 46and running `home-manager switch` to activate the change. Afterwards, `home-manager build` and `home-manager switch` will use your cloned repository. 47 48The first option is good if you only temporarily want to use your clone. 49 50[[sec-guidelines]] 51=== Guidelines 52: irc-home-manager : https://webchat.oftc.net/?channels=home-manager 53: valuable-options : https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md#valuable-options 54: rfc-42 : https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md 55: assertions : https://nixos.org/manual/nixos/stable/index.html#sec-assertions 56 57If your contribution satisfy the following rules then there is a good chance it will be merged without too much trouble. The rules are enforced by the Home Manager maintainers and to a lesser extent the Home Manager CI system. 58 59If you are uncertain how these rules affect the change you would like to make then feel free to start a discussion in the {irc-home-manager}[#home-manager] IRC channel, ideally before you start developing. 60 61[[sec-guidelines-back-compat]] 62==== Maintain backward compatibility 63 64Your contribution should not cause another user's existing configuration to break unless there is a very good reason and the change should be announced to the user through an {assertions}[assertion] or similar. 65 66Remember that Home Manager is used in many different environments and you should consider how your change may effect others. For example, 67 68- Does your change work for people that do not use NixOS? Consider other GNU/Linux distributions and macOS. 69- Does your change work for people whose configuration is built on one system and deployed on another system? 70 71[[sec-guidelines-forward-compat]] 72==== Keep forward compatibility in mind 73 74The master branch of Home Manager tracks the unstable channel of Nixpkgs, which may update package versions at any time. It is therefore important to consider how a package update may affect your code and try to reduce the risk of breakage. 75 76The most effective way to reduce this risk is to follow the advice in <<sec-guidelines-valuable-options>>. 77 78[[sec-guidelines-valuable-options]] 79==== Add only valuable options 80 81When creating a new module it is tempting to include every option supported by the software. This is _strongly_ discouraged. Providing many options increases maintenance burden and risk of breakage considerably. This is why only the most {valuable-options}[important software options] should be modeled explicitly. Less important options should be expressible through an `extraConfig` escape hatch. 82 83A good rule of thumb for the first implementation of a module is to only add explicit options for those settings that absolutely must be set for the software to function correctly. It follows that a module for software that provides sensible default values for all settings would require no explicit options at all. 84 85If the software uses a structured configuration format like a JSON, YAML, INI, TOML, or even a plain list of key/value pairs then consider using a `settings` option as described in {rfc-42}[Nix RFC 42]. 86 87[[sec-guidelines-add-tests]] 88==== Add relevant tests 89 90If at all possible, make sure to add new tests and expand existing tests so that your change will keep working in the future. See <<sec-tests>> for more information about the Home Manager test suite. 91 92All contributed code _must_ pass the test suite. 93 94[[sec-guidelines-module-maintainer]] 95 96==== Add relevant documentation 97: nixpkgs-markdown : https://nixos.org/manual/nixpkgs/unstable/#sec-contributing-markup 98: docbook : https://tdg.docbook.org/ 99:asciidoc: https://asciidoc.org/ 100 101Many code changes require changing the documentation as well. Module options should be documented with {nixpkgs-markdown}[Nixpkgs-flavoured Markdown]. Home Manager is itself documented using a combination of {docbook}[DocBook] and {asciidoc}[AsciiDoc]. All text is hosted in Home Manager's Git repository. 102 103The HTML version of the manual containing both the module option descriptions and the documentation of Home Manager can be generated and opened by typing the following in a shell within a clone of the Home Manager Git repository: 104 105[ source,console ] 106$ nix-build -A docs.html 107$ xdg-open ./result/share/doc/home-manager/index.html 108 109When you have made changes to a module, it is a good idea to check that the man page version of the module options looks good: 110 111[ source,console ] 112$ nix-build -A docs.manPages 113$ man ./result/share/man/man5/home-configuration.nix.5.gz 114 115==== Add yourself as a module maintainer 116 117Every new module _must_ include a named maintainer using the `meta.maintainers` attribute. If you are a user of a module that currently lacks a maintainer then please consider adopting it. 118 119If you are present in the nixpkgs maintainer list then you can use that entry. If you are not then you can add yourself to `modules/lib/maintainers.nix` in the Home Manager project. 120 121Maintainers are encouraged to join the IRC or Matrix channel and participate when they have opportunity. 122 123[[sec-guidelines-code-style]] 124==== Format your code 125 126Make sure your code is formatted as described in <<sec-code-style>>. To maintain consistency throughout the project you are encouraged to browse through existing code and adopt its style also in new code. 127 128[[sec-guidelines-commit-message-style]] 129==== Format your commit messages 130 131Similar to <<sec-guidelines-code-style>> we encourage a consistent commit message format as described in <<sec-commit-style>>. 132 133[[sec-guidelines-news-style]] 134==== Format your news entries 135 136If your contribution includes a change that should be communicated to users of Home Manager then you can add a news entry. The entry must be formatted as described in <<sec-news>>. 137 138When new modules are added a news entry should be included but you do not need to create this entry manually. The merging maintainer will create the entry for you. This is to reduce the risk of merge conflicts. 139 140[[sec-guidelines-conditional-modules]] 141==== Use conditional modules and news 142 143Home Manager includes a number of modules that are only usable on some of the supported platforms. The most common example of platform specific modules are those that define systemd user services, which only works on Linux systems. 144 145If you add a module that is platform specific then make sure to include a condition in the `loadModule` function call. This will make the module accessible only on systems where the condition evaluates to `true`. 146 147Similarly, if you are adding a news entry then it should be shown only to users that may find it relevant, see <<sec-news>> for a description of conditional news. 148 149[[sec-guidelines-licensing]] 150==== Mind the license 151 152The Home Manager project is covered by the MIT license and we can only accept contributions that fall under this license, or are licensed in a compatible way. When you contribute self written code and documentation it is assumed that you are doing so under the MIT license. 153 154A potential gotcha with respect to licensing are option descriptions. Often it is convenient to copy from the upstream software documentation. When this is done it is important to verify that the license of the upstream documentation allows redistribution under the terms of the MIT license. 155 156[[sec-commit-style]] 157=== Commits 158 159The commits in your pull request should be reasonably self-contained, that is, each commit should make sense in isolation. In particular, you will be asked to amend any commit that introduces syntax errors or similar problems even if they are fixed in a later commit. 160 161The commit messages should follow the {seven-rules}[seven rules], except for "Capitalize the subject line". We also ask you to include the affected code component or module in the first line. That is, a commit message should follow the template 162 163---- 164{component}: {description} 165 166{long description} 167---- 168 169where `{component}` refers to the code component (or module) your change affects, `{description}` is a very brief description of your change, and `{long description}` is an optional clarifying description. As a rare exception, if there is no clear component, or your change affects many components, then the `{component}` part is optional. See <<ex-commit-message>> for a commit message that fulfills these requirements. 170 171[[ex-commit-message]] 172. Compliant commit message 173=============================================================================== 174The commit {example-commit-message}[69f8e47e9e74c8d3d060ca22e18246b7f7d988ef] contains the commit message 175 176---- 177starship: allow running in Emacs if vterm is used 178 179The vterm buffer is backed by libvterm and can handle Starship prompts 180without issues. 181---- 182 183which ticks all the boxes necessary to be accepted in Home Manager. 184=============================================================================== 185 186Finally, when adding a new module, say `programs/foo.nix`, we use the fixed commit format `foo: add module`. You can, of course, still include a long description if you wish. 187 188[[sec-code-style]] 189=== Code Style 190 191The code in Home Manager is formatted by the {nixfmt}[nixfmt] tool and the formatting is checked in the pull request tests. Run the `format` tool inside the project repository before submitting your pull request. 192 193Keep lines at a reasonable width, ideally 80 characters or less. This also applies to string literals. 194 195We prefer `lowerCamelCase` for variable and attribute names with the accepted exception of variables directly referencing packages in Nixpkgs which use a hyphenated style. For example, the Home Manager option `services.gpg-agent.enableSshSupport` references the `gpg-agent` package in Nixpkgs. 196 197[[sec-news]] 198=== News 199 200Home Manager includes a system for presenting news to the user. When making a change you, therefore, have the option to also include an associated news entry. In general, a news entry should only be added for truly noteworthy news. For example, a bug fix or new option does generally not need a news entry. 201 202If you do have a change worthy of a news entry then please add one in {news-nix}[`news.nix`] but you should follow some basic guidelines: 203 204- The entry timestamp should be in ISO-8601 format having "+00:00" as time zone. For example, "2017-09-13T17:10:14+00:00". A suitable timestamp can be produced by the command 205+ 206[ source,console ] 207$ date --iso-8601=second --universal 208 209- The entry condition should be as specific as possible. For example, if you are changing or deprecating a specific option then you could restrict the news to those users who actually use this option. 210 211- Wrap the news message so that it will fit in the typical terminal, that is, at most 80 characters wide. Ideally a bit less. 212 213- Unlike commit messages, news will be read without any connection to the Home Manager source code. It is therefore important to make the message understandable in isolation and to those who do not have knowledge of the Home Manager internals. To this end it should be written in more descriptive, prose like way. 214 215- If you refer to an option then write its full attribute path. That is, instead of writing 216+ 217---- 218The option 'foo' has been deprecated, please use 'bar' instead. 219---- 220+ 221it should read 222+ 223---- 224The option 'services.myservice.foo' has been deprecated, please 225use 'services.myservice.bar' instead. 226---- 227 228- A new module, say `foo.nix`, should always include a news entry that has a message along the lines of 229+ 230---- 231A new module is available: 'services.foo'. 232---- 233+ 234If the module is platform specific, e.g., a service module using systemd, then a condition like 235+ 236[ source,nix ] 237condition = hostPlatform.isLinux; 238+ 239should be added. If you contribute a module then you don't need to add this entry, the merger will create an entry for you. 240 241[[sec-tests]] 242=== Tests 243 244Home Manager includes a basic test suite and it is highly recommended to include at least one test when adding a module. Tests are typically in the form of "golden tests" where, for example, a generated configuration file is compared to a known correct file. 245 246It is relatively easy to create tests by modeling the existing tests, found in the `tests` project directory. For a full reference to the functions available in test scripts, you can look at NMT's https://git.sr.ht/~rycee/nmt/tree/master/item/bash-lib[bash-lib]. 247 248The full Home Manager test suite can be run by executing 249 250[ source,console ] 251$ nix-shell --pure tests -A run.all 252 253in the project root. List all test cases through 254 255[ source,console ] 256$ nix-shell --pure tests -A list 257 258and run an individual test, for example `alacritty-empty-settings`, through 259 260[ source,console ] 261$ nix-shell --pure tests -A run.alacritty-empty-settings 262 263However, those invocations will impurely source the system’s nixpkgs, and may cause failures. To run against the nixpkgs from the flake.lock, use instead e.g. 264 265[ source,console ] 266$ nix develop --ignore-environment .#all