Something has broken my NixOS setup, and now I can no longer use nix-shell:
❯ nix-shell -p bc
error:
… while calling the 'import' builtin
at «string»:1:18:
1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (bc) ]; } ""
| ^
error: opening file '/nix/store/04g5j6d9za4pgjcyb9p57j87ywmqfa9g-source/default.nix': No such file or directory
/nix/store/04g5j6d9za4pgjcyb9p57j87ywmqfa9g-source contains a copy of the files in the repository I run deploy --hostname 127.0.0.1 .#$(hostname) in, so maybe it’s an issue with deploy-rs?
What I’ve tried so far:
Re-deploying the latest configuration and rebooting. No change.
❯ nix registry list | grep flake:nixpkgs
system flake:nixpkgs path:/nix/store/04g5j6d9za4pgjcyb9p57j87ywmqfa9g-source
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
I don’t know where this value comes from, or how to correct it, though.
And you said /nix/store/04g5j6d9za4pgjcyb9p57j87ywmqfa9g-source is your config flake, not a copy of nixpkgs, correct? You must have set this wrong somewhere. Look for nix.registry settings in your nixos config that might be wrong.
It is the default now for a flake config to set a registry entry for nixpkgs… so if the nixpkgs.flake.source option is somehow set incorrectly, that could be the cause.
nixpkgs.flake.source is set correctly when you use nixpkgs.lib.nixosSystem, but I’m not sure how deploy-rs deals with that.
You can check options.nixpkgs.flake.source.definitionsWithLocations to get some idea what’s setting it.
Oh, it’s probably related to my attempt to apply nixpkgs PR patches! Four different packages I use are broken right now (IDEA, Renovate, Darktable, and Mcomix), and I really wanted to not get stuck until 25.11 is released. So I tried a few things (there doesn’t seem to be an idiomatic way to do this yet) and ended up with this (trimmed for legibility):
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in
{
nixosConfigurations =
let
nixpkgsWithPatches = pkgs.applyPatches {
name = "nixpkgs-patched";
src = nixpkgs;
patches = [
];
};
patchedNixpkgs = (import "${nixpkgsWithPatches}/flake.nix").outputs {
inherit self;
};
in
{
foo = patchedNixpkgs.lib.nixosSystem { … };
};
};
}
Do you mean patchedNixpkgs = builtins.getFlake "path:${nixpkgsWithPatches}";? If I do that then nix flake check complains:
error: the string 'path:/nix/store/bgl6ldj5ihbwcq8p42z3a0qzgqafgk2b-source' is not allowed to refer to a store path (such as 'bgl6ldj5ihbwcq8p42z3a0qzgqafgk2b-source')
Update: I could’ve sworn I tried this originally, but it works:
nixosConfigurations =
let
patchedNixpkgs = pkgs.applyPatches {
name = "nixpkgs-patched";
src = nixpkgs;
patches = [
];
};
in
{
foo = patchedNixpkgs.lib.nixosSystem {
…
};
};
Update: Nope, this breaks as soon as I actually add anything to patches.
Update 2: I was able to use this to get to nixosSystem = import (nixpkgsWithPatches + "/nixos/lib/eval-config.nix");, which gets me the one thing I need from the patched nixpkgs. Hopefully this doesn’t have another weird side effect.