This manual will eventually describe how to install, use, and extend Project Manager.
If you encounter problems then please reach out on the Project Manager Matrix room. If your problem is caused by a bug in Project Manager then it should be reported on the Project Manager issue tracker.
Commands prefixed with $ sudo
have to be run as root, either
requiring to login as root user or temporarily switching to it using
sudo
for example.
Project Manager can be used in three primary ways:
project-manager
tool.
In this chapter we describe how to install Project Manager in the standard way using channels. If you prefer to use Nix Flakes then please see the instructions in Chapter 3, Nix Flakes.
nix-instantiate '<nixpkgs>' -A hello
without having to switch to the
root user. For a multi-user install of Nix this means that your user
must be covered by the allowed-users
Nix
option. On NixOS you can control this option using the
nix.settings.allowed-users
system option.
Add the appropriate Project Manager channel. If you are following Nixpkgs master or an unstable channel you can run
$ nix-channel --add https://github.com/sellout/project-manager/archive/master.tar.gz project-manager $ nix-channel --update
and if you follow a Nixpkgs version 23.05 channel you can run
$ nix-channel --add https://github.com/sellout/project-manager/archive/release-23.05.tar.gz project-manager $ nix-channel --update
Run the Project Manager installation command and create the first Project Manager generation:
$ nix-shell '<project-manager>' -A install
Once finished, Project Manager should be active and available in your user environment.
If you don’t plan on having Project Manager manage your shell configuration then you must source the
$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
file in your shell configuration. Alternatively source
/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh
when managing home configuration together with system configuration.
This file can be sourced directly by POSIX.2-like shells such as Bash or Z shell. Fish users can use utilities such as foreign-env or babelfish.
For example, if you use Bash then add
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
to your ~/.profile
file.
Once installed you can see Chapter 2, Using Project Manager for a more detailed description of Project Manager and how to use it.
Your use of Project Manager is centered around the configuration file,
which is typically found at $PROJECT_ROOT/.config/project.nix
in the standard installation
or $PROJECT_ROOT/flake.nix
in a Nix flake based installation.
The default configuration used to be placed in ~/.config/nixpkgs
¸
so you may see references to that elsewhere.
The old directory still works but Project Manager will print a warning message when used.
This configuration file can be built and activated.
Building a configuration produces a directory in the Nix store that has all files and programs that should be available in your project directory and Nix project profile, respectively. The build step also checks that the configuration is valid and it will fail with an error if you, for example, assign a value to an option that doesn’t exist or assign a value of the wrong type. Some modules also have custom assertions that perform more detailed, module specific, checks.
Concretely, if your configuration has
programs.git.enable = "yes";
then building it, for example using project-manager build
, will result in an error message saying something like
$ project-manager build error: A definition for option `programs.git.enable' is not of type `boolean'. Definition values: - In `/.../.config/project.nix': "yes" (use '--show-trace' to show detailed location information)
The message indicates that you must give a Boolean value for this option, that is, either true
or false
. The documentation of each option will state the expected type, for programs.git.enable
you will see “Type: boolean”. You there also find information about the default value and a description of the option. You can find the complete option documentation in Appendix A, Configuration Options or directly in the terminal by running
man project-configuration.nix
Once a configuration is successfully built, it can be activated. The activation performs the steps necessary to make the files, programs, and services available in your user environment. The project-manager switch
command performs a combined build and activation.
A fresh install of Project Manager will generate a minimal $PROJECT_ROOT/.config/project.nix
file containing something like
{ config, pkgs, ... }: { # This value determines the Project Manager release that your # configuration is compatible with. This helps avoid breakage # when a new Project Manager release introduces backwards # incompatible changes. # # You can update Project Manager without changing this value. See # the Project Manager release notes for a list of state version # changes in each release. project.stateVersion = 0; # Let Project Manager install and manage itself. programs.project-manager.enable = true; }
You can use this as a base for your further configurations.
If you aren’t very familiar with the Nix language and NixOS modules then it’s encouraged to start with small and simple changes. As you learn you can gradually grow the configuration with confidence.
As an example, let us expand the initial configuration file to also install the ‘htop’ and ‘fortune’ packages, install Emacs with a few extra packages available, and enable the user ‘gpg-agent’ service.
To satisfy the above setup we should elaborate the project.nix
file as follows:
{ config, pkgs, ... }: { # Packages that should be installed to the project profile. project.devPackages = [ pkgs.htop pkgs.fortune ]; # This value determines the Project Manager release that your # configuration is compatible with. This helps avoid breakage # when a new Project Manager release introduces backwards # incompatible changes. # # You can update Project Manager without changing this value. See # the Project Manager release notes for a list of state version # changes in each release. project.stateVersion = 0; # Let Project Manager install and manage itself. programs.project-manager.enable = true; programs.emacs = { enable = true; extraPackages = epkgs: [ epkgs.nix-mode epkgs.magit ]; }; services.gpg-agent = { enable = true; defaultCacheTtl = 1800; enableSshSupport = true; }; }
Nixpkgs packages can be installed to the development shell using | |
The option names of a program module typically start with | |
Similarly, for a service module, the names start with |
To activate this configuration you can run
project-manager switch
or if you aren’t feeling so lucky,
project-manager build
which will create a result
link to a directory containing an
activation script and the generated project directory files.
While the project-manager
tool doesn’t explicitly support rollbacks at the moment it’s relatively easy to perform one manually. The steps to do so are
Run project-manager generations
to determine which generation you wish to rollback to:
$ project-manager generations 2018-01-04 11:56 : id 765 -> /nix/store/kahm1rxk77mnvd2l8pfvd4jkkffk5ijk-project-manager-generation 2018-01-03 10:29 : id 764 -> /nix/store/2wsmsliqr5yynqkdyjzb1y57pr5q2lsj-project-manager-generation 2018-01-01 12:21 : id 763 -> /nix/store/mv960kl9chn2lal5q8lnqdp1ygxngcd1-project-manager-generation 2017-12-29 21:03 : id 762 -> /nix/store/6c0k1r03fxckql4vgqcn9ccb616ynb94-project-manager-generation 2017-12-25 18:51 : id 761 -> /nix/store/czc5y6vi1rvnkfv83cs3rn84jarcgsgh-project-manager-generation …
Copy the Nix store path of the generation you chose, for example,
/nix/store/mv960kl9chn2lal5q8lnqdp1ygxngcd1-project-manager-generation
for generation 763.
Run the activate
script inside the copied store path:
$ /nix/store/mv960kl9chn2lal5q8lnqdp1ygxngcd1-project-manager-generation/activate Starting project manager activation …
Project Manager is compatible with Nix Flakes. But please be aware that the support it’s still experimental and may change in backwards incompatible ways.
Just like in the standard installation you can use the Project Manager flake in three ways:
project-manager
tool. For platforms other than
NixOS and Darwin, this is the only available choice. it’s also
recommended for people on NixOS or Darwin that want to manage their
project directory independently of the system as a whole. See
Section 3.2, “Standalone setup” for instructions on how to perform this
installation.
nix-shell
.
Enable experimental features nix-command
and flakes
.
When using NixOS, add the following to your configuration.nix
and rebuild your system.
nix = { package = pkgs.nixFlakes; extraOptions = '' experimental-features = nix-command flakes ''; };
If you aren’t using NixOS, add the following to nix.conf
(located at ~/.config/nix/
or /etc/nix/nix.conf
).
experimental-features = nix-command flakes
You may need to restart the Nix daemon with, for example, sudo systemctl restart nix-daemon.service
.
You can also enable flakes on a per-command basis with the following extra flags to nix
and project-manager
:
$ nix --extra-experimental-features "nix-command flakes" <sub-commands> $ project-manager --extra-experimental-features "nix-command flakes" <sub-commands>
Prepare your Project Manager configuration (project.nix
).
Unlike the channel-based setup,
project.nix
will be evaluated when the flake is built,
so it must be present before bootstrap of Project Manager from the flake.
See Section 2.1, “Configuration Example” for introduction about
writing a Project Manager configuration.
To prepare an initial Project Manager configuration for your logged in user,
you can run the Project Manager init
command directly from its flake.
For example, if you are using the unstable version of Nixpkgs or NixOS, then to generate and activate a basic configuration run the command
$ nix run project-manager/master -- init --switch
For Nixpkgs or NixOS version 23.05 run
$ nix run project-manager/release-23.05 -- init --switch
This will generate a flake.nix
and a project.nix
file in
~/.config/project-manager
, creating the directory if it doesn’t exist.
If you omit the --switch
option then the activation won’t happen.
This is useful if you want to inspect and edit the configuration before activating it.
$ nix run project-manager/$branch -- init $ # Edit files in ~/.config/project-manager $ nix run project-manager/$branch -- init --switch
Where $branch
is one of master
or release-23.05
.
After the initial activation has completed successfully then building and activating your flake-based configuration is as simple as
$ project-manager switch
it’s possible to override the default configuration directory, if you want. For example,
$ nix run project-manager/$branch -- init --switch ~/hmconf $ # And after the initial activation. $ project-manager switch --flake ~/hmconf
The flake inputs aren’t automatically updated by Project Manager.
You need to use the standard nix flake update
command for that.
If you only want to update a single flake input,
then the command nix flake lock --update-input <input>
can be used.
You can also pass flake-related options
such as --recreate-lock-file
or --update-input <input>
to project-manager
when building or switching,
and these options will be forwarded to nix build
.
See the NixOS Wiki page for details.
The module system in Project Manager is based entirely on the NixOS module system so we will here only highlight aspects that are specific for Project Manager. For information about the module system as such please refer to the Writing NixOS Modules chapter of the NixOS manual.
Contributions to Project Manager are enthusiastically welcomed. To make the process as smooth as possible for both you and the Project Manager maintainers we provide some guidelines that we ask you to follow. See Section 5.1, “Getting started” for information on how to set up a suitable development environment and Section 5.2, “Guidelines” for the actual guidelines.
This text is mainly directed at those who would like to make code contributions to Project Manager. If you just want to report a bug then first look among the already 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 page and write a description of your problem. Include as much information as you can, ideally also include relevant excerpts from your Project Manager configuration.
If you haven’t forked Project Manager yet, then you need to do that first. Have a look at GitHub’s Fork a repo for instructions on how to do this.
Once you have a fork of Project 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 Section 5.2, “Guidelines” then push the branch to GitHub and create a pull request.
Assuming your clone is at $HOME/devel/project-manager
then you can make the project-manager
command use it by either
overriding the default path by using the -I
command line option:
$ project-manager -I project-manager=$HOME/devel/project-manager
or, if using flakes:
$ project-manager --override-input project-manager ~/devel/project-manager
or
changing the default path by ensuring your configuration includes
programs.project-manager.enable = true; programs.project-manager.path = "$HOME/devel/project-manager";
and running project-manager switch
to activate the change. Afterward, project-manager build
and project-manager switch
will use your cloned repository.
The first option is good if you only temporarily want to use your clone.
If 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 Project Manager maintainers and to a lesser extent the Project Manager CI system.
If you are uncertain how these rules affect the change you would like to make then feel free to start a discussion in the #project-manager IRC channel, ideally before you start developing.
Your contribution shouldn’t cause another user’s existing configuration to break unless there is a good reason and the change should be announced to the user through an assertion or similar.
Remember that Project Manager is used in many different environments and you should consider how your change may effect others. For example,
The master branch of Project Manager tracks the unstable channel of Nixpkgs, which may update package versions at any time. It’s therefore important to consider how a package update may affect your code and try to reduce the risk of breakage.
The most effective way to reduce this risk is to follow the advice in Section 5.2.3, “Add only valuable options”.
When creating a new module it’s 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 important software options should be modeled explicitly. Less important options should be expressible through an extraConfig
escape hatch.
A 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.
If 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 Nix RFC 42.
If at all possible, make sure to add new tests and expand existing tests so that your change will keep working in the future. See Section 5.6, “Tests” for more information about the Project Manager test suite.
All contributed code must pass the test suite.
Many code changes require changing the documentation as well. Module options should be documented with Nixpkgs-flavoured Markdown. Project Manager is itself documented using a combination of DocBook and AsciiDoc. All text is hosted in Project Manager’s Git repository.
The HTML version of the manual containing both the module option descriptions and the documentation of Project Manager can be generated and opened by typing the following in a shell within a clone of the Project Manager Git repository:
$ nix-build -A docs.html $ xdg-open ./result/share/doc/project-manager/index.html
When you have made changes to a module, it’s a good idea to check that the man page version of the module options looks good:
$ nix-build -A docs.manPages $ man ./result/share/man/man5/project-configuration.nix.5.gz
Every 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.
If you are present in the nixpkgs maintainer list then you can use that entry. If you aren’t then you can add yourself to modules/lib/maintainers.nix
in the Project Manager project.
Maintainers are encouraged to join the IRC or Matrix channel and participate when they have opportunity.
Make sure your code is formatted as described in Section 5.4, “Code Style”. To maintain consistency throughout the project you are encouraged to browse through existing code and adopt its style also in new code.
Similar to Section 5.2.7, “Format your code” we encourage a consistent commit message format as described in Section 5.3, “Commits”.
If your contribution includes a change that should be communicated to users of Project Manager then you can add a news entry. The entry must be formatted as described in Section 5.5, “News”.
When new modules are added a news entry should be included but you don’t need to create this entry manually. The merging maintainer will create the entry for you. This is to reduce the risk of merge conflicts.
Project Manager includes a number of modules that are only usable on some supported platforms. The most common example of platform specific modules are those that define systemd user services, which only works on Linux systems.
If you add a module that’s 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
.
Similarly, if you are adding a news entry then it should be shown only to users that may find it relevant, see Section 5.5, “News” for a description of conditional news.
The Project 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’s assumed that you are doing so under the MIT license.
A potential gotcha with respect to licensing are option descriptions. Often it’s convenient to copy from the upstream software documentation. When this is done it’s important to verify that the license of the upstream documentation allows redistribution under the terms of the MIT license.
The 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’re fixed in a later commit.
The commit messages should follow the 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
{component}: {description} {long description}
where {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 Example 5.1, “Compliant commit message” for a commit message that fulfills these requirements.
Example 5.1. Compliant commit message
The commit 69f8e47e9e74c8d3d060ca22e18246b7f7d988ef contains the commit message
starship: allow running in Emacs if vterm is used The vterm buffer is backed by libvterm and can handle Starship prompts without issues.
which ticks all the boxes necessary to be accepted in Project Manager.
Finally, 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.
The code in Project Manager is formatted by the 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.
Keep lines at a reasonable width, ideally 80 characters or less. This also applies to string literals.
We 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 Project Manager option services.gpg-agent.enableSshSupport
references the gpg-agent
package in Nixpkgs.
Project 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 doesn’t need a news entry.
If you do have a change worthy of a news entry then please add one in news.nix
but you should follow some basic guidelines:
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
$ date --iso-8601=second --universal
If you refer to an option then write its full attribute path. That is, instead of writing
The option 'foo' has been deprecated, please use 'bar' instead.
it should read
The option 'services.myservice.foo' has been deprecated, please use 'services.myservice.bar' instead.
A new module, say foo.nix
, should always include a news entry that has a message similar to
A new module is available: 'services.foo'.
If the module is platform specific, for example, a service module using systemd, then a condition like
condition = hostPlatform.isLinux;
should be added. If you contribute a module then you don’t need to add this entry, the merger will create an entry for you.
Project Manager includes a basic test suite and it’s 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.
It’s 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 bash-lib.
The full Project Manager test suite can be run by executing
$ nix-shell --pure tests -A run.all
in the project root. List all test cases through
$ nix-shell --pure tests -A list
and run an individual test, for example alacritty-empty-settings
, through
$ nix-shell --pure tests -A run.alacritty-empty-settings
However, 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.
$ nix develop --ignore-environment .#all
Project Manager is only able to set session variables automatically in derivations that extend the ones provided by Project Manager.
If you are using a stable version of Nixpkgs but would like to install some particular packages from Nixpkgs unstable – or some other channel – then you can import the unstable Nixpkgs and refer to its packages within your configuration. Something like
{ pkgs, config, ... }: let pkgsUnstable = import <nixpkgs-unstable> {}; in { project.devPackages = [ pkgsUnstable.foo ]; # … }
should work provided you have a Nix channel called nixpkgs-unstable
.
You can add the nixpkgs-unstable
channel by running
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable $ nix-channel --update
Note, the package won’t be affected by any package overrides, overlays, etc.
By default Project Manager will install the package provided by your chosen nixpkgs
channel but occasionally you might end up needing to change this package. This can typically be done in two ways.
If the module provides a package
option, such as programs.beets.package
, then this is the recommended way to perform the override. For example,
programs.beets.package = pkgs.beets.override { enableCheck = true; };
If no package
option is available then you can typically override the relevant package using an overlay.
For example, if you want to use the programs.skim
module but use the skim
package from Nixpkgs unstable, then a configuration like
{ pkgs, config, ... }: let pkgsUnstable = import <nixpkgs-unstable> {}; in { programs.skim.enable = true; nixpkgs.overlays = [ (self: super: { skim = pkgsUnstable.skim; }) ]; # … }
should work OK.