From 8e9d566d10a772ef84ebf4015c7c9bd54737ac69 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Sun, 28 Jan 2024 13:57:36 +0100 Subject: [PATCH] simplify flake functions --- flake.nix | 17 ++++++----------- nixos/machines/default.nix | 12 +++++------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 78448b3..8af709c 100644 --- a/flake.nix +++ b/flake.nix @@ -40,20 +40,15 @@ pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; machines = import ./nixos/machines; physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines; - # TODO: Use mergeAttrLists mkNixosSystems = systemDef: - nixpkgs.lib.foldlAttrs - (acc: name: machine: - acc // { - "${name}" = nixpkgs.lib.nixosSystem (systemDef name machine); - }) - { } + builtins.mapAttrs + (name: machine: + nixpkgs.lib.nixosSystem (systemDef name machine) + ) physicalMachines; mkDeployNodes = nodeDef: - # TODO: Use mergeAttrLists - nixpkgs.lib.foldlAttrs - (acc: name: machine: acc // { "${name}" = nodeDef name machine; }) - { } + builtins.mapAttrs + (name: machine: nodeDef name machine) physicalMachines; in { diff --git a/nixos/machines/default.nix b/nixos/machines/default.nix index fb4eac4..649ef3d 100644 --- a/nixos/machines/default.nix +++ b/nixos/machines/default.nix @@ -1,6 +1,5 @@ { jefke = { - # TODO: model this in a nixos module? type = "physical"; nixosModule = { @@ -57,7 +56,7 @@ lewis = { type = "physical"; - nixosModule = { pkgs, ... }: { + nixosModule = { networking.hostName = "lewis"; lab = { @@ -81,14 +80,13 @@ type = "virtual"; hypervisorName = "lewis"; - nixosModule = { pkgs, config, ... }: { + nixosModule = { pkgs, ... }: { + networking.hostName = "my-microvm"; + lab.vmMacAddress = "BA:DB:EE:F0:00:00"; + programs.bash.interactiveShellInit = '' echo "Hello world from inside a virtual machine!!" | ${pkgs.lolcat}/bin/lolcat ''; - - networking.hostName = "my-microvm"; - - lab.vmMacAddress = "BA:DB:EE:F0:00:00"; }; }; }