How to select packages and configs based on flag

Hi all, apologies if this has been asked before but I haven’t been successful in finding an answer.

I want to share a nix flake with several different machines. Some machines will have a DE, some are a VM with terminal only.

How can I conditionally add / enable packages and features based on whether it has a GUI or not?

Specifically on a DE I’d install and enable things like: plasma, alacrity, gimp, etc

In a headless VM I wouldn’t need any of those

this may be of help NixOS Specialisations - How do you use them? - #14 by 7c6f434c

then again it may not be exactly what your using for.

i tend to move out ‘machine specific configuration’ into it’s own .nix file

if your using flakes, you use the modules part to import it.

However, how please lay out their configuration files fo nix, is really up to the user.

However, there are some great examples out there on the internet, you can use sourcegraph.com
with lang:nix configuration.nix to find lots and lots and lots of examples.

  nixosConfigurations = {
    acoolmachine = nixpkgs.lib.nixosSystem
      {
        system = "x86_64-linux";
        modules = [
          ./config/users/commander.nix
          ./config/configuration.nix
          #./obs-box/obs-box.nix
          ./config/environments/i3wm.nix
          ./config/environments/video_call_streaming.nix
          ./config/modifier_imports/zfs.nix

]
… … . . … .blah blah rest of the flake.

1 Like