Why must I manually specify the default package?

I’ve added a flake to a small Rust based utility called git-repo-sync.

In that flake I specify:

      packages = forAllSystems (system: {
        default = pkgs.rustPlatform.buildRustPackage {
          inherit buildInputs nativeBuildInputs;
          pname = "git-repo-sync";
          version = "0.2.0";
          src = pkgs.lib.cleanSource ./.;
          cargoLock = {
            lockFile = ./Cargo.lock;
          };
        };
      });

      defaultPackage = forAllSystems (system: self.packages.${system}.default);

full source here

When I run nix flake show it shows that it has packages.x86_64-linux.default and also defaultPackages.x86_64-linux. The package also builds correctly and all seems to be fine.

The issue is however in the use of the package. In my NixOs flake.nix I have:

inputs = {
 ....
    gitRepoSync = { 
      url = "github:oddity-ai/git-repo-sync/nixify";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  }
  outputs = { nixpkgs, home-manager, nix-ld, plasma-manager, ... }@inputs: {
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      specialArgs = inputs;

Then in a module that I defined called packages. nix I have:

{ pkgs, gitRepoSync, ... }:
{
    environment.systemPackages = [
      ...
      gitRepoSync.packages.x86_64-linux.default # <- why do I need to specify the default pacakge here?
      ...
}

This works fine and gives me exactly the result that I am looking for. However, why do I need to specify the default package like that? I would have expected that I could just put gitRepoSync there. However, when I do that my nixos-rebuild completes without an error, but the git repo-sync command is also not available on my path. Why? What am I missing here?

Okay, it seems to be just the way it is. It’s just a mismatch of expectations. Found this thread talking about the same ‘problem’:

Yes, though the nix CLI checks certain outputs automatically, that doesn’t happen in nix code.
It’s adimttedly unergonomic but you can write helper functions (or use a framework like flake-parts) to make it less clunky.

1 Like