mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 04:19:19 -08:00
feat: migrate to Gensokyo-zone/infrastructure systems modules
This commit is contained in:
parent
d021ec2e15
commit
c5e8103b6b
6 changed files with 196 additions and 174 deletions
19
modules/system/ci.nix
Normal file
19
modules/system/ci.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
in {
|
||||
options.ci = with lib.types; {
|
||||
enable =
|
||||
mkEnableOption "build via CI"
|
||||
// {
|
||||
default = config.type == "NixOS";
|
||||
};
|
||||
allowFailure = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
37
modules/system/deploy.nix
Normal file
37
modules/system/deploy.nix
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
name,
|
||||
config,
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkOptionDefault;
|
||||
in {
|
||||
options = let
|
||||
inherit (lib.types) nullOr;
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
deploy = mkOption {
|
||||
type = nullOr inputs.arcexprs.lib.json.types.attrs;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
deploy = let
|
||||
nixos = config.built;
|
||||
in {
|
||||
sshUser = mkOptionDefault "deploy";
|
||||
user = mkOptionDefault "root";
|
||||
sshOpts = mkIf (config.type == "NixOS") (
|
||||
mkOptionDefault ["-p" "${builtins.toString (builtins.head nixos.config.services.openssh.ports)}"]
|
||||
);
|
||||
autoRollback = mkOptionDefault true;
|
||||
magicRollback = mkOptionDefault true;
|
||||
fastConnection = mkOptionDefault false;
|
||||
hostname = mkOptionDefault "${name}.inskip.me";
|
||||
profiles.system = {
|
||||
user = "root";
|
||||
path = inputs.deploy-rs.lib.${config.system}.activate.nixos inputs.self.nixosConfigurations.${name};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
118
modules/system/host.nix
Normal file
118
modules/system/host.nix
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
{
|
||||
name,
|
||||
config,
|
||||
meta,
|
||||
std,
|
||||
Std,
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkOptionDefault;
|
||||
inherit (lib.trivial) mapNullable;
|
||||
inherit (std) string;
|
||||
in {
|
||||
options = let
|
||||
inherit (lib.types) str listOf attrs unspecified enum;
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
default = name;
|
||||
readOnly = true;
|
||||
};
|
||||
arch = mkOption {
|
||||
description = "Processor architecture of the host";
|
||||
type = str;
|
||||
default = "x86_64";
|
||||
};
|
||||
type = mkOption {
|
||||
description = "Operating system type of the host";
|
||||
type = enum ["NixOS" "MacOS" "Darwin" "Linux" "Windows"];
|
||||
default = "NixOS";
|
||||
};
|
||||
folder = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
system = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
modules = mkOption {
|
||||
type = listOf unspecified;
|
||||
default = [];
|
||||
};
|
||||
specialArgs = mkOption {
|
||||
type = attrs;
|
||||
internal = true;
|
||||
};
|
||||
builder = mkOption {
|
||||
type = unspecified;
|
||||
internal = true;
|
||||
};
|
||||
built = mkOption {
|
||||
type = unspecified;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
system = let
|
||||
kernel =
|
||||
{
|
||||
nixos = "linux";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
}
|
||||
.${string.toLower config.type};
|
||||
in "${config.arch}-${kernel}";
|
||||
folder =
|
||||
{
|
||||
nixos = "nixos";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
windows = "windows";
|
||||
}
|
||||
.${string.toLower config.type};
|
||||
modules = mkIf (config.folder != "linux") [
|
||||
# per-OS modules
|
||||
meta.modules.${config.folder}
|
||||
# per-OS configuration
|
||||
meta.${config.folder}.base
|
||||
];
|
||||
builder =
|
||||
{
|
||||
nixos = let
|
||||
lib = inputs.nixpkgs.lib.extend (self: super:
|
||||
import (inputs.arcexprs + "/lib") {
|
||||
inherit super;
|
||||
lib = self;
|
||||
isOverlayLib = true;
|
||||
});
|
||||
sys = args:
|
||||
lib.nixosSystem ({
|
||||
inherit lib;
|
||||
}
|
||||
// args);
|
||||
in
|
||||
sys;
|
||||
darwin = inputs.darwin.lib.darwinSystem;
|
||||
macos = inputs.darwin.lib.darwinSystem;
|
||||
}
|
||||
.${string.toLower config.type}
|
||||
or null;
|
||||
built = mkOptionDefault (mapNullable (builder:
|
||||
builder {
|
||||
inherit (config) system modules specialArgs;
|
||||
})
|
||||
config.builder);
|
||||
specialArgs = {
|
||||
inherit name inputs std Std meta;
|
||||
inherit (inputs.self.lib) gensokyo-zone;
|
||||
systemType = config.folder;
|
||||
system = config;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,189 +1,32 @@
|
|||
{
|
||||
inputs,
|
||||
{ inputs,
|
||||
tree,
|
||||
lib,
|
||||
std,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
pkgs, }: let
|
||||
# The purpose of this file is to set up the host module which allows assigning of the system, e.g. aarch64-linux and the builder used with less pain.
|
||||
inherit (lib.modules) evalModules;
|
||||
inherit (std) string types optional set list;
|
||||
defaultSpecialArgs = {
|
||||
inherit inputs tree std;
|
||||
};
|
||||
hostModule = {
|
||||
config,
|
||||
machine,
|
||||
...
|
||||
}: {
|
||||
options = let
|
||||
inherit (lib.types) str listOf attrs unspecified;
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
arch = mkOption {
|
||||
description = "Processor architecture of the host";
|
||||
type = str;
|
||||
default = "x86_64";
|
||||
};
|
||||
type = mkOption {
|
||||
description = "Operating system type of the host";
|
||||
type = str;
|
||||
default = "NixOS";
|
||||
};
|
||||
folder = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
system = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
modules = mkOption {
|
||||
type = listOf unspecified;
|
||||
};
|
||||
specialArgs = mkOption {
|
||||
type = attrs;
|
||||
internal = true;
|
||||
};
|
||||
builder = mkOption {
|
||||
type = unspecified;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
system = let
|
||||
kernel =
|
||||
{
|
||||
nixos = "linux";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
}
|
||||
.${string.toLower config.type};
|
||||
in "${config.arch}-${kernel}";
|
||||
folder =
|
||||
{
|
||||
nixos = "nixos";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
}
|
||||
.${string.toLower config.type};
|
||||
modules = with tree; [
|
||||
# per-OS modules
|
||||
tree.modules.${config.folder}
|
||||
# per-OS configuration
|
||||
tree.${config.folder}.common
|
||||
# per-OS user definition
|
||||
tree.home.user.${config.folder}
|
||||
# the base common module
|
||||
common
|
||||
];
|
||||
builder =
|
||||
{
|
||||
nixos = let
|
||||
lib = inputs.nixpkgs.lib.extend (self: super:
|
||||
import (inputs.arcexprs + "/lib") {
|
||||
inherit super;
|
||||
lib = self;
|
||||
isOverlayLib = true;
|
||||
});
|
||||
sys = args:
|
||||
lib.nixosSystem ({
|
||||
inherit lib;
|
||||
}
|
||||
// args);
|
||||
in
|
||||
args: let
|
||||
nixos = sys args;
|
||||
in
|
||||
nixos.extendModules {
|
||||
modules =
|
||||
nixos.config.scalpels
|
||||
++ [
|
||||
inputs.scalpel.nixosModules.scalpel
|
||||
];
|
||||
specialArgs = {prev = nixos;};
|
||||
};
|
||||
darwin = inputs.darwin.lib.darwinSystem;
|
||||
macos = inputs.darwin.lib.darwinSystem;
|
||||
}
|
||||
.${string.toLower config.type};
|
||||
specialArgs = let
|
||||
nur = import inputs.nur {
|
||||
pkgs = pkgs.${config.system};
|
||||
nurpkgs = pkgs.${config.system};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit machine nur;
|
||||
systemType = config.folder;
|
||||
inherit (config) system;
|
||||
}
|
||||
// defaultSpecialArgs;
|
||||
};
|
||||
};
|
||||
inherit (std) set;
|
||||
hostConfigs = set.map (name: path:
|
||||
evalModules {
|
||||
modules = [
|
||||
hostModule
|
||||
path
|
||||
tree.modules.system
|
||||
];
|
||||
specialArgs =
|
||||
defaultSpecialArgs
|
||||
// {
|
||||
machine = name;
|
||||
};
|
||||
specialArgs = {
|
||||
inherit name inputs std tree pkgs;
|
||||
};
|
||||
})
|
||||
tree.systems;
|
||||
(set.map (_: c: c) tree.systems);
|
||||
processHost = name: cfg: let
|
||||
host = cfg.config;
|
||||
serverLocations = {
|
||||
mediabox = "10.1.1.167";
|
||||
orb = "orb";
|
||||
daiyousei = "140.238.156.121";
|
||||
mei = "150.230.28.111";
|
||||
mai = "132.145.108.249";
|
||||
};
|
||||
in {
|
||||
deploy.nodes = set.merge [
|
||||
(set.optional (host.folder == "nixos") {
|
||||
${name} = {
|
||||
profiles.system = {
|
||||
user = "root";
|
||||
path = inputs.deploy-rs.lib.${host.system}.activate.nixos inputs.self.nixosConfigurations.${name};
|
||||
};
|
||||
autoRollback = false;
|
||||
magicRollback = false;
|
||||
};
|
||||
})
|
||||
(set.optional (!(list.elem name (set.keys serverLocations)) && host.folder == "nixos") {
|
||||
${name} = {
|
||||
hostname = "${name}.inskip.me";
|
||||
sshUser = "deploy";
|
||||
sshOpts = ["-oControlMaster=no" "-oControlPath=/tmp/willneverexist" "-p" "${builtins.toString (builtins.head inputs.self.nixosConfigurations.${name}.config.services.openssh.ports)}"];
|
||||
};
|
||||
})
|
||||
(set.optional ((list.elem name (set.keys serverLocations)) && host.folder == "nixos") {
|
||||
${name} = {
|
||||
hostname = serverLocations.${name};
|
||||
sshUser = "deploy";
|
||||
sshOpts = ["-oControlMaster=no" "-oControlPath=/tmp/willneverexist" "-p" "${builtins.toString (builtins.head inputs.self.nixosConfigurations.${name}.config.services.openssh.ports)}"];
|
||||
};
|
||||
})
|
||||
(set.optional (name == "renko" && host.folder == "nixos") {
|
||||
${name} = {
|
||||
sshUser = "nixos";
|
||||
fastConnection = true;
|
||||
sshOpts = ["-oControlMaster=no" "-oControlPath=/tmp/willneverexist" "-p" "32222"];
|
||||
};
|
||||
})
|
||||
];
|
||||
in
|
||||
set.optional (host.type != null) {
|
||||
deploy.nodes.${name} = host.deploy;
|
||||
|
||||
"${host.folder}Configurations".${name} = host.builder {
|
||||
inherit (host) system modules specialArgs;
|
||||
"${host.folder}Configurations".${name} = host.built;
|
||||
};
|
||||
};
|
||||
in
|
||||
set.merge (set.mapToValues processHost hostConfigs)
|
||||
{
|
||||
systems = hostConfigs;
|
||||
}
|
||||
// set.merge (set.mapToValues processHost hostConfigs)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ _: let
|
|||
};
|
||||
in {
|
||||
arch = "aarch64";
|
||||
type = "macOS";
|
||||
type = "MacOS";
|
||||
modules = [
|
||||
hostConfig
|
||||
];
|
||||
|
|
|
|||
5
tree.nix
5
tree.nix
|
|
@ -67,6 +67,11 @@
|
|||
"nixos/hardware/conditional" = {
|
||||
functor.enable = true;
|
||||
};
|
||||
"modules/system" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
"modules/nixos" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue