simplify flake functions

This commit is contained in:
Pim Kunis 2024-01-28 13:57:36 +01:00
parent a015290fcf
commit 8e9d566d10
2 changed files with 11 additions and 18 deletions

View file

@ -40,20 +40,15 @@
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
machines = import ./nixos/machines; machines = import ./nixos/machines;
physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines; physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines;
# TODO: Use mergeAttrLists
mkNixosSystems = systemDef: mkNixosSystems = systemDef:
nixpkgs.lib.foldlAttrs builtins.mapAttrs
(acc: name: machine: (name: machine:
acc // { nixpkgs.lib.nixosSystem (systemDef name machine)
"${name}" = nixpkgs.lib.nixosSystem (systemDef name machine); )
})
{ }
physicalMachines; physicalMachines;
mkDeployNodes = nodeDef: mkDeployNodes = nodeDef:
# TODO: Use mergeAttrLists builtins.mapAttrs
nixpkgs.lib.foldlAttrs (name: machine: nodeDef name machine)
(acc: name: machine: acc // { "${name}" = nodeDef name machine; })
{ }
physicalMachines; physicalMachines;
in in
{ {

View file

@ -1,6 +1,5 @@
{ {
jefke = { jefke = {
# TODO: model this in a nixos module?
type = "physical"; type = "physical";
nixosModule = { nixosModule = {
@ -57,7 +56,7 @@
lewis = { lewis = {
type = "physical"; type = "physical";
nixosModule = { pkgs, ... }: { nixosModule = {
networking.hostName = "lewis"; networking.hostName = "lewis";
lab = { lab = {
@ -81,14 +80,13 @@
type = "virtual"; type = "virtual";
hypervisorName = "lewis"; hypervisorName = "lewis";
nixosModule = { pkgs, config, ... }: { nixosModule = { pkgs, ... }: {
networking.hostName = "my-microvm";
lab.vmMacAddress = "BA:DB:EE:F0:00:00";
programs.bash.interactiveShellInit = '' programs.bash.interactiveShellInit = ''
echo "Hello world from inside a virtual machine!!" | ${pkgs.lolcat}/bin/lolcat echo "Hello world from inside a virtual machine!!" | ${pkgs.lolcat}/bin/lolcat
''; '';
networking.hostName = "my-microvm";
lab.vmMacAddress = "BA:DB:EE:F0:00:00";
}; };
}; };
} }