Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elide flake.lock entries that are already "locked" by the url #7895

Open
RuRo opened this issue Feb 23, 2023 · 1 comment
Open

Elide flake.lock entries that are already "locked" by the url #7895

RuRo opened this issue Feb 23, 2023 · 1 comment
Labels
feature Feature request or proposal flakes

Comments

@RuRo
Copy link

RuRo commented Feb 23, 2023

Is your feature request related to a problem? Please describe.

Consider the following flake (note the narHash in the url):

# uses-foo/flake.nix
{
  inputs.foo.url = "github:nixos/nixpkgs/a395950650818e22403fafaadccb42cb40cb5852?narHash=sha256-kBBoeXhOlTIje7S1lku1k+euf9GcpL8eGZkI66yLeBw=";
  outputs = { foo, ... }: foo;
}

Currently, this flake will produce a non-empty flake.lock file that basically duplicates the information already included in the URL. Committing only flake.nix to a git repository and then trying to use it with something like nix run github:myself/uses-foo#hello will fail, complain about the missing flake.lock and ask the user to use --no-write-lock-file or --no-update-lock-file.


A similar thing (but with an extra layer of indirection) happens with the common "override an empty dependency flake" pattern. In this pattern, some flake doesn't define one of its inputs (or defines it to point to an empty dummy flake):

# uses-bar/flake.nix
{
  outputs = { bar, ... }: bar;
}
# or
{
  inputs.bar.url = "github:myself/empty-flake";
  outputs = { bar, ... }: bar;
}

Given this, I would expect

nix run github:myself/uses-bar#hello --override-flake bar 'github:nixos/nixpkgs/a395950650818e22403fafaadccb42cb40cb5852?narHash=sha256-kBBoeXhOlTIje7S1lku1k+euf9GcpL8eGZkI66yLeBw='

and (in the first case)

nix registry add bar 'github:nixos/nixpkgs/a395950650818e22403fafaadccb42cb40cb5852?narHash=sha256-kBBoeXhOlTIje7S1lku1k+euf9GcpL8eGZkI66yLeBw='
nix run github:myself/uses-bar#hello

to work without requiring --no-write-lock-file. Note, that this is already (kind of) the case, but only when bar is replaced with the follows mechanism from another flake:

# another/flake.nix
{
  inputs = {
    this-bar.url = "github:nixos/nixpkgs";
    uses-bar = {
      url = "github:myself/uses-bar";
      inputs.bar.follows = "this-bar";
    };
  };
  outputs = { uses-bar, ... }: uses-bar;
}

So, AFAIK, we currently have 3 mechanisms for "replacing" a flake:

  1. --override-flake
  2. registry
  3. follows

and only follows works without --no-write-lock-file.

Describe the solution you'd like

When a flake input url is already specific enough, don't add it to the lock file

  • "specific enough" probably means "includes a narHash"
    (I would personally prefer if just providing a specific rev would be enough, but this is up for discussion)
  • I would be okay, if this would be a per-input opt-in behaviour (something like inputs.bar.unlocked = true;)
  • This would include the urls derived from follows, --override-flake and registries

Describe alternatives you've considered

The only alternatives I see are:

  1. Don't use flakes at all. Unfortunately, "classic" nix doesn't provide a standardized/idiomatic way to organize nix code.
  2. Run everything with --no-write-lock-file. Unfortunately, this is either really cumbersome (if you manually add this option to each command) or really error-prone (if you declare an alias that automatically includes --no-write-lock-file or something to that effect).

Priorities

Add 👍 to issues you find important.

@RuRo RuRo added the feature Feature request or proposal label Feb 23, 2023
@roberth
Copy link
Member

roberth commented Feb 24, 2023

Seems like at least the "override an empty dependency flake" pattern part would be solvable by

The remaining part would be not to lock already fully pinned inputs.

@roberth roberth added the flakes label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal flakes
Projects
None yet
Development

No branches or pull requests

2 participants