feat: format via 'ls **/*.nix | each { |it| nixfmt $it.name }'

This commit is contained in:
Ryan Yin
2025-07-30 12:17:24 +08:00
parent d10b30b06b
commit 13bb77108c
219 changed files with 2103 additions and 1728 deletions

View File

@@ -1,5 +1,6 @@
# https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix
{lib, ...}: {
{ lib, ... }:
{
# Generate an attribute set from a list.
#
# lib.genAttrs [ "foo" "bar" ] (name: "x_" + name)

View File

@@ -3,7 +3,7 @@
lib,
inputs,
nixos-modules,
home-modules ? [],
home-modules ? [ ],
myvars,
system,
tags,
@@ -11,30 +11,29 @@
genSpecialArgs,
specialArgs ? (genSpecialArgs system),
...
}: let
}:
let
inherit (inputs) home-manager;
in
{name, ...}: {
deployment = {
inherit tags;
targetUser = ssh-user;
targetHost = name; # hostName or IP address
};
{ name, ... }:
{
deployment = {
inherit tags;
targetUser = ssh-user;
targetHost = name; # hostName or IP address
};
imports =
nixos-modules
++ (
lib.optionals ((lib.lists.length home-modules) > 0)
[
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
imports =
nixos-modules
++ (lib.optionals ((lib.lists.length home-modules) > 0) [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]
);
}
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]);
}

View File

@@ -1,9 +1,10 @@
{lib, ...}: {
{ lib, ... }:
{
colmenaSystem = import ./colmenaSystem.nix;
macosSystem = import ./macosSystem.nix;
nixosSystem = import ./nixosSystem.nix;
attrs = import ./attrs.nix {inherit lib;};
attrs = import ./attrs.nix { inherit lib; };
genK3sServerModule = import ./genK3sServerModule.nix;
genK3sAgentModule = import ./genK3sAgentModule.nix;
@@ -12,18 +13,18 @@
# use path relative to the root of the project
relativeToRoot = lib.path.append ../.;
scanPaths = path:
builtins.map
(f: (path + "/${f}"))
(builtins.attrNames
(lib.attrsets.filterAttrs
(
scanPaths =
path:
builtins.map (f: (path + "/${f}")) (
builtins.attrNames (
lib.attrsets.filterAttrs (
path: _type:
(_type == "directory") # include directories
|| (
(path != "default.nix") # ignore default.nix
&& (lib.strings.hasSuffix ".nix" path) # include .nix files
)
)
(builtins.readDir path)));
(_type == "directory") # include directories
|| (
(path != "default.nix") # ignore default.nix
&& (lib.strings.hasSuffix ".nix" path) # include .nix files
)
) (builtins.readDir path)
)
);
}

View File

@@ -2,13 +2,15 @@
pkgs,
masterHost,
tokenFile,
nodeLabels ? [],
k3sExtraArgs ? [],
nodeLabels ? [ ],
k3sExtraArgs ? [ ],
...
}: let
}:
let
package = pkgs.k3s;
in {
environment.systemPackages = [package];
in
{
environment.systemPackages = [ package ];
# Kernel modules required by cilium
boot.kernelModules = [
@@ -30,14 +32,14 @@ in {
role = "agent";
serverAddr = "https://${masterHost}:6443";
# https://docs.k3s.io/cli/agent
extraFlags = let
flagList =
[
extraFlags =
let
flagList = [
"--data-dir /var/lib/rancher/k3s"
]
++ (map (label: "--node-label=${label}") nodeLabels)
++ k3sExtraArgs;
in
in
pkgs.lib.concatStringsSep " " flagList;
};
}

View File

@@ -10,16 +10,18 @@
# this can be a domain name or an IP address(such as kube-vip's virtual IP)
masterHost,
clusterInit ? false,
kubeletExtraArgs ? [],
k3sExtraArgs ? [],
nodeLabels ? [],
nodeTaints ? [],
kubeletExtraArgs ? [ ],
k3sExtraArgs ? [ ],
nodeLabels ? [ ],
nodeTaints ? [ ],
disableFlannel ? true,
...
}: let
}:
let
lib = pkgs.lib;
package = pkgs.k3s;
in {
in
{
environment.systemPackages = with pkgs; [
package
k9s
@@ -50,16 +52,13 @@ in {
services.k3s = {
enable = true;
inherit package tokenFile clusterInit;
serverAddr =
if clusterInit
then ""
else "https://${masterHost}:6443";
serverAddr = if clusterInit then "" else "https://${masterHost}:6443";
role = "server";
# https://docs.k3s.io/cli/server
extraFlags = let
flagList =
[
extraFlags =
let
flagList = [
"--write-kubeconfig=${kubeconfigFile}"
"--write-kubeconfig-mode=644"
"--service-node-port-range=80-32767"
@@ -77,9 +76,9 @@ in {
++ (map (label: "--node-label=${label}") nodeLabels)
++ (map (taint: "--node-taint=${taint}") nodeTaints)
++ (map (arg: "--kubelet-arg=${arg}") kubeletExtraArgs)
++ (lib.optionals disableFlannel ["--flannel-backend=none"])
++ (lib.optionals disableFlannel [ "--flannel-backend=none" ])
++ k3sExtraArgs;
in
in
lib.concatStringsSep " " flagList;
};

View File

@@ -3,11 +3,13 @@
hostName,
networking,
...
}: let
}:
let
inherit (networking) defaultGateway defaultGateway6 nameservers;
inherit (networking.hostsAddr.${hostName}) iface ipv4;
ipv4WithMask = "${ipv4}/24";
in {
in
{
# supported file systems, so we can mount any removable disks with these filesystems
boot.supportedFilesystems = [
"ext4"
@@ -29,9 +31,9 @@ in {
systemd.network.enable = true;
systemd.network.networks."10-${iface}" = {
matchConfig.Name = [iface];
matchConfig.Name = [ iface ];
networkConfig = {
Address = [ipv4WithMask];
Address = [ ipv4WithMask ];
DNS = nameservers;
DHCP = "ipv6"; # enable DHCPv6 only, so we can get a GUA.
IPv6AcceptRA = true; # for Stateless IPv6 Autoconfiguraton (SLAAC)

View File

@@ -3,11 +3,13 @@
hostName,
networking,
...
}: let
}:
let
inherit (networking) defaultGateway defaultGateway6 nameservers;
inherit (networking.hostsAddr.${hostName}) iface ipv4;
ipv4WithMask = "${ipv4}/24";
in {
in
{
# supported file systems, so we can mount any removable disks with these filesystems
boot.supportedFilesystems = [
"ext4"
@@ -21,7 +23,10 @@ in {
"nfs" # required by longhorn
];
boot.kernelModules = ["kvm-amd" "vfio-pci"];
boot.kernelModules = [
"kvm-amd"
"vfio-pci"
];
boot.extraModprobeConfig = "options kvm_amd nested=1"; # for amd cpu
boot.kernel.sysctl = {
@@ -93,7 +98,7 @@ in {
ovsbr1 = {
# Attach the interfaces to OVS bridge
# This interface should not used by the host itself!
interfaces.${iface} = {};
interfaces.${iface} = { };
};
};
@@ -102,9 +107,9 @@ in {
# Set the host's address on the OVS bridge interface instead of the physical interface!
systemd.network.networks = {
"10-ovsbr1" = {
matchConfig.Name = ["ovsbr1"];
matchConfig.Name = [ "ovsbr1" ];
networkConfig = {
Address = [ipv4WithMask];
Address = [ ipv4WithMask ];
DNS = nameservers;
DHCP = "ipv6"; # enable DHCPv6 only, so we can get a GUA.
IPv6AcceptRA = true; # for Stateless IPv6 Autoconfiguraton (SLAAC)
@@ -124,7 +129,7 @@ in {
linkConfig.RequiredForOnline = "routable";
};
"20-${iface}" = {
matchConfig.Name = [iface];
matchConfig.Name = [ iface ];
networkConfig.LinkLocalAddressing = "no";
# tell networkd ignore this interface.
# it's managed by openvswitch

View File

@@ -2,40 +2,41 @@
lib,
inputs,
darwin-modules,
home-modules ? [],
home-modules ? [ ],
myvars,
system,
genSpecialArgs,
specialArgs ? (genSpecialArgs system),
...
}: let
}:
let
inherit (inputs) nixpkgs-darwin home-manager nix-darwin;
in
nix-darwin.lib.darwinSystem {
inherit system specialArgs;
modules =
darwin-modules
++ [
({lib, ...}: {
nix-darwin.lib.darwinSystem {
inherit system specialArgs;
modules =
darwin-modules
++ [
(
{ lib, ... }:
{
nixpkgs.pkgs = import nixpkgs-darwin {
inherit system; # refer the `system` parameter form outer scope recursively
# To use chrome, we need to allow the installation of non-free software
config.allowUnfree = true;
};
})
]
++ (
lib.optionals ((lib.lists.length home-modules) > 0)
[
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
}
)
]
++ (lib.optionals ((lib.lists.length home-modules) > 0) [
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]
);
}
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]);
}

View File

@@ -4,32 +4,30 @@
system,
genSpecialArgs,
nixos-modules,
home-modules ? [],
home-modules ? [ ],
specialArgs ? (genSpecialArgs system),
myvars,
...
}: let
}:
let
inherit (inputs) nixpkgs home-manager nixos-generators;
in
nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules =
nixos-modules
++ [
nixos-generators.nixosModules.all-formats
]
++ (
lib.optionals ((lib.lists.length home-modules) > 0)
[
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules =
nixos-modules
++ [
nixos-generators.nixosModules.all-formats
]
++ (lib.optionals ((lib.lists.length home-modules) > 0) [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "home-manager.backup";
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]
);
}
home-manager.extraSpecialArgs = specialArgs;
home-manager.users."${myvars.username}".imports = home-modules;
}
]);
}