nixnix-flake

Using an external flake in home-manager/darwin nix config


I'm trying to use an external (as in not present in nixpkgs) flake in my home-manager (using nix-darwin) config.

The flake has a default output which is the binary produced by buildGoModule: https://github.com/pcasaretto/dotenv/blob/f41d74aa56c2528c46f58977010c6ce99619921a/flake.nix

          default = buildGoModule {
            pname = "dotenv";
            inherit version;
            # In 'nix develop', we don't need a copy of the source tree
            # in the Nix store.
            src = ./.;

            vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
          };

I've managed to add the flake to my config, it builds but the binary does not show up in my path

https://github.com/pcasaretto/nix-home/commit/18e82337efdb0579588e6633c0ae8006788ae402

# flake.nix
dotenv.url = "github:pcasaretto/dotenv";
dotenv.inputs.nixpkgs.follows = "nixpkgs-unstable";
# ...
home-manager.extraSpecialArgs = { dotenv = dotenv; };
# home.nix
{ config, pkgs, lib, dotenv, ... }:
# ...
home.packages = [
# ...
dotenv

Solution

  • home.packages needs to include the package from the flake, not the flake itself.

    Change:

    home.packages = [ # ...
      dotenv
    ];
    

    to:

    home.packages = [ # ...
      dotenv.packages.${pkgs.system}.default
    ];
    

    If you aren't in a flake (or other purity-enforced) context, you can use builtins.currentSystem instead of pkgs.system.