Let flake pkgs follow nixos pkgs

On a flake I want to have the same unstable packages as on my nixos system so that packages are reused. What is the best way to do this and keep both in sync?

I presume you mean like this? The nixpkgs in my-flake will get replaced with the one in your inputs.

# flake.nix
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  my-flake = {
    url = "github:Fake/Url";
    inputs.nixpkgs.follows = "nixpkgs":

The other way around could be you leave nixpkgs undefined in my-flake and have the user set it via inputs.nixpkgs.follows :thinking:
Not sure if it would work though

I want the toplevel nixpkgs nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable" to be the nixpkgs from my nixos flake configuration. One solution would probably to set the “ref” field with the value from my flake.lock of the configuration. But it would be nicer if these two were kept in sync - I guess that is hard to achieve though…

I guess this is what you are looking for:

  inputs = {
    your-nixos-flake.url = "github:you/your-nixos";
    nixpkgs.follows = "your-nixos-flake/nixpkgs";

Looks about right, I might do a file dependency but in general that’s a good Idea!

Actually, this might not even be needed:

  inputs.your-nixos.url = "github:you/your-nixos";
  outputs = {your-nixos, ...} :
    system = "x86_64-linux";
    pkgs = your-nixos.inputs.nixpkgs.legacyPackages.${system};
      packages.${system}.default = pkgs.hello;