2023-01-12 21:10:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
description = "Deployment for skynet";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
# gonna start off with a fairly modern base
|
2023-01-12 21:35:12 +00:00
|
|
|
nixpkgs.url = "nixpkgs/nixos-22.11";
|
2023-01-12 21:10:17 +00:00
|
|
|
|
|
|
|
# utility stuff
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
agenix.url = "github:ryantm/agenix";
|
|
|
|
deploy-rs.url = "github:serokell/deploy-rs";
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-01-12 23:58:35 +00:00
|
|
|
outputs = { self, nixpkgs, deploy-rs, ... }: let
|
|
|
|
|
2023-01-13 00:33:28 +00:00
|
|
|
# can centralise the config for each machiene here
|
2023-01-12 23:58:35 +00:00
|
|
|
machine_config = [
|
|
|
|
# each system one line
|
|
|
|
{
|
2023-01-13 00:33:28 +00:00
|
|
|
# each machiene must have a name
|
2023-01-12 23:58:35 +00:00
|
|
|
name = "test01";
|
2023-01-13 00:33:28 +00:00
|
|
|
|
|
|
|
# core info about it
|
2023-01-12 23:58:35 +00:00
|
|
|
system = "x86_64-linux";
|
|
|
|
modules = [
|
|
|
|
./machines/base.nix
|
|
|
|
];
|
2023-01-13 00:14:44 +00:00
|
|
|
|
2023-01-13 00:33:28 +00:00
|
|
|
# for the deployment
|
2023-01-13 00:14:44 +00:00
|
|
|
hostname = "test01.home.brendan.ie";
|
|
|
|
sshUser = "root";
|
2023-01-12 23:58:35 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# the best part, nix is functional, so lets have some functions
|
|
|
|
|
|
|
|
# map applies this function to every item in an array
|
|
|
|
create_nixosConfigurations = map (
|
|
|
|
# converts it into {name_of_machiene = {system = '..'; modules = '..'}}
|
2023-01-13 00:02:41 +00:00
|
|
|
config: {
|
|
|
|
# need to extract teh name of the machiene
|
|
|
|
${config.name} = (
|
|
|
|
# nixpkgs.lib.nixosSystem is a fucntion that is used to turn a attribute set into the config for a machiene
|
2023-01-13 00:10:56 +00:00
|
|
|
nixpkgs.lib.nixosSystem {
|
|
|
|
system = config.system;
|
2023-01-13 00:14:09 +00:00
|
|
|
modules = config.modules;
|
2023-01-13 00:10:56 +00:00
|
|
|
}
|
2023-01-13 00:02:41 +00:00
|
|
|
);
|
|
|
|
}
|
2023-01-12 23:58:35 +00:00
|
|
|
);
|
|
|
|
|
2023-01-13 00:33:28 +00:00
|
|
|
# this takes the config attributes and turns it into something useful for the nodes
|
2023-01-13 00:14:44 +00:00
|
|
|
create_nodes = map (
|
2023-01-13 00:33:28 +00:00
|
|
|
# this is fairly simple, just plug in teh values
|
2023-01-13 00:14:44 +00:00
|
|
|
config: {
|
|
|
|
${config.name} = {
|
|
|
|
hostname = config.hostname;
|
|
|
|
profiles.system = {
|
|
|
|
path = deploy-rs.lib."${config.system}".activate.nixos self.nixosConfigurations."${config.name}";
|
|
|
|
sshUser = config.sshUser;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-13 00:33:28 +00:00
|
|
|
# this merges together an array of atributes into just one set
|
2023-01-12 23:58:35 +00:00
|
|
|
merge = nixpkgs.lib.lists.foldl (a: b: a // b) {};
|
|
|
|
|
|
|
|
in {
|
2023-01-13 00:33:28 +00:00
|
|
|
# values created using the data and functions above
|
2023-01-12 23:58:35 +00:00
|
|
|
nixosConfigurations = merge (create_nixosConfigurations machine_config);
|
2023-01-13 00:14:44 +00:00
|
|
|
deploy.nodes = merge (create_nodes machine_config);
|
2023-01-12 21:10:17 +00:00
|
|
|
|
|
|
|
# This is highly advised, and will prevent many possible mistakes
|
|
|
|
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|