Starting out simple. Small.
This commit is contained in:
parent
cde6ba8905
commit
96cc5e9501
5 changed files with 47 additions and 62 deletions
32
README.md
32
README.md
|
|
@ -1,22 +1,28 @@
|
||||||
# Metanix
|
# Metanix
|
||||||
*Declare your infrastructure!*
|
|
||||||
|
_Declare your infrastructure!_
|
||||||
|
|
||||||
**THIS IS STILL IN DESIGN AND EXPERIMENTATION PHASE**
|
**THIS IS STILL IN DESIGN AND EXPERIMENTATION PHASE**
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
Metanix is a nix library designed to allow a central, no-nonsense nix file to be written to allow for a Source of Truth leading to deterministic configuration identifiers like IP addresses, UIDs, GIDs, and enable quickly establishing frameworks for NixOS systems existing within an ecosystem.
|
Metanix is a nix library designed to allow a central, no-nonsense nix file to be written to allow for a Source of Truth leading to deterministic configuration identifiers like IP addresses, UIDs, GIDs, and enable quickly establishing frameworks for NixOS systems existing within an ecosystem.
|
||||||
As such, I am trying to design this system to enable a would-be admin to answer very simple one-word questions. Sort of.
|
As such, I am trying to design this system to enable a would-be admin to answer very simple one-word questions. Sort of.
|
||||||
|
|
||||||
## What?
|
## What?
|
||||||
|
|
||||||
Or, in other words, what systems do you want Metanix to manage or at least be aware of?
|
Or, in other words, what systems do you want Metanix to manage or at least be aware of?
|
||||||
|
|
||||||
## Where?
|
## Where?
|
||||||
|
|
||||||
Or, in other words, what networks and subnets do you have and where do your systems/users belong?
|
Or, in other words, what networks and subnets do you have and where do your systems/users belong?
|
||||||
|
|
||||||
## Who?
|
## Who?
|
||||||
|
|
||||||
Or, in other words, who are your users?
|
Or, in other words, who are your users?
|
||||||
|
|
||||||
## How?
|
## How?
|
||||||
|
|
||||||
Or, in other words, what kind of access control groups do you want or need to best control how everything is used.
|
Or, in other words, what kind of access control groups do you want or need to best control how everything is used.
|
||||||
|
|
||||||
## Enter: THINGS
|
## Enter: THINGS
|
||||||
|
|
@ -119,28 +125,32 @@ More on each of these categories of things later.
|
||||||
role = "infrastructure";
|
role = "infrastructure";
|
||||||
tags = [ "router" "linode" ];
|
tags = [ "router" "linode" ];
|
||||||
services = [ "nginx-proxy" "headscale" ];
|
services = [ "nginx-proxy" "headscale" ];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
metatron = {
|
metatron = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
nixOS = true;
|
nixOS = true;
|
||||||
role = "server";
|
role = "server";
|
||||||
tags = ["server" "linode" "upstream"];
|
tags = ["server" "linode" "upstream"];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
io = {
|
io = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
nixOS = true;
|
nixOS = true;
|
||||||
role = "infrastructure";
|
role = "infrastructure";
|
||||||
tags = ["router" "downstream"];
|
tags = ["router" "downstream"];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
europa = {
|
europa = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
nixOS = true;
|
nixOS = true;
|
||||||
role = "infrastructure";
|
role = "infrastructure";
|
||||||
tags = ["router" "downstream"];
|
tags = ["router" "downstream"];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
deimos = {
|
deimos = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
|
|
@ -157,7 +167,8 @@ More on each of these categories of things later.
|
||||||
"forgejo"
|
"forgejo"
|
||||||
"headscale"
|
"headscale"
|
||||||
];
|
];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
phobos = {
|
phobos = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
|
|
@ -171,7 +182,8 @@ More on each of these categories of things later.
|
||||||
"sandbox"
|
"sandbox"
|
||||||
"node-red"
|
"node-red"
|
||||||
];
|
];
|
||||||
config = {...}: { # NixOS config here, or use a path to one. };
|
config = {...}: { # NixOS config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
terra = {
|
terra = {
|
||||||
owner = "yaro";
|
owner = "yaro";
|
||||||
|
|
@ -189,7 +201,8 @@ More on each of these categories of things later.
|
||||||
group = {
|
group = {
|
||||||
userGroups = {
|
userGroups = {
|
||||||
programmers = {
|
programmers = {
|
||||||
config = { ... }: { # Home-manager config here, or use a path to one. };
|
config = { ... }: { # Home-manager config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemGroups = {
|
systemGroups = {
|
||||||
|
|
@ -198,7 +211,8 @@ More on each of these categories of things later.
|
||||||
"nfs"
|
"nfs"
|
||||||
"isci"
|
"isci"
|
||||||
];
|
];
|
||||||
config = { ... }: { # Home-manager config here, or use a path to one. };
|
config = { ... }: { # Home-manager config here, or use a path to one.
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
16
flake.lock
generated
16
flake.lock
generated
|
|
@ -2,18 +2,14 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1752950548,
|
"lastModified": 0,
|
||||||
"narHash": "sha256-NS6BLD0lxOrnCiEOcvQCDVPXafX1/ek1dfJHX1nUIzc=",
|
"narHash": "sha256-NV4S2Lf2hYmZQ3Qf4t/YyyBaJNuxLPyjzvDma0zPp/M=",
|
||||||
"owner": "NixOS",
|
"path": "/nix/store/4878dzkl1bdxv6wqavzy7bdracvl9q16-source",
|
||||||
"repo": "nixpkgs",
|
"type": "path"
|
||||||
"rev": "c87b95e25065c028d31a94f06a62927d18763fdf",
|
|
||||||
"type": "github"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-unstable",
|
"type": "indirect"
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
|
|
|
||||||
1
lib/functions/buildLocationList.nix
Normal file
1
lib/functions/buildLocationList.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
locations: builtins.attrNames locations
|
||||||
|
|
@ -1,45 +1,12 @@
|
||||||
# lib/metanix.nix
|
|
||||||
{ data, lib }:
|
{ data, lib }:
|
||||||
|
|
||||||
let
|
let
|
||||||
buildSystemIndex =
|
indexOf = name: names:
|
||||||
let
|
let
|
||||||
flattenSystems = locationName: subnetName: systems:
|
indexed = builtins.imap0 (i: v: { inherit i v; }) names;
|
||||||
lib.mapAttrsToList
|
matches = builtins.filter (x: x.v == name) indexed;
|
||||||
(systemName: systemCfg: {
|
|
||||||
inherit systemName locationName subnetName;
|
|
||||||
primary = systemCfg.primary or false;
|
|
||||||
macs = systemCfg.macAddresses or [ ];
|
|
||||||
})
|
|
||||||
systems;
|
|
||||||
|
|
||||||
allSystems =
|
|
||||||
builtins.concatLists (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(locationName: location:
|
|
||||||
builtins.concatLists (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(subnetName: subnet:
|
|
||||||
flattenSystems locationName subnetName (subnet.systems or { })
|
|
||||||
)
|
|
||||||
(location.subnets or { })
|
|
||||||
)
|
|
||||||
)
|
|
||||||
data.locations
|
|
||||||
);
|
|
||||||
in
|
in
|
||||||
builtins.foldl'
|
if matches == [ ] then null else (builtins.head matches).i;
|
||||||
(acc: entry:
|
|
||||||
let
|
|
||||||
existing = acc.${entry.systemName} or [ ];
|
|
||||||
in
|
|
||||||
acc // {
|
|
||||||
${entry.systemName} = existing ++ [ builtins.removeAttrs entry [ "systemName" ] ];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
allSystems;
|
|
||||||
in
|
in
|
||||||
{
|
{ indexOf = indexOf; }
|
||||||
inherit buildSystemIndex;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
7
test/test-buildLocationList.nix
Normal file
7
test/test-buildLocationList.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
let
|
||||||
|
buildLocationList = import ../lib/functions/buildLocationList.nix;
|
||||||
|
sampleData = import ./meta.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
result = buildLocationList sampleData.locations;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue