mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
config: make platforms as a list for users and images
The `images` output attribute is now similar to packages as an attribute set of packages with their platforms as the first level.
This commit is contained in:
parent
25cf8a9af4
commit
f282aa2066
112
flake.nix
112
flake.nix
@ -83,7 +83,7 @@
|
||||
users = lib'.importTOML ./users.toml;
|
||||
|
||||
# A set of image-related utilities for the flake outputs.
|
||||
inherit (import ./lib/images.nix { inherit inputs; lib = lib'; }) mkHost mkHome mkImage;
|
||||
inherit (import ./lib/images.nix { inherit inputs; lib = lib'; }) mkHost mkHome mkImage listImagesWithSystems;
|
||||
|
||||
# The order here is important(?).
|
||||
overlays = [
|
||||
@ -294,30 +294,35 @@
|
||||
|
||||
# A list of NixOS configurations from the `./hosts` folder. It also has
|
||||
# some sensible default configurations.
|
||||
nixosConfigurations = lib'.mapAttrs
|
||||
(host: metadata:
|
||||
let
|
||||
path = ./hosts/${host};
|
||||
extraModules = [
|
||||
({ lib, ... }: {
|
||||
config = lib.mkMerge [
|
||||
{ networking.hostName = metadata.hostname or host; }
|
||||
nixosConfigurations =
|
||||
let
|
||||
images' = listImagesWithSystems images;
|
||||
in
|
||||
lib'.mapAttrs
|
||||
(_: host:
|
||||
let
|
||||
name = host._name;
|
||||
path = ./hosts/${name};
|
||||
extraModules = [
|
||||
({ lib, ... }: {
|
||||
config = lib.mkMerge [
|
||||
{ networking.hostName = lib.mkForce name; }
|
||||
|
||||
(lib.mkIf (metadata ? domain)
|
||||
{ networking.domain = metadata.domain; })
|
||||
];
|
||||
})
|
||||
(lib.mkIf (host ? domain)
|
||||
{ networking.domain = lib.mkForce host.domain; })
|
||||
];
|
||||
})
|
||||
|
||||
hostSharedConfig
|
||||
path
|
||||
];
|
||||
in
|
||||
mkHost {
|
||||
inherit extraModules extraArgs;
|
||||
system = metadata.system or defaultSystem;
|
||||
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||
})
|
||||
(lib'.filterAttrs (name: host: (host.format or "iso") == "iso") images);
|
||||
hostSharedConfig
|
||||
path
|
||||
];
|
||||
in
|
||||
mkHost {
|
||||
inherit extraModules extraArgs;
|
||||
system = host._system;
|
||||
nixpkgs-channel = host.nixpkgs-channel or "nixpkgs";
|
||||
})
|
||||
(lib'.filterAttrs (_: host: (host.format or "iso") == "iso") images');
|
||||
|
||||
# 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.
|
||||
@ -325,10 +330,15 @@
|
||||
|
||||
# I can now install home-manager users in non-NixOS systems.
|
||||
# NICE!
|
||||
homeConfigurations = lib'.mapAttrs
|
||||
homeConfigurations =
|
||||
let
|
||||
users' = listImagesWithSystems users;
|
||||
in
|
||||
lib'.mapAttrs
|
||||
(name: metadata:
|
||||
let
|
||||
system = metadata.system or defaultSystem;
|
||||
name = metadata._name;
|
||||
system = metadata._system;
|
||||
pkgs = import inputs."${metadata.nixpkgs-channel or "nixpkgs"}" {
|
||||
inherit system overlays;
|
||||
};
|
||||
@ -359,7 +369,7 @@
|
||||
inherit pkgs system extraModules extraArgs;
|
||||
home-manager-channel = metadata.home-manager-channel or "home-manager";
|
||||
})
|
||||
users;
|
||||
users';
|
||||
|
||||
# Extending home-manager with my custom modules, if anyone cares.
|
||||
homeModules =
|
||||
@ -386,30 +396,34 @@
|
||||
# somewhere else including those NixOS configurations that are built as
|
||||
# an ISO.
|
||||
images =
|
||||
lib'.mapAttrs
|
||||
(host: metadata:
|
||||
let
|
||||
system = metadata.system or defaultSystem;
|
||||
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||
pkgs = import inputs."${nixpkgs-channel}" { inherit system overlays; };
|
||||
format = metadata.format or "iso";
|
||||
in
|
||||
mkImage {
|
||||
inherit format system pkgs extraArgs;
|
||||
extraModules = [
|
||||
({ lib, ... }: {
|
||||
config = lib.mkMerge [
|
||||
{ networking.hostName = lib.mkForce metadata.hostname or host; }
|
||||
forAllSystems (system:
|
||||
let
|
||||
images' = lib'.filterAttrs (host: metadata: lib'.elem system metadata.systems) images;
|
||||
in
|
||||
lib'.mapAttrs
|
||||
(host: metadata:
|
||||
let
|
||||
inherit system;
|
||||
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||
pkgs = import inputs."${nixpkgs-channel}" { inherit system overlays; };
|
||||
format = metadata.format or "iso";
|
||||
in
|
||||
mkImage {
|
||||
inherit format system pkgs extraArgs;
|
||||
extraModules = [
|
||||
({ lib, ... }: {
|
||||
config = lib.mkMerge [
|
||||
{ networking.hostName = lib.mkForce metadata.hostname or host; }
|
||||
|
||||
(lib.mkIf (metadata ? domain)
|
||||
{ networking.domain = lib.mkForce metadata.domain; })
|
||||
];
|
||||
})
|
||||
hostSharedConfig
|
||||
./hosts/${host}
|
||||
];
|
||||
})
|
||||
images;
|
||||
(lib.mkIf (metadata ? domain)
|
||||
{ networking.domain = lib.mkForce metadata.domain; })
|
||||
];
|
||||
})
|
||||
hostSharedConfig
|
||||
./hosts/${host}
|
||||
];
|
||||
})
|
||||
images');
|
||||
|
||||
# My several development shells for usual type of projects. This is much
|
||||
# more preferable than installing all of the packages at the system
|
||||
|
17
images.toml
17
images.toml
@ -8,13 +8,12 @@
|
||||
#
|
||||
# Take note, any images with the "iso" format is essentially made to be
|
||||
# deployed somewhere (e.g., desktop, homelab server, VPS).
|
||||
|
||||
[ni]
|
||||
system = "x86_64-linux"
|
||||
systems = [ "x86_64-linux" ]
|
||||
format = "iso"
|
||||
|
||||
[plover]
|
||||
system = "x86_64-linux"
|
||||
systems = [ "x86_64-linux" ]
|
||||
format = "iso"
|
||||
domain = "foodogsquared.one"
|
||||
|
||||
@ -24,14 +23,20 @@ auto-rollback = true
|
||||
magic-rollback = true
|
||||
|
||||
[void]
|
||||
system = "x86_64-linux"
|
||||
systems = [ "x86_64-linux" ]
|
||||
format = "vm"
|
||||
|
||||
[bootstrap]
|
||||
system = "x86_64-linux"
|
||||
systems = [
|
||||
"aarch64-linux",
|
||||
"x86_64-linux",
|
||||
]
|
||||
format = "install-iso"
|
||||
nixpkgs-channel = "nixos-unstable-small"
|
||||
|
||||
[graphical-installer]
|
||||
system = "x86_64-linux"
|
||||
systems = [
|
||||
"aarch64-linux",
|
||||
"x86_64-linux",
|
||||
]
|
||||
format = "install-iso"
|
||||
|
@ -42,4 +42,30 @@
|
||||
# Our own modules.
|
||||
++ extraModules;
|
||||
};
|
||||
|
||||
listImagesWithSystems = data:
|
||||
lib.foldlAttrs
|
||||
(acc: name: metadata:
|
||||
let
|
||||
name' = metadata.hostname or name;
|
||||
in
|
||||
if lib.length metadata.systems > 1 then
|
||||
acc // (lib.foldl
|
||||
(images: system: images // {
|
||||
"${name'}-${system}" = metadata // {
|
||||
_system = system;
|
||||
_name = name';
|
||||
};
|
||||
})
|
||||
{}
|
||||
metadata.systems)
|
||||
else
|
||||
acc // {
|
||||
"${name'}" = metadata // {
|
||||
_system = lib.head metadata.systems;
|
||||
_name = name';
|
||||
};
|
||||
})
|
||||
{}
|
||||
data;
|
||||
}
|
||||
|
@ -2,7 +2,10 @@
|
||||
# of the users defined here should correspond to one of the home-manager users
|
||||
# at `./users/home-manager/`.
|
||||
[foo-dogsquared]
|
||||
system = "x86_64-linux"
|
||||
systems = [
|
||||
"aarch64-linux",
|
||||
"x86_64-linux",
|
||||
]
|
||||
|
||||
[plover]
|
||||
system = "x86_64-linux"
|
||||
systems = [ "x86_64-linux" ]
|
||||
|
Loading…
Reference in New Issue
Block a user