Skip to content
IT related

CMHSPRIOR-Nix

Updated 3 min read

CMHSPRIOR and Derivatives


Explaining

Theory

This document is about the standardised NixOS Flake configuration located here.

The idea being that we have uniformity accross the systems by having them pull from the same configuration files, however we have some manipulation of each host individually too.

System packages will all be the samem, but the hostnames and IP addresses need to be different.

Using what we learnt from building MASTER-NIX. If you havn't read the above, then go start there and come back here.

Practice

Folder structure:

- flake.nix
- configuration.nix
- cmhsprior.nix
- cmhsprior2.nix
- cmhsprior3.nix
- .gitignore

In the Flake.nix file you will see 3 (maybe more) entries under nixosConfigurations, this is where we will describe each systems unique information, including the line that tells it to import further confiuration from the relevant chmhsprior.nix. So that when the system is called "CMHSPRIOR2" it will pull configurations from the cmhsprior2.nix.

The configuration.nix is pretty standard basically setting up a normal server with the packages that we want. At the bottom will have some of the custom configurations.

cmhsprior.nix and derivatives have more of the specific configuration for each server. At the moment they are mainly networking related, in the future they will have Xirrix configurations as well.

Deploying with Ansible

In the interest of making deployment of NixOS easier in our workplace I have made a Ansible Playbook.

  1. We need to install NixOS and format the drive how you want.
    I have setup a system with the following info:
    username: ed
    password: alto
    
  2. Run through the installer as normal, once that is complete move to the below.
  3. Login and then cd /etc/nixos/
  4. ip a, list down the IP address of the server we will need it.
  5. sudo nano configuration.nix we are going to edit the system packages section, you need to add python3. Its a requirement for Ansible.
  6. Now we need to enable ssh so that Ansible can access the machine by uncommenting the line services.openssh.enable = true;
  7. So the bottom of your config should look like this:
    environment. systemPackages = with pkgs; [
     # wget
     python3
     ];
     # Some programs need SUID wrappers, can be configured further or are
     started in user sessions.
     # programs.mtr.enable = true;
     # programs.gnupg. agent = {
     enable = true;
     enableSSHSupport = true;
     = };
     
     # List services that you want to enable:
     
     # Enable the OpenSSH daemon.
     services.openssh.enable = true;
    
  8. Save the file and rebuild the config: sudo nixos-rebuild switch
  9. Goto our Ansible github, into the alto/nix-install folder. We need to edit the inventory file.
  10. Change the login details and IP to be the same as the server you just setup.
  11. Now we are ready to run the playbook.
  12. SSH into MASTER-NIX.
  13. cd /home/alto/Ansible/alto/nix-install/
  14. try to ssh into the server you setup, you need to accept the RSA key fingerprint for the remote host before Ansible can run, once you type "yes" you can cancel the command.
  15. run git pull to get the changes you just made from github.
  16. By default it will create a CMHSPRIOR server, use this command ansible-playbook ./main.yml. If you want to make CMHSPRIOR2 or another varient run this: ansible-playbook ./main.yml -e "hostname=CMHSPRIOR2"
  17. It should run through the steps to create this server, it may take a while, there is no progress but you can run top on the remote VM if you want to check the process is working. A process called 'nix' should be using alot of resources.
  18. Once the configuration has been completed you will need to manually reboot the machine, so that all the new configurations can be implemented.
  19. This configuration should then be kept upto date by the server and git pull system timers that are setup.

This basically automates the process of setting up the server and means that we can setup and deploy as many siteservers as needed in very short time. Basically as long as the install itself and the time it takes you to configure the variables in Ansible. Far less time than it would have taken to setup an Ubuntu server with everything required.

IT related RSS feed Published with Oblish

Keyboard shortcuts

/
Search
[
Previous page
]
Next page
?
Show this list
Esc
Close