Reusing parts of a configuration.nix file in a nix-shell

I have a dedicated laptop at home to experiment with NixOS. I created a private gitlab repository to version it and keep track of the changes.

Sometimes I won’t have access to the laptop but I have an idea I want to try out that would require modifying the configuration and then testing it (this generally happens when I’m on lunch break at work :smile:)

I thought of maybe using a nix-shell script on my work laptop to replicate parts of my personal laptop’s config, at least the terminal emulator, shell and commands and TUI tools I use. This would allow me to make changes like adding an extra plugin in my neovim config, quickly test that it works and then commit the new version of the config. I could then pull the changes at home and know it’ll work as expected.

Is this possible and if so, how would I go about it ? Mind you I’m quite new to nix so there may be notions I don’t have that would make this trivial.

Not exactly a nix-shell command, but you might find useful the nixos-rebuild test - useful if you have also NixOS installed on your work laptop. If you use flakes, to manage your nixos configurations, you can use something like nixos-rebuild test /etc/nixos#laptop-config. See also:

https://nixos.wiki/wiki/Flakes#Using_nix_flakes_with_NixOS

If you are interested in simply evaluating a nixpkgs with the overlays defined at /etc/nixos/configuration.nix, there are other examples in the WiKi for that:

https://nixos.wiki/wiki/Overlays#Applying_overlays_automatically

You can use nixos-rebuild build-vm to build a VM using that config. If you break up things a bit (maybe have two top-level configuration files and import all the stuff from common nix files) you can play with your neovim config easily and more comfortably then with a nix-shell.

1 Like