mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
config: fix shared config for nixosConfigurations and images
This commit is contained in:
parent
c442f22735
commit
e45fad294e
80
flake.nix
80
flake.nix
@ -88,10 +88,10 @@
|
|||||||
# A set of images with their metadata that is usually built for usual
|
# A set of images with their metadata that is usually built for usual
|
||||||
# purposes. The format used here is whatever formats nixos-generators
|
# purposes. The format used here is whatever formats nixos-generators
|
||||||
# support.
|
# support.
|
||||||
images = listImagesWithSystems (lib'.importTOML ./images.toml);
|
images = lib'.importTOML ./images.toml;
|
||||||
|
|
||||||
# A set of users with their metadata to be deployed with home-manager.
|
# A set of users with their metadata to be deployed with home-manager.
|
||||||
users = listImagesWithSystems (lib'.importTOML ./users.toml);
|
users = lib'.importTOML ./users.toml;
|
||||||
|
|
||||||
# A set of image-related utilities for the flake outputs.
|
# A set of image-related utilities for the flake outputs.
|
||||||
inherit (import ./lib/images.nix { inherit inputs; lib = lib'; }) mkHost mkHome mkImage listImagesWithSystems;
|
inherit (import ./lib/images.nix { inherit inputs; lib = lib'; }) mkHost mkHome mkImage listImagesWithSystems;
|
||||||
@ -160,12 +160,11 @@
|
|||||||
|
|
||||||
# Then, make the most with the modules from the flake inputs. Take
|
# Then, make the most with the modules from the flake inputs. Take
|
||||||
# note importing some modules such as home-manager are as part of the
|
# note importing some modules such as home-manager are as part of the
|
||||||
# declarative host config so be sure to check out nixosConfigurations
|
# declarative host config so be sure to check out
|
||||||
# output as well.
|
# `hostSpecificModule` function as well.
|
||||||
++ [
|
++ [
|
||||||
inputs.nur.nixosModules.nur
|
inputs.nur.nixosModules.nur
|
||||||
inputs.sops-nix.nixosModules.sops
|
inputs.sops-nix.nixosModules.sops
|
||||||
inputs.guix-overlay.nixosModules.guix
|
|
||||||
inputs.disko.nixosModules.disko
|
inputs.disko.nixosModules.disko
|
||||||
inputs.nix-index-database.nixosModules.nix-index
|
inputs.nix-index-database.nixosModules.nix-index
|
||||||
inputs.nixos-wsl.nixosModules.default
|
inputs.nixos-wsl.nixosModules.default
|
||||||
@ -341,6 +340,25 @@
|
|||||||
# here.
|
# here.
|
||||||
nixpkgs.overlays = overlays;
|
nixpkgs.overlays = overlays;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# A function that generates a Nix module from host metadata.
|
||||||
|
hostSpecificModule = host: metadata:
|
||||||
|
{ lib, ... }: {
|
||||||
|
imports = [
|
||||||
|
inputs.${metadata.home-manager-channel or "home-manager"}.nixosModules.home-manager
|
||||||
|
|
||||||
|
hostSharedConfig
|
||||||
|
nixSettingsSharedConfig
|
||||||
|
./hosts/${host}
|
||||||
|
];
|
||||||
|
|
||||||
|
config = lib.mkMerge [
|
||||||
|
{ networking.hostName = lib.mkForce metadata.hostname or host; }
|
||||||
|
|
||||||
|
(lib.mkIf (metadata ? domain)
|
||||||
|
{ networking.domain = lib.mkForce metadata.domain; })
|
||||||
|
];
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Exposes only my library with the custom functions to make it easier to
|
# Exposes only my library with the custom functions to make it easier to
|
||||||
@ -351,34 +369,14 @@
|
|||||||
# some sensible default configurations.
|
# some sensible default configurations.
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
lib'.mapAttrs
|
lib'.mapAttrs
|
||||||
(filename: host:
|
(host: metadata:
|
||||||
let
|
|
||||||
path = ./hosts/${filename};
|
|
||||||
extraModules = [
|
|
||||||
({ lib, ... }: {
|
|
||||||
imports = [
|
|
||||||
inputs.${host.home-manager-channel or "home-manager"}.nixosModules.home-manager
|
|
||||||
];
|
|
||||||
|
|
||||||
config = lib.mkMerge [
|
|
||||||
{ networking.hostName = lib.mkForce host._name; }
|
|
||||||
|
|
||||||
(lib.mkIf (host ? domain)
|
|
||||||
{ networking.domain = lib.mkForce host.domain; })
|
|
||||||
];
|
|
||||||
})
|
|
||||||
|
|
||||||
hostSharedConfig
|
|
||||||
nixSettingsSharedConfig
|
|
||||||
path
|
|
||||||
];
|
|
||||||
in
|
|
||||||
mkHost {
|
mkHost {
|
||||||
inherit extraModules extraArgs;
|
inherit extraArgs;
|
||||||
system = host._system;
|
extraModules = [(hostSpecificModule host metadata)];
|
||||||
nixpkgs-channel = host.nixpkgs-channel or "nixpkgs";
|
system = metadata._system;
|
||||||
|
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||||
})
|
})
|
||||||
(lib'.filterAttrs (_: host: (host.format or "iso") == "iso") images);
|
(listImagesWithSystems images);
|
||||||
|
|
||||||
# We're going to make our custom modules available for our flake. Whether
|
# We're going to make our custom modules available for our flake. Whether
|
||||||
# or not this is a good thing is debatable, I just want to test it.
|
# or not this is a good thing is debatable, I just want to test it.
|
||||||
@ -392,7 +390,7 @@
|
|||||||
let
|
let
|
||||||
name = metadata._name;
|
name = metadata._name;
|
||||||
system = metadata._system;
|
system = metadata._system;
|
||||||
pkgs = inputs."${metadata.nixpkgs-channel or "nixpkgs"}".legacyPackages."${system}";
|
pkgs = inputs.${metadata.nixpkgs-channel or "nixpkgs"}.legacyPackages.${system};
|
||||||
path = ./users/home-manager/${name};
|
path = ./users/home-manager/${name};
|
||||||
extraModules = [
|
extraModules = [
|
||||||
({ pkgs, config, ... }: {
|
({ pkgs, config, ... }: {
|
||||||
@ -454,31 +452,19 @@
|
|||||||
images =
|
images =
|
||||||
forAllSystems (system:
|
forAllSystems (system:
|
||||||
let
|
let
|
||||||
images' = lib'.filterAttrs (host: metadata: system == metadata._system) images;
|
images' = lib'.filterAttrs (host: metadata: system == metadata._system) (listImagesWithSystems images);
|
||||||
in
|
in
|
||||||
lib'.mapAttrs'
|
lib'.mapAttrs'
|
||||||
(host: metadata:
|
(host: metadata:
|
||||||
let
|
let
|
||||||
inherit system;
|
|
||||||
name = metadata._name;
|
name = metadata._name;
|
||||||
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||||
pkgs = import inputs."${nixpkgs-channel}" { inherit system overlays; };
|
pkgs = import inputs.${nixpkgs-channel} { inherit system overlays; };
|
||||||
format = metadata.format or "iso";
|
format = metadata.format or "iso";
|
||||||
in
|
in
|
||||||
lib'.nameValuePair name (mkImage {
|
lib'.nameValuePair name (mkImage {
|
||||||
inherit format system pkgs extraArgs;
|
inherit format system pkgs extraArgs;
|
||||||
extraModules = [
|
extraModules = [(hostSpecificModule host metadata)];
|
||||||
({ lib, ... }: {
|
|
||||||
config = lib.mkMerge [
|
|
||||||
{ networking.hostName = lib.mkForce metadata.hostname or name; }
|
|
||||||
|
|
||||||
(lib.mkIf (metadata ? domain)
|
|
||||||
{ networking.domain = lib.mkForce metadata.domain; })
|
|
||||||
];
|
|
||||||
})
|
|
||||||
hostSharedConfig
|
|
||||||
./hosts/${name}
|
|
||||||
];
|
|
||||||
}))
|
}))
|
||||||
images');
|
images');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user