I want to switch to a full flake based system as it fulfills the only problem I had with nixos: mixing nixpkgs with my personal projects in a reproducible and traceable way.
If I try to rebuild my system though, something is missing:
[dan@thinkpad:/etc/nixos]$ nixos-rebuild switch --flake /etc/nixos
building the system configuration...
error: flake 'git+file:///etc/nixos?ref=main&rev=d1656f817efa24fb3ec11e7a58ab082fb2298688' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."thinkpad".config.system.build.toplevel', 'legacyPackages.x86_64-linux.nixosConfigurations."thinkpad".config.system.build.toplevel' or 'nixosConfigurations."thinkpad".config.system.build.toplevel'
Too much copy-pasting w/o thinking here I’m defining the container configuration, I want to build one for the “thinkpad” machine instead. Changing that solves it.
As usual, saying things out loud solves most of the problems. I’m keeping this post here for reference! Thanks and cheers to everyone reading.
sudo nixos-rebuild switch --flake /etc/nixos
warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
updating systemd-boot from (249.7) to (249.5)
Skipping "/boot/EFI/systemd/systemd-bootx64.efi", since a newer boot loader version exists already.
Skipping "/boot/EFI/BOOT/BOOTX64.EFI", since a newer boot loader version exists already.
Traceback (most recent call last):
File "/nix/store/kl48p3k468d8ypp882gj2ndz98z7wdgx-systemd-boot", line 314, in <module>
main()
File "/nix/store/kl48p3k468d8ypp882gj2ndz98z7wdgx-systemd-boot", line 267, in main
subprocess.check_call(["/nix/store/n7shnc1xmriya9djkcvzibw9f6paahxy-systemd-249.5/bin/bootctl", "--path=/boot", "update"])
File "/nix/store/rppr9s436950i1dlzknbmz40m2xqqnxc-python3-3.9.9/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/nix/store/n7shnc1xmriya9djkcvzibw9f6paahxy-systemd-249.5/bin/bootctl', '--path=/boot', 'update']' returned non-zero exit status 1.
warning: error(s) occurred while switching to the new configuration
Any ideas on this one? I mean, I understand the error message but I don’t get it!
I picked branch github:NixOS/nixpkgs/staging-next which mentioned this behaviour and it fixed the issue indeed. I’m on flakes now Thanks @matthewcroughan for the suggestion though.
To have flakes use the system’s pinned set of packages by default. If I do it though in my configuration.nix, using the pkgs passed as module parameter, I get
[dan@thinkpad:/etc/nixos]$ sudo nixos-rebuild switch --flake '.#'
[sudo] password for dan:
warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
error: attribute 'outPath' missing
at /nix/store/vmzh4cjf7pa8sq06cj5j7l73g5nk3pir-source/nixos/modules/services/misc/nix-daemon.nix:542:27:
541| ({ type = "path";
542| path = config.flake.outPath;
| ^
543| } // lib.filterAttrs
(use '--show-trace' to show detailed location information)
Any clues? In general, I find it difficult to discover what nix has to offer, i.e. what options are available, what attributes functions expect. This is of course due to the fact that I’m new to this environment and I’m still learning how to move in the documentation; nevertheless, if you have suggestions also on this regard, you’re welcome
Force nix-shell and all of the old Nix tools to use the Nixpkgs in your flake’s input.
Force nix shell to do the same in nix shell nixpkgs#hello for example.
Disable the registry from having impure behavior, like fetching the latest nixpkgs when you say nix-build nixpkgs#hello for example. Otherwise it’s kind of annoying in the same way that nix-channels are.
If you want to do this, you need to make sure that your nixosConfigurations in your flake have specialArgs = { inherit inputs; }; and that your flake’s outputs argument set is able to be referenced by the name inputs using the @ syntax of Nix, like this:
In this example, specialArgs = { inherit inputs; } allows the (import ./common.nix) in modules to use the word inputs to access the nixpkgs defined in outputs = { self, nixpkgs, ... }@inputs:.