-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Flakes in the nix store do not retain references to their inputs #6895
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/what-would-you-change-in-nix-or-nixos/21086/3 |
Related, including possible solutions: #4250 |
For anyone looking to work around this problem, this may be helpful: tejing1/nixos-config@4767d88 |
If you're looking at @tejing1's config and wondering how to adapt it for your use in flakes, this example I wrote might help. https://github.com/a-h/nix-copy-flake-inputs-to-store/blob/main/flake.nix {
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
xc = {
url = "github:joerdav/xc";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, xc, ... }:
let
pkgsForSystem = system: import nixpkgs {
inherit system;
overlays = [
(final: prev: { xc = xc.packages.${system}.xc; })
];
};
flakeClosureRefForSystem = { system, pkgs }: (import ./flakeClosureRef.nix {
pkgs = pkgs;
lib = nixpkgs.lib;
});
listFlakeInputsForSystem = { system, pkgs }: pkgs.writeShellScriptBin "list-flake-inputs" ''
cat ${((flakeClosureRefForSystem { inherit system pkgs; }) self)}
'';
allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
system = system;
pkgs = pkgsForSystem system;
});
in
{
# Add the flake input reference to the output set so that we can see it in the repl.
#
# Load the repl with:
# nix repl
# Inside the repl, load the flake:
# :lf .
# View the derivation:
# outputs.flakeInputReference.x86_64-linux
# Then build it.
# :b outputs.flakeInputReference.x86_64-linux
#
# The store path will be printed.
#
# cat the store path to see the contents. If you inspect the directories, you'll see
# that the directories contain the source code of all flake inputs.
flakeInputReference = forAllSystems ({ system, pkgs }: {
default = ((flakeClosureRefForSystem { inherit system pkgs; }) self);
});
# `nix develop` provides a shell containing development tools.
devShells = forAllSystems ({ system, pkgs }: {
default = pkgs.mkShell {
buildInputs = [
# Bring in xc as an overlay applied within pkgsForSystem.
# So instead of xc.packages.${system}.xc, we can use pkgs.xc.
pkgs.xc
# Ensure that the recursive tree of flake inputs are added to the Nix store.
# You can list the flake inputs with the `list-flake-inputs` command.
(listFlakeInputsForSystem { inherit system pkgs; })
];
};
});
};
} If you want to build without an internet connection later as per #4250 you may find this useful. |
hi @a-h i'm sorry can you help me understand how to use this for nixosConfiguration inputs? |
For a nixos config, my original example is closer to what you want. Assuming you pass { lib, pkgs, inputs, ... }:
let
inherit (builtins) concatMap attrValues concatStringsSep;
inherit (lib) unique;
flakesClosure = flakes: if flakes == [] then [] else unique (flakes ++ flakesClosure (concatMap (flake: if flake ? inputs then attrValues flake.inputs else []) flakes));
flakeClosureRef = flake: pkgs.writeText "flake-closure" (concatStringsSep "\n" (flakesClosure [ flake ]) + "\n");
in
{
system.extraDependencies = [ (flakeClosureRef inputs.self) ];
} |
Describe the bug
Many nixos + flakes users keep a reference to
self
in their nixos generations, for traceability, however this does not ensure that inputs to the flake are kept in the closure. For most inputs, in most cases, this simply means they need to be re-downloaded from github or wherever they came from, however forpath:
inputs, and for inputs where the source has been taken down for some reason, a user may be unpleasantly surprised to find that they do not, in fact, have all the nix code needed to reproduce their system.Steps To Reproduce
(Note the dependence on PWD in
flake2
's inputs. Adjust as needed if reproducing.)Expected behavior
I would expect that final
nix eval $(realpath ./result/self)\#foo
to successfully produce1
, just as it did before the gc, indicating that savingself
in theresult
output had in fact kept everything necessary to re-evaluate the flake.nix-env --version
outputThe text was updated successfully, but these errors were encountered: