hosts: migrate to nilla
This commit is contained in:
parent
c523ebe44b
commit
ba23a8d7f5
19 changed files with 78 additions and 205 deletions
|
@ -1,8 +1,8 @@
|
|||
{ lib, ... }:
|
||||
{ lib }:
|
||||
{
|
||||
options.assets = lib.mkOption {
|
||||
type = lib.types.unspecified;
|
||||
readOnly = true;
|
||||
options.assets = lib.options.create {
|
||||
type = lib.types.raw;
|
||||
writable = false;
|
||||
};
|
||||
|
||||
config.assets = {
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
inherit systems;
|
||||
imports = [
|
||||
./assets
|
||||
./hosts
|
||||
./modules
|
||||
./services
|
||||
];
|
||||
|
||||
flake.nixosConfigurations = nilla.nixosConfigurations;
|
||||
flake.darwinConfigurations = nilla.darwinConfigurations;
|
||||
flake.homeConfigurations = nilla.homeConfigurations;
|
||||
flake.devShells = transpose nilla.shells;
|
||||
flake.packages = transpose nilla.packages;
|
||||
flake.formatter = nilla.packages.formatter.result;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
config,
|
||||
self,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inputs = builtins.mapAttrs (_: input: input.result) config.inputs;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
includes = [
|
||||
./kazuki
|
||||
./hijiri-vm
|
||||
./hijiri
|
||||
|
@ -16,20 +16,20 @@
|
|||
./youko
|
||||
];
|
||||
|
||||
builders =
|
||||
config.configBuilders =
|
||||
let
|
||||
sharedOptions = {
|
||||
_file = ./default.nix;
|
||||
|
||||
settei.sane-defaults.allSshKeys = config.assets.sshKeys.user;
|
||||
settei.flake-qol.inputs = inputs // {
|
||||
settei = self;
|
||||
settei = inputs.self;
|
||||
};
|
||||
};
|
||||
|
||||
baseNixos = inputs.nixpkgs.lib.nixosSystem {
|
||||
modules = [
|
||||
self.nixosModules.combined
|
||||
inputs.self.nixosModules.combined
|
||||
sharedOptions
|
||||
];
|
||||
specialArgs.configurationName = "base";
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
baseDarwin = inputs.darwin.lib.darwinSystem {
|
||||
modules = [
|
||||
self.darwinModules.combined
|
||||
inputs.self.darwinModules.combined
|
||||
sharedOptions
|
||||
];
|
||||
specialArgs.configurationName = "base";
|
||||
|
@ -49,7 +49,7 @@
|
|||
baseNixos.extendModules {
|
||||
modules = [
|
||||
module
|
||||
config.__extraHostConfigs.${name} or { }
|
||||
config.extraHostConfigs.${name} or { }
|
||||
];
|
||||
specialArgs.configurationName = name;
|
||||
};
|
||||
|
@ -60,7 +60,7 @@
|
|||
eval = baseDarwin._module.args.extendModules {
|
||||
modules = [
|
||||
module
|
||||
config.__extraHostConfigs.${name} or { }
|
||||
config.extraHostConfigs.${name} or { }
|
||||
];
|
||||
specialArgs.configurationName = name;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.nixos.hijiri-vm =
|
||||
config.configurations.nixos.hijiri-vm =
|
||||
{
|
||||
modulesPath,
|
||||
lib,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.darwin.hijiri =
|
||||
config.configurations.darwin.hijiri =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
configurations.nixos =
|
||||
config.configurations.nixos =
|
||||
let
|
||||
mkInstaller =
|
||||
system:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.nixos.kazuki =
|
||||
config.configurations.nixos.kazuki =
|
||||
{
|
||||
modulesPath,
|
||||
...
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.darwin.kogata =
|
||||
config.configurations.darwin.kogata =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
nixpkgs.system = "aarch64-darwin";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.nixos.ude =
|
||||
config.configurations.nixos.ude =
|
||||
{
|
||||
config,
|
||||
modulesPath,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
configurations.nixos.youko =
|
||||
config.configurations.nixos.youko =
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
|
|
|
@ -3,24 +3,12 @@
|
|||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
flakeModule = import ./flake { inherit (inputs) nixpkgs darwin home-manager; };
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
flakeModule
|
||||
];
|
||||
|
||||
flake.homeModules = rec {
|
||||
settei = ./home;
|
||||
default = settei;
|
||||
};
|
||||
|
||||
flake.flakeModules = rec {
|
||||
settei = flakeModule;
|
||||
default = settei;
|
||||
};
|
||||
|
||||
flake.nixosModules = rec {
|
||||
settei = import ./system {
|
||||
inherit (config) perInput;
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
nixpkgs,
|
||||
darwin,
|
||||
home-manager,
|
||||
}:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
_file = ./configurations.nix;
|
||||
|
||||
options = {
|
||||
# Those functions take the final arguments and emit a valid configuration.
|
||||
# Probably should hardly ever be overriden
|
||||
builders = {
|
||||
nixos = mkOption {
|
||||
type = types.functionTo types.unspecified;
|
||||
default = _name: nixpkgs.lib.nixosSystem;
|
||||
};
|
||||
darwin = mkOption {
|
||||
type = types.functionTo types.unspecified;
|
||||
default = _name: darwin.lib.darwinSystem;
|
||||
};
|
||||
home = mkOption {
|
||||
type = types.functionTo types.unspecified;
|
||||
default = _name: home-manager.lib.homeManagerConfiguration;
|
||||
};
|
||||
};
|
||||
|
||||
configurations = {
|
||||
nixos = mkOption {
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
darwin = mkOption {
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
home = mkOption {
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config.flake = {
|
||||
nixosConfigurations = mapAttrs config.builders.nixos config.configurations.nixos;
|
||||
darwinConfigurations = mapAttrs config.builders.darwin config.configurations.darwin;
|
||||
homeConfigurations = mapAttrs config.builders.home config.configurations.home;
|
||||
};
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
nixpkgs,
|
||||
darwin,
|
||||
home-manager,
|
||||
}:
|
||||
{
|
||||
_file = ./default.nix;
|
||||
|
||||
imports = [
|
||||
(import ./configurations.nix { inherit nixpkgs darwin home-manager; })
|
||||
./services.nix
|
||||
];
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
# List of features I want this module to eventually have
|
||||
# TODO: Automatic port allocation
|
||||
# TODO: Making it possible to conveniently isolate services (running them in NixOS containers)
|
||||
# TODO: Handling specializations
|
||||
# TODO: Convenient http handling
|
||||
# TODO: Automatic backup
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
serviceModule =
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
ports = lib.mkOption {
|
||||
type = with lib.types; listOf port;
|
||||
default = [ ];
|
||||
};
|
||||
hosts = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
default = [ config.host ];
|
||||
};
|
||||
module = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
hostModule = lib.mkOption {
|
||||
type = with lib.types; attrsOf deferredModule;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
moduleToHostConfigs =
|
||||
cfg:
|
||||
lib.genAttrs cfg.hosts (host: {
|
||||
imports = [
|
||||
cfg.module
|
||||
(cfg.hostModule.${host} or { })
|
||||
];
|
||||
});
|
||||
|
||||
maybeGetPreviousConfigs = acc: host: (acc.${host} or { imports = [ ]; }).imports;
|
||||
in
|
||||
{
|
||||
_file = ./services.nix;
|
||||
|
||||
options = {
|
||||
services = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule serviceModule);
|
||||
default = { };
|
||||
};
|
||||
|
||||
__extraHostConfigs = lib.mkOption {
|
||||
type = with lib.types; attrsOf deferredModule;
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config.__extraHostConfigs =
|
||||
let
|
||||
duplicatePorts = lib.pipe config.services [
|
||||
lib.attrValues
|
||||
(map (cfg: cfg.ports))
|
||||
lib.flatten
|
||||
(lib.groupBy' (cnt: _: cnt + 1) 0 toString)
|
||||
(lib.filterAttrs (_: cnt: cnt > 1))
|
||||
lib.attrNames
|
||||
];
|
||||
assertMsg =
|
||||
let
|
||||
plural = lib.length duplicatePorts > 1;
|
||||
in
|
||||
"\nBad service config:\nThe following port${if plural then "s" else ""} ${
|
||||
if plural then "were" else "was"
|
||||
} declared multiple times: ${lib.concatStringsSep ", " duplicatePorts}";
|
||||
# Here I collect all the services.<name>.config into a flat
|
||||
# __extraHostConfigs.<host>.imports = [
|
||||
# ...
|
||||
# ]
|
||||
# so that I can easily import them in hosts/default.nix
|
||||
hostConfigs = lib.pipe config.services [
|
||||
lib.attrValues
|
||||
(lib.foldl' (
|
||||
acc: cfg:
|
||||
acc
|
||||
// lib.mapAttrs (host: c: {
|
||||
imports = c.imports ++ (maybeGetPreviousConfigs acc host);
|
||||
}) (moduleToHostConfigs cfg)
|
||||
) { })
|
||||
];
|
||||
in
|
||||
if duplicatePorts != [ ] then throw assertMsg else hostConfigs;
|
||||
}
|
47
modules/nilla/configurations.nix
Normal file
47
modules/nilla/configurations.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
{ config, lib }:
|
||||
{
|
||||
options = {
|
||||
configBuilders = {
|
||||
nixos = lib.options.create {
|
||||
type = lib.types.function lib.types.raw;
|
||||
default.value = _name: config.inputs.nixpkgs.result.lib.nixosSystem;
|
||||
};
|
||||
darwin = lib.options.create {
|
||||
type = lib.types.function lib.types.raw;
|
||||
default.value = _name: config.inputs.darwin.result.lib.darwinSystem;
|
||||
};
|
||||
home = lib.options.create {
|
||||
type = lib.types.function lib.types.raw;
|
||||
default.value = _name: config.inputs.home-manager.result.lib.homeManagerConfiguration;
|
||||
};
|
||||
};
|
||||
|
||||
configurations = {
|
||||
nixos = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = { };
|
||||
};
|
||||
darwin = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = { };
|
||||
};
|
||||
home = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = { };
|
||||
};
|
||||
};
|
||||
|
||||
nixosConfigurations = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = builtins.mapAttrs config.configBuilders.nixos config.configurations.nixos;
|
||||
};
|
||||
darwinConfigurations = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = builtins.mapAttrs config.configBuilders.darwin config.configurations.darwin;
|
||||
};
|
||||
homeConfigurations = lib.options.create {
|
||||
type = lib.types.attrs.lazy lib.types.raw;
|
||||
default.value = builtins.mapAttrs config.configBuilders.home config.configurations.home;
|
||||
};
|
||||
};
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
includes = [
|
||||
./builders
|
||||
./services.nix
|
||||
./configurations.nix
|
||||
];
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ let
|
|||
{
|
||||
options = {
|
||||
host = lib.options.create {
|
||||
type = lib.types.str;
|
||||
type = lib.types.string;
|
||||
};
|
||||
ports = lib.options.create {
|
||||
type = lib.types.list.of lib.types.port;
|
||||
default.value = [ ];
|
||||
};
|
||||
hosts = lib.options.create {
|
||||
type = lib.types.list.of lib.types.str;
|
||||
type = lib.types.list.of lib.types.string;
|
||||
default.value = [ config.host ];
|
||||
};
|
||||
module = lib.options.create {
|
||||
|
|
|
@ -8,10 +8,9 @@
|
|||
./modules/nilla
|
||||
./pkgs
|
||||
./wrappers
|
||||
|
||||
./services/attic.nix
|
||||
./services/forgejo-runner.nix
|
||||
./services/forgejo.nix
|
||||
./hosts
|
||||
./assets
|
||||
./services
|
||||
];
|
||||
|
||||
config.inputs = builtins.mapAttrs (_: src: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
imports = [
|
||||
includes = [
|
||||
./attic.nix
|
||||
./forgejo-runner.nix
|
||||
./forgejo.nix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue