Project Manager Manual

Version 24.05 (unstable)


Table of Contents

Preface
Introduction to Project Manager
the project-manager devShell
Quick Start
New Project
Integrate With an Existing Project
Installing Project Manager
Using Project Manager
Configuration Example
Rollbacks
Keeping your project root safe from harm
Updating
Nix Flakes
Prerequisites
Standalone setup
Writing Project Manager Modules
Option Types
Contributing
Getting started
Guidelines
News
Tests
Third-Party Tools and Extensions
Module Collections
Frequently Asked Questions (FAQ)
Why is there a collision error when switching generation?
Why are the session variables not set?
Why do I get an error message about ca.desrt.dconf or dconf.service?
How do I install packages from Nixpkgs unstable?
How do I change the package used by a module?
A. Project Manager Configuration Options
B. Release Notes

Preface

This manual will eventually describe how to install, use, and extend Project Manager.

If you encounter problems then please reach out on the Matrix room. If your problem is caused by a bug in Project Manager then it should be reported on the Project Manager issue tracker.

Note

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.

Introduction to Project Manager

Project Manager is a Nix-powered tool for reproducible management of the contents of project directories. This includes programs, configuration files, environment variables and, well… arbitrary files. The following example snippet of Nix code:

programs.git = {
  enable = true;
  userEmail = "joe@example.org";
  userName = "joe";
};

would make available to a user the git executable and man pages and a configuration file ~/.config/git/config:

[user]
  email = "joe@example.org"
  name = "joe"

Since Project Manager is implemented in Nix, it provides several benefits:

  • Contents are reproducible — a project will be the exact same every time it’s built, unless of course, an intentional change is made. This also means you can have the exact same project on different hosts.

  • Significantly faster and more powerful than various backup strategies.

  • Unlike “dot files” repositories, Project Manager supports specifying programs, as well as their configurations.

  • Supported by http://cache.nixos.org/, so that you don’t have to build from source.

  • If you do want to build some programs from source, there is hardly a tool more useful than Nix for that, and the build instructions can be neatly integrated in your Project Manager usage.

  • Infinitely composable, so that values in different configuration files and build instructions can share a source of truth.

  • Connects you with the most extensive and most up-to-date software package repository on earth, Nixpkgs.

Project Manager produces two things

  1. Nix expressions to be used in flakes and

  2. files in your project’s working tree.

Either of these can be used individually, but are designed to work together.

The former are accessed via self.projectConfigurations.${system} in your flake, while the latter are created by running project-manager switch.

Table of Contents

the project-manager devShell

the project-manager devShell

One of the most powerful combinations is self.projectConfigurations.${system}.devShells.project-manager. This provides a shell that has a PATH and other environment that have been produced by the Project Manager configuration. If you use this environment, you can often avoid producing files into your working tree, as the executables available here may be modified to look for their files directly in the Nix store.

Quick Start

It’s not necessary to install Project Manager in order to use it for a project. The easiest way to try it out is on a new project, but it is also intended to be easy to integrate it with an existing project

NB: If you have installed Project Manager already, then nix run github:sellout/project-manager -- can be replaced with project-manager in any commands.

New Project

To create a new project from scratch, run the following command :

nix run github:sellout/project-manager -- init my-new-project --switch

This will create a new directory called “my-new-project” in the current directory, create a flake and project configuration (.config/project/default.nix) in that directory, and populate it with files as dictated by the project configuration.

See §Configuration for where to go from here.

Integrate With an Existing Project

WARNING: project-manager switch (but no other subcommands) may overwrite files that already exist in your working tree. You should ensure that everything is committed or stashed before integrating Project Manager with an existing project.

Start by creating a basic project configuration by running this from within your project directory:

nix run github:sellout/project-manager

Note that this is similar to the command used by a new project. The differences are that

  1. we’re not providing a directory for it to create, so it will use the current directory and

  2. we are not providing --switch to avoid it immediately creating the new configuration.

If your project is already flake-based, this will not overwrite the existing flake, so you will need to modify your flake to provide Project Manager integration.

At a minimum, you need to have

{
  outputs = {nixpkgs, project-manager, self}: let
    system = "x86_64-linux"; # or another system
    pkgs = import nixpkgs {inherit system};
  in {
    projectConfigurations.${system} =
      project-manager.lib.defaultConfiguration {inherit pkgs self};
  }

  inputs = {
    # NB: This version doesn’t have to be current, Project Manager supports many
    #     older Nixpkgs releases as well as unstable (as much as is possible).
    nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
    project-manager.url = "github:sellout/project-manager";
  }
}

But project manager offers many attributes to integrate with other parts of your flake. For example., you may also include

{
  outputs = {nixpkgs, project-manager, self}: let
    system = "x86_64-linux"; # or another system
    pkgs = import nixpkgs {inherit system};
  in {
    # …

    devShells.${system} = let
        self.projectConfigurations.${system}.devShells
        // {
          # You can user `overrideAttrs` on this to extend this shell.
          default =
            self.projectConfigurations.${system}.devShells.project-manager;
        };

      checks.${system} =
        # This provides a check that files generated by Project Manager are
        # up-to-date, as well as checks for other modules you may have
        # configured (a formatter, linters, etc.)
        self.projectConfigurations.${system}.checks
        // {
          # Any additional checks
        }

      # If your formatter is configured by Project Manager, which is especially
      # useful when using meta-formatters like treefmt-nix.
      # (https://github.com/numtide/treefmt-nix#readme)
      formatter.${system} = self.projectConfigurations.${system}.formatter;
}

If you have all of your non-Project Manager related changes stashed, you can see how the default configuration affects your project by running

nix run github:sellout/project-manager -- switch

You can now see what changes are reflected in your VCS. The most important thing is to check for modified files. For anything that has been modified you can either disable that module in .config/project/default.nix or adjust the configuration there to match what exists in your repository.

Other files may have also been created. You can similarly disable these modules if you want to.

Installing Project Manager

NB: Project Manager doesn’t need to be installed outside of the projects it is used in. In most projects that use Project Manager, nix develop (or maybe nix develop .#project-manager) should put you into a shell that makes project-manager available to you. The exception to this is when you are adding Project Manager to a project.

That said, it can be useful to have Project Manager installed more widely. Currently this can only be done via a flake. This snippet includes examples for nix-darwin, Home Manager, and NixOS. You do not need to include all of them.

{
  outputs = {home-manager, nix-darwin, nixpkgs, project-manager, self ...}: let
    system = "x86_64-linux"; # or another system
    pkgs = import nixpkgs {
      inherit system;
      overlays = [project-manager.overlays.default];
    };
  {
    darwinConfigurations."host" = nix-darwin.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [
        ({pkgs, ...}: {
          environment.systemPackages = [pkgs.project-manager];
        })
      ];
    };

    homeConfigurations."user@host" = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      modules = [
        ({pkgs, ...}: {
          home.packages = [pkgs.project-manager];
        })
      ];
    };

    nixosConfigurations."host" = nixpkgs.lib.nixosSystem {
      inherit pkgs system;
      modules = [
        ({pkgs, ...}: {
          environment.systemPackages = [pkgs.project-manager];
        })
      ];
    };
  };

  inputs.project-manager.url = "github:sellout/project-manager";
}

Using Project Manager

Your use of Project Manager is centered around the configuration file, which is typically found at $PROJECT_ROOT/.config/project/default.nix in the standard installation or $PROJECT_ROOT/flake.nix in a Nix flake based installation.

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/default.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 Project Manager 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.

Configuration Example

A fresh install of Project Manager will generate a minimal $PROJECT_ROOT/.config/project/default.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.
  home.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.

Note

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 project.devPackages.

  • The option names of a program module typically start with programs.<package name>.

  • Similarly, for a service module, the names start with services.<package name>. Note in some cases a package has both programs and service options – Emacs is such an example.

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.

Rollbacks

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

  1. 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
    …
    
  2. Copy the Nix store path of the generation you chose, for example,

    /nix/store/mv960kl9chn2lal5q8lnqdp1ygxngcd1-project-manager-generation
    

    for generation 763.

  3. Run the activate script inside the copied store path:

    $ /nix/store/mv960kl9chn2lal5q8lnqdp1ygxngcd1-project-manager-generation/activate
    Starting Project Manager activation
    …
    

Keeping your project root safe from harm

To configure programs and services Project Manager must write various things to your project directory. Project Manager will attempt to detect collisions with existing files, but this can be difficult. Whereas Home Manager can rely on symlinks to identify files that have been produced during activation, Project Manager can’t always do this. Files with “repository” persistence must be either hard links or copies (if the project is on a different volume than the Nix store). Project Manager must assume these files can be overwritten. This is why it’s important to ensure that changes are stashed or committed before running project-manager switch.

If there are collisions between existing files and files with “worktree” persistence, these will cause Project manager to terminate before changing any files. (Files with “store” persistence don’t exist in the worktree and thus can never prevent switching.)

For example, suppose you have a wonderful, painstakingly created $PROJECT_ROOT/.git/config and add

{
  # …

  programs.git = {
    enable = true;
    userName = "Jane Doe";
    userEmail = "jane.doe@example.org";
  };

  # …
}

to your configuration. Attempting to switch to the generation will then result in

$ project-manager switch
…
Activating checkLinkTargets
Existing file '/…/.git/config' is in the way
Please move the above files and try again

Updating

If you have installed Project Manager using the Nix channel method then updating Project Manager is done by first updating the channel. You can then switch to the updated Project Manager environment.

$ nix-channel --update
…
unpacking channels...
$ project-manager switch

Nix Flakes

Project Manager is compatible with Nix Flakes. But please be aware that this support is still experimental and may change in backwards incompatible ways.

Just like in the standard installation you can use the Project Manager flake in one way:

  1. Using the standalone project-manager tool. See Standalone setup for instructions on how to perform this installation.

Table of Contents

Prerequisites
Standalone setup

Prerequisites

  • Install Nix 2.4 or later, or have it in 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 (.config/project/default.nix).

    Unlike the channel-based setup, .config/project/default.nix will be evaluated when the flake is built, so it must be present before bootstrap of Project Manager from the flake. See Configuration Example for introduction about writing a Project Manager configuration.

Standalone setup

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 24.05 run

$ nix run project-manager/release-24.05 -- init --switch

This will generate a flake.nix and a default.nix file in ./.config/project, 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-24.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

Note

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.

Writing Project Manager Modules

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.

Overall the basic option types are the same in Project Manager as Home Manager. There are some extra options provided in the file-type submodule.

Table of Contents

Option Types

Option Types

Overall the basic option types are the same in Project Manager as NixOS. A few Project Manager options, however, make use of custom types that are worth describing in more detail. These are the option types dagOf and gvariant that are used, for example, by project.activation.

hm.types.dagOf

Options of this type have attribute sets as values where each member is a node in a directed acyclic graph (DAG). This allows the attribute set entries to express dependency relations among themselves. This can, for example, be used to control the order of match blocks in a OpenSSH client configuration or the order of activation script blocks in project.activation.

A number of functions are provided to create DAG nodes. The functions are shown below with examples using an option foo.bar of type hm.types.dagOf types.int.

hm.dag.entryAnywhere (value: T) : DagEntry<T>

Indicates that value can be placed anywhere within the DAG. This is also the default for plain attribute set entries, that is

foo.bar = {
  a = hm.dag.entryAnywhere 0;
}

and

foo.bar = {
  a = 0;
}

are equivalent.

hm.dag.entryAfter (afters: list string) (value: T) : DagEntry<T>

Indicates that value must be placed after each of the attribute names in the given list. For example

foo.bar = {
  a = 0;
  b = hm.dag.entryAfter [ "a" ] 1;
}

would place b after a in the graph.

hm.dag.entryBefore (befores: list string) (value: T) : DagEntry<T>

Indicates that value must be placed before each of the attribute names in the given list. For example

foo.bar = {
  b = hm.dag.entryBefore [ "a" ] 1;
  a = 0;
}

would place b before a in the graph.

hm.dag.entryBetween (befores: list string) (afters: list string) (value: T) : DagEntry<T>

Indicates that value must be placed before the attribute names in the first list and after the attribute names in the second list. For example

foo.bar = {
  a = 0;
  c = hm.dag.entryBetween [ "b" ] [ "a" ] 2;
  b = 1;
}

would place c before b and after a in the graph.

There are also a set of functions that generate a DAG from a list. These are convenient when you just want to have a linear list of DAG entries, without having to manually enter the relationship between each entry. Each of these functions take a tag as argument and the DAG entries will be named ${tag}-${index}.

hm.dag.entriesAnywhere (tag: string) (values: [T]) : Dag<T>

Creates a DAG with the given values with each entry labeled using the given tag. For example

foo.bar = hm.dag.entriesAnywhere "a" [ 0 1 ];

is equivalent to

foo.bar = {
  a-0 = 0;
  a-1 = hm.dag.entryAfter [ "a-0" ] 1;
}
hm.dag.entriesAfter (tag: string) (afters: list string) (values: [T]) : Dag<T>

Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed are placed after each of the attribute names in afters. For example

foo.bar =
  { b = 0; }
  // hm.dag.entriesAfter "a" [ "b" ] [ 1 2 ];

is equivalent to

foo.bar = {
  b = 0;
  a-0 = hm.dag.entryAfter [ "b" ] 1;
  a-1 = hm.dag.entryAfter [ "a-0" ] 2;
}
hm.dag.entriesBefore (tag: string) (befores: list string) (values: [T]) : Dag<T>

Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed before each of the attribute names in befores. For example

foo.bar =
  { b = 0; }
  // hm.dag.entriesBefore "a" [ "b" ] [ 1 2 ];

is equivalent to

foo.bar = {
  b = 0;
  a-0 = 1;
  a-1 = hm.dag.entryBetween [ "b" ] [ "a-0" ] 2;
}
hm.dag.entriesBetween (tag: string) (befores: list string) (afters: list string) (values: [T]) : Dag<T>

Creates a DAG with the given values with each entry labeled using the given tag. The list of values are placed before each of the attribute names in befores and after each of the attribute names in afters. For example

foo.bar =
  { b = 0; c = 3; }
  // hm.dag.entriesBetween "a" [ "b" ] [ "c" ] [ 1 2 ];

is equivalent to

foo.bar = {
  b = 0;
  c = 3;
  a-0 = hm.dag.entryAfter [ "c" ] 1;
  a-1 = hm.dag.entryBetween [ "b" ] [ "a-0" ] 2;
}
hm.types.gvariant

This type is useful for options representing GVariant values. The type accepts all primitive GVariant types as well as arrays, tuples, “maybe” types, and dictionaries.

Some Nix values are automatically coerced to matching GVariant value but the GVariant model is richer so you may need to use one of the provided constructor functions. Examples assume an option foo.bar of type hm.types.gvariant.

hm.gvariant.mkBoolean (v: bool)

Takes a Nix value v to a GVariant boolean value (GVariant format string b). Note, Nix booleans are automatically coerced using this function. That is,

foo.bar = hm.gvariant.mkBoolean true;

is equivalent to

foo.bar = true;
hm.gvariant.mkString (v: string)

Takes a Nix value v to a GVariant string value (GVariant format string s). Note, Nix strings are automatically coerced using this function. That is,

foo.bar = hm.gvariant.mkString "a string";

is equivalent to

foo.bar = "a string";
hm.gvariant.mkObjectpath (v: string)

Takes a Nix value v to a GVariant objectpath value (GVariant format string o).

hm.gvariant.mkUchar (v: string)

Takes a Nix value v to a GVariant uchar value (GVariant format string y).

hm.gvariant.mkInt16 (v: int)

Takes a Nix value v to a GVariant int16 value (GVariant format string n).

hm.gvariant.mkUint16 (v: int)

Takes a Nix value v to a GVariant uint16 value (GVariant format string q).

hm.gvariant.mkInt32 (v: int)

Takes a Nix value v to a GVariant int32 value (GVariant format string i). Note, Nix integers are automatically coerced using this function. That is,

foo.bar = hm.gvariant.mkInt32 7;

is equivalent to

foo.bar = 7;
hm.gvariant.mkUint32 (v: int)

Takes a Nix value v to a GVariant uint32 value (GVariant format string u).

hm.gvariant.mkInt64 (v: int)

Takes a Nix value v to a GVariant int64 value (GVariant format string x).

hm.gvariant.mkUint64 (v: int)

Takes a Nix value v to a GVariant uint64 value (GVariant format string t).

hm.gvariant.mkDouble (v: double)

Takes a Nix value v to a GVariant double value (GVariant format string d). Note, Nix floats are automatically coerced using this function. That is,

foo.bar = hm.gvariant.mkDouble 3.14;

is equivalent to

foo.bar = 3.14;
hm.gvariant.mkArray type elements

Builds a GVariant array containing the given list of elements, where each element is a GVariant value of the given type (GVariant format string a${type}). The type value can be constructed using

  • hm.gvariant.type.string (GVariant format string s)

  • hm.gvariant.type.boolean (GVariant format string b)

  • hm.gvariant.type.uchar (GVariant format string y)

  • hm.gvariant.type.int16 (GVariant format string n)

  • hm.gvariant.type.uint16 (GVariant format string q)

  • hm.gvariant.type.int32 (GVariant format string i)

  • hm.gvariant.type.uint32 (GVariant format string u)

  • hm.gvariant.type.int64 (GVariant format string x)

  • hm.gvariant.type.uint64 (GVariant format string t)

  • hm.gvariant.type.double (GVariant format string d)

  • hm.gvariant.type.variant (GVariant format string v)

  • hm.gvariant.type.arrayOf type (GVariant format string a${type})

  • hm.gvariant.type.maybeOf type (GVariant format string m${type})

  • hm.gvariant.type.tupleOf types (GVariant format string (${lib.concatStrings types}))

  • hm.gvariant.type.dictionaryEntryOf [keyType valueType] (GVariant format string {${keyType}${valueType}})

where type and types are themselves a type and list of types, respectively.

hm.gvariant.mkEmptyArray type

An alias of hm.gvariant.mkArray type [].

hm.gvariant.mkNothing type

Builds a GVariant maybe value (GVariant format string m${type}) whose (non-existent) element is of the given type. The type value is constructed as described for the mkArray function above.

hm.gvariant.mkJust element

Builds a GVariant maybe value (GVariant format string m${element.type}) containing the given GVariant element.

hm.gvariant.mkTuple elements

Builds a GVariant tuple containing the given list of elements, where each element is a GVariant value.

hm.gvariant.mkVariant element

Builds a GVariant variant (GVariant format string v) which contains the value of a GVariant element.

hm.gvariant.mkDictionaryEntry [key value]

Builds a GVariant dictionary entry containing the given list of elements (GVariant format string {${key.type}${value.type}}), where each element is a GVariant value.

Contributing

Contributions to Project Manager are very welcome. 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 Getting started for information on how to set up a suitable development environment and 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.

Table of Contents

Getting started
Guidelines
News
Tests

Getting started

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 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

  1. 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

  2. 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.

Guidelines

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 Matrix room. ideally before you start developing.

Maintain backward compatibility

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,

  • Does your change work for people that don’t use NixOS? Consider other GNU/Linux distributions and macOS.

  • Does your change work for people whose configuration is built on one system and deployed on another system?

Keep forward compatibility in mind

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 Add only valuable options.

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.

Add relevant tests

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 Tests for more information about the Project Manager test suite.

All contributed code must pass the test suite.

Add relevant documentation

Many code changes require changing the documentation as well. Module options should be documented with Nixpkgs-flavoured Markdown. 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

Add yourself as a module maintainer

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.

As a maintainer you are expected to respond to issues and pull-requests associated with your module.

Maintainers are encouraged to join the Matrix room and participate when they have opportunity.

Format your code

Make sure your code is formatted as described in Code Style. To maintain consistency throughout the project you are encouraged to browse through existing code and adopt its style also in new code.

Format your commit messages

Similar to Format your code we encourage a consistent commit message format as described in Commits.

Format your news entries

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 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.

Use conditional modules and news

Project 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.

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 News for a description of conditional news.

Mind the license

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.

Commits

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 the example commit for a commit message that fulfills these requirements.

Example commit

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.

Code Style

The code in Project Manager is formatted by the alejandra tool and the formatting is checked in the pull request tests. Run nix fmt 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.

News

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
    
  • 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.

  • Wrap the news message so that it will fit in the typical terminal, that is, at most 80 characters wide. Ideally a bit less.

  • Unlike commit messages, news will be read without any connection to the Project Manager source code. It’s therefore important to make the message understandable in isolation and to those who don’t have knowledge of the Project Manager internals. To this end it should be written in more descriptive, prose like way.

  • 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.

Tests

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

Third-Party Tools and Extensions

Here is a collection of tools and extensions that relate to Project Manager. Note, these are maintained outside the regular Project Manager flow so quality and support may vary wildly. If you encounter problems then please raise them in the corresponding project, not as issues in the Project Manager tracker.

If you have made something interesting related to Project Manager then you are encouraged to create a PR that expands this chapter.

Table of Contents

Module Collections

Module Collections

Frequently Asked Questions (FAQ)

Why is there a collision error when switching generation?

Project Manager currently installs packages into the user environment, precisely as if the packages were installed through nix-env --install. This means that you will get a collision error if your Project Manager configuration attempts to install a package that you already have installed manually, that is, packages that shows up when you run nix-env --query.

For example, imagine you have the hello package installed in your environment

$ nix-env --query
hello-2.10

and your Project Manager configuration contains

project.devPackages = [ pkgs.hello ];

Then attempting to switch to this configuration will result in an error similar to

$ project-manager switch
these derivations will be built:
  /nix/store/xg69wsnd1rp8xgs9qfsjal017nf0ldhm-project-manager-path.drv
[…]
Activating installPackages
replacing old ‘project-manager-path’
installing ‘project-manager-path’
building path(s) ‘/nix/store/b5c0asjz9f06l52l9812w6k39ifr49jj-project-environment’
Wide character in die at /nix/store/64jc9gd2rkbgdb4yjx3nrgc91bpjj5ky-buildenv.pl line 79.
collision between ‘/nix/store/fmwa4axzghz11cnln5absh31nbhs9lq1-project-manager-path/bin/hello’ and ‘/nix/store/c2wyl8b9p4afivpcz8jplc9kis8rj36d-hello-2.10/bin/hello’; use ‘nix-env --set-flag priority NUMBER PKGNAME’ to change the priority of one of the conflicting packages
builder for ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-project-environment.drv’ failed with exit code 2
error: build of ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-project-environment.drv’ failed

The solution is typically to uninstall the package from the environment using nix-env --uninstall and reattempt the Project Manager generation switch.

You could also opt to uninstall all of the packages from your profile with nix-env --uninstall '*'.

Why are the session variables not set?

Project Manager is only able to set session variables automatically in derivations that extend the ones provided by Project Manager.

Why do I get an error message about ca.desrt.dconf or dconf.service?

You are most likely trying to configure something that uses dconf but the DBus session isn’t aware of the dconf service. The full error you might get is

error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files

or

error: GDBus.Error:org.freedesktop.systemd1.NoSuchUnit: Unit dconf.service not found.

The solution on NixOS is to add

programs.dconf.enable = true;

to your system configuration.

How do I install packages from Nixpkgs unstable?

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.

How do I change the package used by a module?

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.

  1. If the module provides a package option, such as programs.beets.package, then this is the recommended way to perform the change. For example,

    programs.beets.package = pkgs.beets.override { pluginOverrides = { beatport.enable = false; }; };
    

    See Nix pill 17 for more information on package overrides. Alternatively, if you want to use the beets package from Nixpkgs unstable, then a configuration like

    { pkgs, config, ... }:
    
    let
    
      pkgsUnstable = import <nixpkgs-unstable> {};
    
    in
    
    {
      programs.beets.package = pkgsUnstable.beets;
    
      # …
    }
    

    should work OK.

  2. If no package option is available then you can typically change 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.