2023-06-20 06:48:38 +00:00
|
|
|
# A set of functions intended for creating images. THis is meant to be imported
|
|
|
|
# for use in flake.nix and nowhere else.
|
|
|
|
{ inputs, lib }:
|
|
|
|
|
2023-12-15 14:05:49 +00:00
|
|
|
let
|
|
|
|
extendLib = self: super:
|
|
|
|
import ./. { lib = super; }
|
|
|
|
// import ./private.nix { lib = self; };
|
|
|
|
in
|
2023-06-20 06:48:38 +00:00
|
|
|
{
|
2023-12-18 10:44:27 +00:00
|
|
|
# A thin wrapper around the NixOS configuration function.
|
2023-12-16 12:02:22 +00:00
|
|
|
mkHost = { extraModules ? [ ], nixpkgs-channel ? "nixpkgs" }:
|
2023-12-16 11:55:47 +00:00
|
|
|
let
|
|
|
|
nixpkgs = inputs.${nixpkgs-channel};
|
2023-12-18 10:44:27 +00:00
|
|
|
|
|
|
|
# Just to be sure, we'll use everything with the given nixpkgs' stdlib.
|
2023-12-16 11:55:47 +00:00
|
|
|
lib' = nixpkgs.lib.extend extendLib;
|
|
|
|
|
|
|
|
# A modified version of `nixosSystem` from nixpkgs flake. There is a
|
|
|
|
# recent change at nixpkgs (at 039f73f134546e59ec6f1b56b4aff5b81d889f64)
|
|
|
|
# that prevents setting our own custom functions so we'll have to
|
|
|
|
# evaluate the NixOS system ourselves.
|
|
|
|
nixosSystem = args: import "${nixpkgs}/nixos/lib/eval-config.nix" args;
|
|
|
|
in
|
|
|
|
(lib'.makeOverridable nixosSystem) {
|
|
|
|
lib = lib';
|
2023-12-16 12:02:22 +00:00
|
|
|
modules = extraModules;
|
2023-12-19 04:41:03 +00:00
|
|
|
|
|
|
|
# Since we're setting it through nixpkgs.hostPlatform, we'll have to pass
|
|
|
|
# this as null.
|
|
|
|
system = null;
|
2023-06-22 03:12:43 +00:00
|
|
|
};
|
2023-06-20 06:48:38 +00:00
|
|
|
|
2023-12-18 10:44:27 +00:00
|
|
|
# A thin wrapper around the home-manager configuration function.
|
2023-12-13 02:00:43 +00:00
|
|
|
mkHome = { pkgs, extraModules ? [ ], home-manager-channel ? "home-manager" }:
|
2023-12-15 14:05:49 +00:00
|
|
|
inputs.${home-manager-channel}.lib.homeManagerConfiguration {
|
|
|
|
inherit pkgs;
|
|
|
|
lib = pkgs.lib.extend extendLib;
|
2023-10-16 15:01:38 +00:00
|
|
|
modules = extraModules;
|
2023-06-20 06:48:38 +00:00
|
|
|
};
|
|
|
|
|
2023-12-18 10:44:27 +00:00
|
|
|
# A thin wrapper around the nixos-generators `nixosGenerate` function.
|
2023-12-16 12:02:22 +00:00
|
|
|
mkImage = { pkgs ? null, extraModules ? [ ], format ? "iso" }:
|
2023-06-20 06:48:38 +00:00
|
|
|
inputs.nixos-generators.nixosGenerate {
|
2023-12-16 12:02:22 +00:00
|
|
|
inherit pkgs format;
|
2023-12-19 09:59:55 +00:00
|
|
|
lib = pkgs.lib.extend (self: super:
|
|
|
|
import ./. { lib = super; }
|
|
|
|
// import ./private.nix { lib = self; }
|
|
|
|
// import ./home-manager.nix { lib = self; });
|
2023-10-16 15:01:38 +00:00
|
|
|
modules = extraModules;
|
2023-06-20 06:48:38 +00:00
|
|
|
};
|
2023-07-29 23:11:53 +00:00
|
|
|
|
2023-12-18 10:44:27 +00:00
|
|
|
# A function to modify the given table of declarative setups (i.e., hosts,
|
|
|
|
# users) to have its own system attribute and its name.
|
|
|
|
#
|
|
|
|
# If the given setup only has one system, its name will stay the same.
|
|
|
|
# Otherwise, it will be appended with the system as part of the name (e.g.,
|
|
|
|
# `$NAME-$SYSTEM`).
|
2023-07-29 23:11:53 +00:00
|
|
|
listImagesWithSystems = data:
|
|
|
|
lib.foldlAttrs
|
|
|
|
(acc: name: metadata:
|
2023-08-27 05:41:29 +00:00
|
|
|
let
|
|
|
|
name' = metadata.hostname or name;
|
|
|
|
in
|
2023-07-29 23:11:53 +00:00
|
|
|
if lib.length metadata.systems > 1 then
|
|
|
|
acc // (lib.foldl
|
|
|
|
(images: system: images // {
|
|
|
|
"${name'}-${system}" = metadata // {
|
|
|
|
_system = system;
|
|
|
|
_name = name';
|
|
|
|
};
|
|
|
|
})
|
2023-08-27 05:41:29 +00:00
|
|
|
{ }
|
2023-07-29 23:11:53 +00:00
|
|
|
metadata.systems)
|
|
|
|
else
|
|
|
|
acc // {
|
|
|
|
"${name'}" = metadata // {
|
|
|
|
_system = lib.head metadata.systems;
|
|
|
|
_name = name';
|
|
|
|
};
|
|
|
|
})
|
2023-08-27 05:41:29 +00:00
|
|
|
{ }
|
2023-07-29 23:11:53 +00:00
|
|
|
data;
|
2023-06-20 06:48:38 +00:00
|
|
|
}
|