feat: basic setup for colmena
This commit is contained in:
parent
53aff5987f
commit
c5f1bedec4
4 changed files with 21 additions and 148 deletions
87
flake.nix
87
flake.nix
|
@ -9,86 +9,27 @@
|
|||
# utility stuff
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
agenix.url = "github:ryantm/agenix";
|
||||
deploy-rs.url = "github:serokell/deploy-rs";
|
||||
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, deploy-rs, ... }: let
|
||||
outputs = { self, nixpkgs, ... }: {
|
||||
# https://github.com/zhaofengli/colmena
|
||||
colmena = {
|
||||
meta = {
|
||||
nixpkgs = import nixpkgs {
|
||||
system = "x86_64-linux";
|
||||
overlays = [];
|
||||
};
|
||||
};
|
||||
|
||||
# can centralise the config for each machiene here
|
||||
machine_config = [
|
||||
# each system one line
|
||||
{
|
||||
# each machiene must have a name
|
||||
name = "test01";
|
||||
# installed for each machine
|
||||
defaults = import ./machines/base.nix;
|
||||
|
||||
# core info about it
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
./machines/test01.nix
|
||||
];
|
||||
test01 = import ./machines/test01.nix;
|
||||
|
||||
# for the deployment
|
||||
hostname = "test01.home.brendan.ie";
|
||||
sshUser = "root";
|
||||
}
|
||||
{
|
||||
# each machiene must have a name
|
||||
name = "test02";
|
||||
test02 = import ./machines/test02.nix;
|
||||
|
||||
# core info about it
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
./machines/test02.nix
|
||||
];
|
||||
|
||||
# for the deployment
|
||||
hostname = "test02.home.brendan.ie";
|
||||
sshUser = "root";
|
||||
}
|
||||
];
|
||||
|
||||
# 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 = '..'}}
|
||||
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
|
||||
nixpkgs.lib.nixosSystem {
|
||||
system = config.system;
|
||||
modules = config.modules;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
# this takes the config attributes and turns it into something useful for the nodes
|
||||
create_nodes = map (
|
||||
# this is fairly simple, just plug in teh values
|
||||
config: {
|
||||
${config.name} = {
|
||||
hostname = config.hostname;
|
||||
profiles.system = {
|
||||
path = deploy-rs.lib."${config.system}".activate.nixos self.nixosConfigurations."${config.name}";
|
||||
sshUser = config.sshUser;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# this merges together an array of atributes into just one set
|
||||
merge = nixpkgs.lib.lists.foldl (a: b: a // b) {};
|
||||
|
||||
in {
|
||||
# values created using the data and functions above
|
||||
nixosConfigurations = merge (create_nixosConfigurations machine_config);
|
||||
deploy.nodes = merge (create_nodes machine_config);
|
||||
|
||||
# This is highly advised, and will prevent many possible mistakes
|
||||
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue