Trouble switching from a flakes based NixOS configuration to a npins based one

The situation is that I have been using a flake.nix NixOS setup so far, and I would like to try out an npins based NixOS setup (i.e. one that uses a configuraiton.nix).

I have a ~/nixos-conf directory with a default.nix (I could call it configuration.nix, but I don’t think it matters ultimately?).

I’ve gotten npins initialized, and I have the following in my sources.json:

   1   │ {
   2   │   "pins": {
   3   │     "nixpkgs": {
   4   │       "type": "Channel",
   5   │       "name": "nixpkgs-unstable",
   6   │       "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.05pre552261.8b8c94078445/nixexprs.t
       │ ar.xz",
   7   │       "hash": "0p9z4sj3svk28agmk98bi24gnw81r5nwknxvrhyz4v6dp5wymn4i"
   8   │     }
   9   │   },
  10   │   "version": 3
  11   │ }

So, nixpkgs (unstable) is currently pinned by npins for my configuration project.

Next up, in my configuration.nix (which I’m calling default.nix), I have:

{
  config,
  ...
}:
let
  hostName = config.networking.hostName;
  sources = import ./npins;
in
{
  environment.etc."nixpkgs".source = sources.nixpkgs;
  # my guess is this nixpkgs overlay may not be needed anymore? but i'm not yet sure.
  nixpkgs.overlays =
    let
      npinsOverlay = self: _super: {
        inherit (sources) nixpkgs;
      };
    in
      [ npinsOverlay ];
  nix.nixPath = [
    # so that <nixpkgs> has the right path
    "nixpkgs=/home/bzm3r/nixos-conf/npins"
    # so that nixos-rebuild etc. have the right path
    "nixos-config=/home/bzm3r/nixos-conf/default.nix"
    # don not understand why this last one is needed
    # therefore left it out
    # "/nix/var/nix/profiles/per-user/root/channels"
  ];
  ...
}

Finally, only because I am currently still on the system configured by the flakes.nix setup, I decided to set up a shell.nix that lets me run my nixos-rebuild switch a little more ergonomically:

{
        sources ? import ./npins,
        pkgs ? import sources.nixpkgs {}
}:

pkgs.mkShell {
        buildInputs = with pkgs; [
                nix
        ];
        shellHook = ''
                export nixpkgs=${sources.nixpkgs.outPath}
                export NIX_PATH=nixpkgs=${sources.nixpkgs.outPath}:nixos-config=/home/bzm3r/nixos-conf/default.nix
        '';
}

(which I think is equivalent to setting export NIX_PATH=nixpkgs=~/nixos-conf/npins:nixos-config=~/nixos-conf/default.nix?)

Ultimately, I end up getting this error:

❯ nixos-rebuild switch
error:
       … while evaluating the attribute 'config'

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:233:21:

          232|           (regularModules ++ [ internalModule ])
          233|           ({ inherit lib options config specialArgs; } // specialArgs);
             |                     ^
          234|         in mergeModules prefix (reverseList collected);
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:233:21:

          232|           (regularModules ++ [ internalModule ])
          233|           ({ inherit lib options config specialArgs; } // specialArgs);
             |                     ^
          234|         in mergeModules prefix (reverseList collected);
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/store/a1n82l7alhh1fn33nyp7p5qk43lr87z9-source/lib/modules.nix:233:21:

          232|           (regularModules ++ [ internalModule ])
          233|           ({ inherit lib options config specialArgs; } // specialArgs);
             |                     ^
          234|         in mergeModules prefix (reverseList collected);

Any tips on what I could google next, or try out next, would be very helpful!

(here’s the github repo for all the above, in case it’s helpful: here’s the github repo for all the above: https://github.com/bzm3r/nixos-conf/tree/no-flakes)

oaaaakkkayyy… .can you tell me what npins is?

Have you managed to work it out? I too am considering leaving flakes altogether and switch to npins.

npins is the spiritual spinoff of niv.

Npins is a dependency pinning. It creates a lockfile and a corresponding Nix file containing all GitHub repos you declared at cmdline.

I will test it tonight, just to freak out a bit.

1 Like

Wait are we trying to deprecate another experimental feature again?

Short answer: NO.

Long answer: many people are testing a truckload of ideas, many of them related to Nix.
Some of them do not like Nix Flakes.
Some others merely like to play with new ideas and experiments.

I hope you are not angry by people like me that like to run experiments.

1 Like

Would be fine if some people wouldn’t pitch this idea to others (often newbies looking for advice) in an attempt to dissuade them off Flakes.

And then you all of a sudden get these posts because, surprise, replacing a maybe not fully polished feature that is at used by a lot of people with something else that is equally unpolished but also used by almost no one is not a good idea.

I do not like that idea of “too dangerous things to be said” vibes.
As we say in my country (not in English), let the people break their faces (let them suffer for their bad choices).

Further, npins is described by nix.dev:

https://nix.dev/guides/recipes/dependency-management.html

1 Like