LnL7 / nix-darwin

nix modules for darwin
MIT License
2.82k stars 431 forks source link

share/ directory omitted in user packages that do not include a bin/ directory #1074

Closed antoineco closed 2 weeks ago

antoineco commented 2 weeks ago

Context of the issue

Below is a flake to reproduce the issue. Its sole purpose is to install the nix-direnv package as a user package, the rest is boilerplate.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";

    nix-darwin = {
      url = "github:LnL7/nix-darwin/master";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    { nix-darwin, ... }:
    {
      darwinConfigurations.myhost = nix-darwin.lib.darwinSystem {
        modules = [
          (
            { pkgs, ... }:
            {
              # BEGIN BOILERPLATE #
              nixpkgs.hostPlatform = "aarch64-darwin";
              system.stateVersion = 5;
              users = {
                knownUsers = [ "acotten" ];
                users.acotten.uid = 501;
              };
              # END BOILERPLATE #

              users.users.acotten.packages = [ pkgs.nix-direnv ];
            }
          )
        ];
      };
    };
}

Note that the nix-direnv package only contains a share/ directory:

$ nix run 'nixpkgs#tree' /nix/store/6lw0d8pc7xr7lhqb98ydzakwncamcj8m-nix-direnv-3.0.5
/nix/store/6lw0d8pc7xr7lhqb98ydzakwncamcj8m-nix-direnv-3.0.5
└── share
    └── nix-direnv
        └── direnvrc

3 directories, 1 file

What happened

In the resulting nix-darwin system, the share/nix-direnv/ directory was omitted:

$ ls /run/current-system/etc/profiles/per-user/acotten/share/nix-direnv
ls: cannot access '/run/current-system/etc/profiles/per-user/acotten/share/nix-direnv': No such file or directory

What was expected

nix-darwin behaves similarly to nix profile and does preserve the share/ directory of the nix-direnv package although it doesn't contain a bin/ directory.

Example:

$ nix profile install 'github:NixOS/nixpkgs/nixos-24.05#nix-direnv'
$ ls -l ~/.nix-profile/share/nix-direnv/direnvrc
-r--r--r-- 1 root nixbld 15879 Jan  1  1970 /Users/acotten/.nix-profile/share/nix-direnv/direnvrc

Additional notes

A cursory inspection led me to this:

$ ls -l /etc/static/profiles/per-user/acotten
lrwxr-xr-x  1 root  wheel    60B Jan  1  1970 /etc/static/profiles/per-user/acotten -> /nix/store/ggyqagjxlmsnbgaax9zzmxhxm86rl0nh-user-environment

https://github.com/LnL7/nix-darwin/blob/9d7aebb3039fbfb93afebef53210e2999f8b7e1a/modules/users/default.nix#L193-L201

https://github.com/LnL7/nix-darwin/blob/9d7aebb3039fbfb93afebef53210e2999f8b7e1a/modules/environment/default.nix#L174-L178

antoineco commented 2 weeks ago

I found out that this is actually by design. It is the responsibility of the user (or relevant module) to link the expected paths by extending environment.pathsToLink.

See also https://github.com/NixOS/nixpkgs/issues/47173

Closing