Nix why-depends on a non standard input

Hello,

I’m trying to call a why-depends on a package in my flake config, but this package is part of my unstablePkgs input and not the standard pkgs one. I might be using the wrong terms, sorry, I’m quite new to this and please do correct me.

Here is my flake for reference:

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    agenix = {
      url = "github:ryantm/agenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    nix-flatpak.url = "github:gmodena/nix-flatpak";
    impermanence.url = "github:nix-community/impermanence/master";
  };
  outputs = { self, nixpkgs, unstable, home-manager, nixos-hardware, agenix, nix-flatpak, impermanence }:
  let
    system = "x86_64-linux";
    allowUnfree = { nixpkgs.config.allowUnfree = true; };
  in {
    nixosConfigurations.champignon = nixpkgs.lib.nixosSystem {
      inherit system;
      specialArgs = {
        unstablePkgs = unstable.legacyPackages.${system};
      };
      modules = [
        nixos-hardware.nixosModules.lenovo-thinkpad-t480
        impermanence.nixosModules.impermanence
        allowUnfree
        ./hosts/champignon/nixos/configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            useGlobalPkgs = true;
            useUserPackages = true;
            users.martin = import ./hosts/champignon/home/home.nix;
            extraSpecialArgs = {
	            unstablePkgs = import unstable { config.allowUnfree = true; inherit system; };
	            agenix = agenix;
	            agenixPkgs = agenix.packages.${system};
	            nix-flatpak = nix-flatpak;
	          };
          };
        }
      ];
    };
  };
}

Now, if I do a nix why-depends .#nixosConfigurations.champignon.config.system.build.toplevel .#nixosConfigurations.champignon.pkgs.tilix, tilix being a package from the nixpkgs input, I do find it. But if I do a nix why-depends .#nixosConfigurations.champignon.config.system.build.toplevel .#nixosConfigurations.champignon.pkgs.logseq, logseq being a package from the unstable input, I don’t find it. Now, I guess that it’s because pkgs.logseq is actually the logseq package from the current channel and not the unstable one. How could I specify that I want the unstable one ?

Subsequent question, I found this path .#nixosConfigurations.champignon.pkgs.logseq but is there actually a way to explore the structure of the derivation so that I could have answered my question myself, like finding all the keys after nixosConfiguration.champignon ?

Thanks in advance !

You probably want an overlay.

nixpkgs.overlays = [
  (final: prev: {
    logseq = unstable.logseq;
  })
]

Hello,

thanks for your answer. My setup actually works this way. I guess I could indeed overlay those packages to have them inside the pkgs. But this is not necessary, right now I have them in a specialArgs unstablePkgs and can install them. My question is more how to target those packages when I’m doing a why-depends for instance, or how I can explore the structure past nixosConfiguration.champignon ?

I haven’t understood your problem thoroughly but you can always open the repl, find the derivation path there, and then just pass that to why-depends.

I’m sorry if this was not clear enough.

My problem is that in the command:

nix why-depends .#nixosConfigurations.champignon.config.system.build.toplevel .#nixosConfigurations.champignon.pkgs.tilix

.#nixosConfigurations.champignon.pkgs.tilix targets a package that is in nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";. I would like to target a package that is in unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; instead.

This said, I would be interested on how you would achieve what you described:

You should be able to access that as .#nixosConfigurations.champignon._module.specialArgs.unstablePkgs.tilix.

nix repl is useful for exploring the module system options. Run :lf . to load the flake from current directory. I especially like to use the Tab to auto-complete attribute names.

1 Like

Thank you very much for the hint, helps me a lot and perfectly answers my question.