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

Flake inputs.*.follows doesn't change lockfile #5785

Open
LunNova opened this issue Dec 16, 2021 · 3 comments
Open

Flake inputs.*.follows doesn't change lockfile #5785

LunNova opened this issue Dec 16, 2021 · 3 comments
Labels

Comments

@LunNova
Copy link
Member

LunNova commented Dec 16, 2021

Describe the bug

When using inputs.*.follows, the input's lockfile in the nix store still has the old locked version.

This means that if you set .follows on an input and then add that to the registry with nix.registry.myregistryentry.flake = my-input in a nixos configuration it will not have the updated input.

The same applies for adding it to the nixPath with nix.nixPath = [ "mychannel=${my-input}" ]; or if the flake reads its own lock file for any other reason.

Steps To Reproduce

Here is a flake which uses nixpkgs as an input:
https://github.com/LunNova/nixos-configs/tree/nixpkgs-unfree-test

Use this flake as your own input and make its nixpkgs input follow a different revision:

{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
  inputs.nixpkgs-unfree-test.url = "github:lunnova/nixos-configs/nixpkgs-unfree-test";
  inputs.nixpkgs-unfree-test.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs-unfree-test, ... }:
    let lockFile = builtins.fromJSON (builtins.readFile "${nixpkgs-unfree-test}/flake.lock");
    in
    { 
      test = {
        lockFile = lockFile.nodes.nixpkgs.locked.rev;
        runtime = nixpkgs-unfree-test.inputs.nixpkgs.rev;
      };
    };
}
$ nix eval github:lunnova/nixos-configs/nixpkgs-unfree-test-user#test
{ lockFile = "545a0831fa918b6a1c065c03fce907c05646416d"; runtime = "573095944e7c1d58d30fc679c81af63668b54056"; }

Expected behavior

$ nix eval github:lunnova/nixos-configs/nixpkgs-unfree-test-user#test
{ lockFile = "573095944e7c1d58d30fc679c81af63668b54056"; runtime = "573095944e7c1d58d30fc679c81af63668b54056"; }

When follows is used, a new copy of the flake could be created (I assume it can be hardlinked so this doesn't waste space?) in the nix store with its lockfile updated to match the follows.

nix-env --version output

Tested with stable and unstable.

$ nix-env --version
nix-env (Nix) 2.4
$ nix-env --version
nix-env (Nix) 2.5.0pre20211206_d1aaa7e

Workaround

I was able to work around this for my particular case by creating a new flake from a template and substituting the hashes, rather than using the follows mechanism.

      nixpkgs-unfree-relocked = pkgs.stdenv.mkDerivation {
        name = "nixpkgs-unfree-relocked";
        outputs = [ "out" ];
        dontUnpack = true;
        fixupPhase = "";
        installPhase = ''
          mkdir -p $out
          cp -t $out ${nixpkgs-unfree-path}/{flake.nix,flake.lock,default.nix}
          substituteInPlace $out/default.nix --replace "nixpkgs = null" 'nixpkgs = "${args.nixpkgs}"'
          substituteInPlace $out/flake.lock --replace \
            "%REV%" "${lock.nodes.nixpkgs.locked.rev}" --replace \
            "%HASH%" "${lock.nodes.nixpkgs.locked.narHash}"
          substituteInPlace $out/flake.nix --replace \
            "%REV%" "${lock.nodes.nixpkgs.locked.rev}"
        '';
      };
@LunNova LunNova added the bug label Dec 16, 2021
@LunNova
Copy link
Member Author

LunNova commented Dec 16, 2021

The reason for wanting this is similar to #4891

@stale
Copy link

stale bot commented Jun 20, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Jun 20, 2022
@tejing1
Copy link

tejing1 commented Dec 24, 2022

Related: #6894

@stale stale bot removed the stale label Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants