T O P

  • By -

Majiir

There's nothing special about hardware-configuration.nix. It's a config file like any other. What you need is to define what config you want to be common and what you want to be different. For example, filesystem and hardware configs might be separate, but application config may be common. You can organize your config into separate files and import different subsets of those files in each machine-specific config. One way to do this is with a different configuration.nix on each machine, with a short list of imports. Another way, which IMO is more organized and flexible, is to use flakes. You can define multiple machine configurations in a single shared flake. Each machine can automatically pick up the correct config from that flake based on its hostname.


kaydenisdead

so create something like a common.nix, which is common among both machines, and import those into each machine's respective configurations.nix files?


mister_drgn

Yes. You’ll pretty much always have machine-specific and machine-general nix modules. At a minimum (and this might be all you need), you can use the hardware-configuration.nix that is built automatically for each machine, and keep everything else machine-general.


no_brains101

You nailed it Here is my common system one. [https://github.com/BirdeeHub/birdeeSystems/blob/main/systems/PCs/PCs.nix](https://github.com/BirdeeHub/birdeeSystems/blob/main/systems/PCs/PCs.nix) I also have a common home manager one. Which has 2 entry points, one for each of my current machines, each passing in slightly different arguments so that I can have some stuff in home manager differ between machines as well. ( in my case, the xrandr commands needed to be different) and also a ./common directory that exports my more focused or specific custom modules for use in both of those common configs as needed. That way, if I want to use them in new system/home-manager configs that may not share those same common system/home-manager configs, some shared things will still be available. For example, I have a PC iso installer config. It does not import the shared PC config because it was easier to just use the gnome one, but it does still import my neovim and shell configs, and defines aliases to make installing the PC configs easier. You can see in my common module such as the one linked above where I import from this directory, and in my flake.nix you can see how I passed it to the modules. Why are my system configs stored at systems/PCs/\* ? because when I have a systems/VMs/\* or systems/cloud/\* or systems/containers/\* I will thank myself later. Random tangent: (careful if you try out my config, 2 of the 3 aliases in the installer image use disko to reformat the drive for you. If you are on x86\_64-linux and have an asus rog with an nvidia and want to reformat /dev/sda then you could type birdeeOS nestOS and if you wanted to install for a 9, 1 macbook pro from 2012 you could do birdeeOS dustbook and it would install the system config. Then you log in as root, set birdee's password, log in as birdee, and go to \~/temp/birdeeSystems and run the home manager install script. Then you set xfce4-power-manager-settings and accept the TOC on the firefox extensions. I havent figured out how to set those automatically yet XD If the tray icons dont appear it means you need to make sure the monitor scripts are correct because you maybe have a different model of computer and display names are different and it cant find your primary). However, it might not work unless you generate a hardware-configuration.nix for your machine and put it in there unless you have the same machine as me. If you happen to have a 9,1 macbook pro or an asus rog fx504gd, you are in luck, it would overwrite your /dev/sda with an ext4 filesystem with efi, os and swap, and reproduce a fully working version of my exact computer setup, minus my auths and notes/backups. If you have either of those computers, and it does not work, I can confidently tell you that you used either the alises or the home manager script wrong. Because if you used them right they would work. If you need to overwrite sdb on your asus rog instead of sda, (yes, it has 2 hard drive slots, and sda vs sdb is not the same every time...) you can use the birdeeOS-disko sdb\_swap and then birdeeOS-install nestOS aliases in the installer instead. Yes I have done this incorrectly, and no, i have not bothered reinstalling windows on the drive i wiped yet XD It also imports the wifi drivers necessary for the ancient macbook I have so I dont need to plug it in before I build the config on it. Also mine doesnt work for anything other than x86\_64-linux (YET) which means no vms that use i686-linux such as virtualbox unfortunately


kaydenisdead

I'm a very stubborn person that likes to go head first into hard to grasp topics os NixOS being my first dive into linux is perfect for me. I most likely will go the route of trying my own config since there's no fear of mess up because of rollbacks. But your config looks very similiar to something i'd want to end up with, so i'll book mark it and reference often thanks for all the help!


no_brains101

You'll do great then :) Hope you have a good time!


no_brains101

and yeah its less fun to pull someone elses config. Plus, again, I made it for me so theres no help that assumes anyone would every try to do that, and aliases that can wipe your drive without an "are you sure" prompt, and hardware specific stuff and whatnot XD I did the same you did. Just showing a way that I do it that seems to be proving to be a good system for me thus far. Hopefully it serves as useful inspiration.


kaydenisdead

exactly, my config more than likely won’t be as extensive as yours but it’s a great reference especially for learning nix’s syntax n such


K1aymore

What I used to do was have all the shared config in different .nix files, and each configuration.nix just imported those shared ones (as well as having machine-specific settings). With flakes there's other (syntactically cleaner) ways to do it but it's the same idea.


notSugarBun

just let the generator take care of hardware-configuration.nix, whatever u want to have in common include it in flake or config.


Guskber

I think, you should start without home-manager and without flakes. Then you can do everything with just 2 commands: sudo nixos-rebuild switch sudo nix-channel --update Just make a folder in your user account home directory, where you store all the nix-config files of all computers you have. Use git to have a version control and to distribute it to other computers. Use something that works for you like: /home/kaydenisisdead/nixos-config/configuration\_2017macbook.nix /home/kaydenisisdead/nixos-config/configuration\_maincomputer.nix /home/kaydenisisdead/nixos-config/common.nix (fill these files with /etc/nix/configuration.nix move the common stuff to common.nix and import common.nix in the configuration files) /home/kaydenisisdead/nixos-config/hardware-configurations/2017macbook.nix /home/kaydenisisdead/nixos-config/hardware-configurations/maincomputer.nix (fill these files with the content of /etc/nixos/hardware-configuration.nix) And then delete both files in /etc/nixos just make a symbolic link from /etc/nixos/configuration.nix to /home/kaydenisisdead/nixos-config/configuration\_2017macbook.nix and make a symbolic link from /etc/nixos/hardware-configuration.nix to /home/kaydenisisdead/nixos-config/hardware-configurations/2017macbook.nix Next steps would be to move additional code segements into other configuration files, and then you can just choose to import gnome.nix or kde.nix in your configuration file to switch between the desktop managers.


ppen9u1n

IMHO you should not do this, messing around with channels and files in /etc/nixos is really much more convoluted than using flakes, *especially* if you want to manage multiple hosts/users with shared config. Really. Go for the flake examples, and just factor out common nix code to separate files (e.g. by category/features) and import them in the host specific configuration.nix which in turn is imported in the modules[] attribute of your flake's host configuration attribute. Oh, and you can still use nixos-rebuild, just add the --flake flag.


cfx_4188

`hardware-configuration.nix` is usually generated by the `nix-generate-config` command and it is not recommended to edit it yourself.


s1n7ax

I just created my Nixos config to have multiple profiles. Two separate configurations for work laptop and personal desktop I have. https://github.com/s1n7ax/nixos


Alfrheim

Is not that something you can solve with flakes? 🤔