Add custom module documentation
This commit is contained in:
parent
f6e5f36e69
commit
7dec8bb56b
@ -1,4 +1,4 @@
|
|||||||
{ lib, pkgs, inputs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
{
|
{
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
"/persist" = {
|
"/persist" = {
|
||||||
|
33
flake.nix
33
flake.nix
@ -33,10 +33,9 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (builtins) mapAttrs;
|
inherit (builtins) mapAttrs attrValues;
|
||||||
inherit (lib) genAttrs mapAttrs';
|
inherit (lib.flake) eachDefaultSystem;
|
||||||
inherit (lib.flake) defaultSystems eachDefaultSystem;
|
inherit (lib.my) mkApp mkShellApp;
|
||||||
inherit (lib.my) addPrefix mkApp mkShellApp;
|
|
||||||
|
|
||||||
extendLib = lib: lib.extend (final: prev: {
|
extendLib = lib: lib.extend (final: prev: {
|
||||||
my = import ./util.nix { lib = final; };
|
my = import ./util.nix { lib = final; };
|
||||||
@ -61,28 +60,30 @@
|
|||||||
];
|
];
|
||||||
})
|
})
|
||||||
pkgsFlakes;
|
pkgsFlakes;
|
||||||
|
|
||||||
|
modules = mapAttrs (_: f: ./. + "/modules/${f}") {
|
||||||
|
common = "common.nix";
|
||||||
|
build = "build.nix";
|
||||||
|
dynamic-motd = "dynamic-motd.nix";
|
||||||
|
tmproot = "tmproot.nix";
|
||||||
|
firewall = "firewall.nix";
|
||||||
|
server = "server.nix";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
# Platform independent stuff
|
# Platform independent stuff
|
||||||
{
|
{
|
||||||
lib = lib.my;
|
lib = lib.my;
|
||||||
|
nixpkgs = pkgs';
|
||||||
|
|
||||||
nixosModules = mapAttrs
|
nixosModules = mapAttrs
|
||||||
(_: path:
|
(_: path:
|
||||||
let path' = ./. + "/modules/${path}"; in
|
|
||||||
{
|
{
|
||||||
_file = path';
|
_file = path;
|
||||||
imports = [ (import path') ];
|
imports = [ (import path) ];
|
||||||
})
|
})
|
||||||
{
|
modules;
|
||||||
common = "common.nix";
|
|
||||||
build = "build.nix";
|
|
||||||
dynamic-motd = "dynamic-motd.nix";
|
|
||||||
tmproot = "tmproot.nix";
|
|
||||||
firewall = "firewall.nix";
|
|
||||||
server = "server.nix";
|
|
||||||
};
|
|
||||||
|
|
||||||
nixosConfigurations = import ./systems.nix { inherit lib pkgsFlakes inputs; modules = self.nixosModules; };
|
nixosConfigurations = import ./systems.nix { inherit lib pkgsFlakes inputs; modules = attrValues modules; };
|
||||||
systems = mapAttrs (_: system: system.config.system.build.toplevel) self.nixosConfigurations;
|
systems = mapAttrs (_: system: system.config.system.build.toplevel) self.nixosConfigurations;
|
||||||
vms = mapAttrs (_: system: system.config.my.build.devVM) self.nixosConfigurations;
|
vms = mapAttrs (_: system: system.config.my.build.devVM) self.nixosConfigurations;
|
||||||
} //
|
} //
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ lib, extendModules, modulesPath, baseModules, options, config, ... }:
|
{ lib, extendModules, modulesPath, baseModules, options, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) recursiveUpdate mkOption;
|
inherit (lib) recursiveUpdate mkOption;
|
||||||
inherit (lib.my) mkBoolOpt;
|
inherit (lib.my) mkBoolOpt';
|
||||||
|
|
||||||
cfg = config.my.build;
|
cfg = config.my.build;
|
||||||
|
|
||||||
@ -18,12 +18,13 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my = with lib.types; {
|
options.my = with lib.types; {
|
||||||
boot.isDevVM = mkBoolOpt false;
|
boot.isDevVM = mkBoolOpt' false "Whether the system is a development VM.";
|
||||||
build = options.system.build;
|
build = options.system.build;
|
||||||
asDevVM = mkOption {
|
asDevVM = mkOption {
|
||||||
inherit (asDevVM) type;
|
inherit (asDevVM) type;
|
||||||
default = { };
|
default = { };
|
||||||
visible = "shallow";
|
visible = "shallow";
|
||||||
|
description = "Configuration as a development VM";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
{ lib, pkgs, inputs, system, config, options, ... }:
|
{ lib, pkgs, inputs, system, config, options, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkIf mkDefault mkAliasDefinitions;
|
inherit (lib) mkIf mkDefault mkAliasDefinitions;
|
||||||
inherit (lib.my) mkOpt;
|
inherit (lib.my) mkOpt';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my = with lib.types; {
|
options.my = with lib.types; {
|
||||||
user = mkOpt (attrsOf anything) { };
|
# Pretty hacky but too lazy to figure out if there's a better way to alias the options
|
||||||
|
user = mkOpt' (attrsOf anything) { } "User definition (as `users.users.*`).";
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
@ -40,13 +41,15 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
nix = {
|
nix = {
|
||||||
package = inputs.nix.defaultPackage.${system};
|
|
||||||
extraOptions =
|
extraOptions =
|
||||||
''
|
''
|
||||||
experimental-features = nix-command flakes ca-derivations
|
experimental-features = nix-command flakes ca-derivations
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
nixpkgs = {
|
nixpkgs = {
|
||||||
|
overlays = [
|
||||||
|
inputs.nix.overlay
|
||||||
|
];
|
||||||
config = {
|
config = {
|
||||||
allowUnfree = true;
|
allowUnfree = true;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ lib, pkgs, config, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) optionalAttrs filterAttrs genAttrs mkIf mkDefault;
|
inherit (lib) optionalAttrs filterAttrs genAttrs mkIf mkDefault;
|
||||||
inherit (lib.my) mkOpt mkBoolOpt;
|
inherit (lib.my) mkOpt' mkBoolOpt';
|
||||||
|
|
||||||
cfg = config.my.dynamic-motd;
|
cfg = config.my.dynamic-motd;
|
||||||
|
|
||||||
@ -9,9 +9,9 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my.dynamic-motd = with lib.types; {
|
options.my.dynamic-motd = with lib.types; {
|
||||||
enable = mkBoolOpt true;
|
enable = mkBoolOpt' true "Whether to enable the dynamic message of the day PAM module.";
|
||||||
services = mkOpt (listOf str) [ "login" "ssh" ];
|
services = mkOpt' (listOf str) [ "login" "ssh" ] "PAM services to enable the dynamic message of the day module for.";
|
||||||
script = mkOpt (nullOr lines) null;
|
script = mkOpt' (nullOr lines) null "Script that generates message of the day.";
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf (cfg.enable && cfg.script != null) {
|
config = mkIf (cfg.enable && cfg.script != null) {
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
{ lib, options, config, ... }:
|
{ lib, options, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) optionalString concatStringsSep concatMapStringsSep optionalAttrs mkIf mkDefault mkMerge mkOverride;
|
inherit (lib) optionalString concatStringsSep concatMapStringsSep optionalAttrs mkIf mkDefault mkMerge mkOverride;
|
||||||
inherit (lib.my) parseIPPort mkOpt mkBoolOpt dummyOption;
|
inherit (lib.my) parseIPPort mkOpt' mkBoolOpt' dummyOption;
|
||||||
|
|
||||||
cfg = config.my.firewall;
|
cfg = config.my.firewall;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my.firewall = with lib.types; {
|
options.my.firewall = with lib.types; {
|
||||||
enable = mkBoolOpt true;
|
enable = mkBoolOpt' true "Whether to enable the nftables-based firewall.";
|
||||||
trustedInterfaces = options.networking.firewall.trustedInterfaces;
|
trustedInterfaces = options.networking.firewall.trustedInterfaces;
|
||||||
tcp = {
|
tcp = {
|
||||||
allowed = mkOpt (listOf (either port str)) [ "ssh" ];
|
allowed = mkOpt' (listOf (either port str)) [ "ssh" ] "TCP ports to open.";
|
||||||
};
|
};
|
||||||
udp = {
|
udp = {
|
||||||
allowed = mkOpt (listOf (either port str)) [ ];
|
allowed = mkOpt' (listOf (either port str)) [ ] "UDP ports to open.";
|
||||||
};
|
};
|
||||||
extraRules = mkOpt lines "";
|
extraRules = mkOpt' lines "" "Arbitrary additional nftables rules.";
|
||||||
|
|
||||||
nat = with options.networking.nat; {
|
nat = with options.networking.nat; {
|
||||||
enable = mkBoolOpt true;
|
enable = mkBoolOpt' true "Whether to enable IP forwarding and NAT.";
|
||||||
inherit externalInterface forwardPorts;
|
inherit externalInterface forwardPorts;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkIf;
|
inherit (lib) mkIf;
|
||||||
inherit (lib.my) mkBoolOpt;
|
inherit (lib.my) mkBoolOpt';
|
||||||
|
|
||||||
|
cfg = config.my.server;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my.server.enable = mkBoolOpt false;
|
options.my.server.enable = mkBoolOpt' false "Whether to enable common configuration for servers.";
|
||||||
config = mkIf config.my.server.enable {
|
config = mkIf cfg.enable {
|
||||||
services.getty.autologinUser = config.my.user.name;
|
services.getty.autologinUser = config.my.user.name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
{ lib, pkgs, inputs, config, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) elem;
|
inherit (lib) concatStringsSep concatMap concatMapStringsSep mkIf mkDefault mkMerge mkVMOverride;
|
||||||
inherit (lib) concatStringsSep concatMap concatMapStringsSep mkIf mkDefault mkMerge mkForce mkVMOverride;
|
inherit (lib.my) mkOpt' mkBoolOpt' mkVMOverride' dummyOption;
|
||||||
inherit (lib.my) mkOpt mkBoolOpt mkVMOverride' dummyOption;
|
|
||||||
|
|
||||||
cfg = config.my.tmproot;
|
cfg = config.my.tmproot;
|
||||||
|
|
||||||
@ -54,16 +53,14 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.impermanence.nixosModule ];
|
|
||||||
|
|
||||||
options = with lib.types; {
|
options = with lib.types; {
|
||||||
my.tmproot = {
|
my.tmproot = {
|
||||||
enable = mkBoolOpt true;
|
enable = mkBoolOpt' true "Whether to enable tmproot.";
|
||||||
persistDir = mkOpt str "/persist";
|
persistDir = mkOpt' str "/persist" "Path where persisted files are stored.";
|
||||||
size = mkOpt str "2G";
|
size = mkOpt' str "2G" "Size of tmpfs root";
|
||||||
unsaved = {
|
unsaved = {
|
||||||
showMotd = mkBoolOpt true;
|
showMotd = mkBoolOpt' true "Whether to show unsaved files with `dynamic-motd`.";
|
||||||
ignore = mkOpt (listOf str) [ ];
|
ignore = mkOpt' (listOf str) [ ] "Path prefixes to ignore if unsaved.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
11
systems.nix
11
systems.nix
@ -25,9 +25,16 @@ let
|
|||||||
in
|
in
|
||||||
nixosSystem' {
|
nixosSystem' {
|
||||||
inherit lib system;
|
inherit lib system;
|
||||||
specialArgs = { inherit inputs system; };
|
baseModules =
|
||||||
modules = attrValues modules ++ [
|
(import "${pkgsFlake}/nixos/modules/module-list.nix") ++ [
|
||||||
|
# Importing modules from module args causes infinite recursion
|
||||||
|
inputs.impermanence.nixosModule
|
||||||
|
inputs.agenix.nixosModules.age
|
||||||
|
inputs.home-manager.nixosModule
|
||||||
|
] ++ modules;
|
||||||
|
modules = [
|
||||||
{
|
{
|
||||||
|
_module.args = { inherit system inputs; };
|
||||||
system.name = name;
|
system.name = name;
|
||||||
networking.hostName = mkDefault name;
|
networking.hostName = mkDefault name;
|
||||||
}
|
}
|
||||||
|
9
util.nix
9
util.nix
@ -26,11 +26,18 @@ rec {
|
|||||||
mkShellApp = pkgs: name: text: mkApp (pkgs.writeShellScript name text).outPath;
|
mkShellApp = pkgs: name: text: mkApp (pkgs.writeShellScript name text).outPath;
|
||||||
|
|
||||||
mkOpt = type: default: mkOption { inherit type default; };
|
mkOpt = type: default: mkOption { inherit type default; };
|
||||||
|
mkOpt' = type: default: description: mkOption { inherit type default description; };
|
||||||
mkBoolOpt = default: mkOption {
|
mkBoolOpt = default: mkOption {
|
||||||
inherit default;
|
inherit default;
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
example = true;
|
example = true;
|
||||||
};
|
};
|
||||||
mkVMOverride' = mkOverride 9;
|
mkBoolOpt' = default: description: mkOption {
|
||||||
|
inherit default description;
|
||||||
|
type = types.bool;
|
||||||
|
example = true;
|
||||||
|
};
|
||||||
dummyOption = mkOption { };
|
dummyOption = mkOption { };
|
||||||
|
|
||||||
|
mkVMOverride' = mkOverride 9;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user