switch formatting to nixpkgs-fmt

This commit is contained in:
Bryton Hall 2023-07-07 22:01:34 -04:00
parent 3598716c73
commit 2712e89716
65 changed files with 4839 additions and 5222 deletions

View file

@ -1,4 +1,4 @@
{
deployment = import ./deployment {};
testing = import ./testing {};
deployment = import ./deployment { };
testing = import ./testing { };
}

View file

@ -1,8 +1,8 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.${builtins.currentSystem} {
module = {kubenix, ...}: {
module = { kubenix, ... }: {
# instead of defining everything inline, let's import it
imports = [./module.nix];
imports = [ ./module.nix ];
# annotate the generated resources with a project name
kubenix.project = "example";

View file

@ -1,5 +1,5 @@
{kubenix, ...}: {
imports = [kubenix.modules.k8s];
{ kubenix, ... }: {
imports = [ kubenix.modules.k8s ];
kubernetes.resources = {
deployments.nginx.spec = {
@ -50,12 +50,10 @@
services.nginx.spec = {
selector.app = "nginx";
ports = [
{
name = "http";
port = 80;
}
];
ports = [{
name = "http";
port = 80;
}];
};
};
}

View file

@ -1,7 +1,7 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.${builtins.currentSystem} {
module = {kubenix, ...}: {
imports = [kubenix.modules.helm];
module = { kubenix, ... }: {
imports = [ kubenix.modules.helm ];
kubernetes.helm.releases.example = {
chart = kubenix.lib.helm.fetch {
repo = "https://charts.bitnami.com/bitnami";

View file

@ -1,15 +1,10 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.${builtins.currentSystem} {
module = {
kubenix,
config,
pkgs,
...
}: {
imports = with kubenix.modules; [k8s docker];
module = { kubenix, config, pkgs, ... }: {
imports = with kubenix.modules; [ k8s docker ];
docker = {
registry.url = "docker.somewhere.io";
images.example.image = pkgs.callPackage ./image.nix {};
images.example.image = pkgs.callPackage ./image.nix { };
};
kubernetes.resources.pods.example.spec.containers = {
custom.image = config.docker.images.example.path;

View file

@ -1,10 +1,7 @@
{
dockerTools,
nginx,
}:
{ dockerTools, nginx }:
dockerTools.buildLayeredImage {
name = "nginx";
contents = [nginx];
contents = [ nginx ];
extraCommands = ''
mkdir -p etc
chmod u+w etc
@ -12,9 +9,9 @@ dockerTools.buildLayeredImage {
echo "nginx:x:1000:nginx" > etc/group
'';
config = {
Cmd = ["nginx" "-c" "/etc/nginx/nginx.conf"];
Cmd = [ "nginx" "-c" "/etc/nginx/nginx.conf" ];
ExposedPorts = {
"80/tcp" = {};
"80/tcp" = { };
};
};
}

View file

@ -1,7 +1,7 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.${builtins.currentSystem} {
module = {kubenix, ...}: {
imports = [./module.nix];
module = { kubenix, ... }: {
imports = [ ./module.nix ];
kubenix.project = "multi-namespace-example";
kubernetes.version = "1.24";

View file

@ -1,11 +1,5 @@
{
config,
lib,
pkgs,
kubenix,
...
}: {
imports = with kubenix.modules; [submodules k8s];
{ config, lib, pkgs, kubenix, ... }: {
imports = with kubenix.modules; [ submodules k8s ];
# Import submodule.
submodules.imports = [
@ -26,12 +20,10 @@
# Now we can set the args options defined in the submodule.
args.kubernetes.resources = {
services.nginx.spec = {
ports = [
{
name = "http";
port = 80;
}
];
ports = [{
name = "http";
port = 80;
}];
selector.app = "nginx";
};
};
@ -41,12 +33,10 @@
submodule = "namespaced";
args.kubernetes.resources = {
services.nginx.spec = {
ports = [
{
name = "https";
port = 443;
}
];
ports = [{
name = "https";
port = 443;
}];
selector.app = "nginx";
};
};

View file

@ -1,13 +1,12 @@
{
config,
kubenix,
lib,
# Name of submodule instance.
name,
# This is a shorthand for config.submodule.args and contains
{ config
, kubenix
, lib
, # Name of submodule instance.
name
, # This is a shorthand for config.submodule.args and contains
# final values of the args options.
args,
...
args
, ...
}: {
imports = with kubenix.modules; [
# This needs to be imported in order to define a submodule.
@ -25,7 +24,7 @@
# to set kubernetes options from the k8s module which are already
# precisely typed.
type = lib.types.attrs;
default = {};
default = { };
};
};
@ -54,9 +53,9 @@
kubernetes = lib.mkMerge [
# Use instance name as namespace
{namespace = name;}
{ namespace = name; }
# Create namespace object
{resources.namespaces.${name} = {};}
{ resources.namespaces.${name} = { }; }
# All resources defined here will use the above namespace
args.kubernetes
];

View file

@ -1,11 +1,11 @@
# let's creata a function whose only input is the kubenix package
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
# evalModules is our main entrypoint
kubenix.evalModules.${builtins.currentSystem} {
# to it, we pass a module that accepts a (different) kubenix object
module = {kubenix, ...}: {
module = { kubenix, ... }: {
# in order to define options, we need to import their definitions
imports = [kubenix.modules.k8s];
imports = [ kubenix.modules.k8s ];
# now we have full access to define Kubernetes resources
kubernetes.resources.pods = {
# "example" is the name of our pod

View file

@ -1,7 +1,7 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.${builtins.currentSystem} {
module = {kubenix, ...}: {
imports = [kubenix.modules.k8s];
module = { kubenix, ... }: {
imports = [ kubenix.modules.k8s ];
kubernetes.resources.secrets.example.stringData = {
password = "ref+file:///path/to/secret";
};

View file

@ -1,17 +1,15 @@
{kubenix ? import ../../../..}:
{ kubenix ? import ../../../.. }:
kubenix.evalModules.x86_64-linux {
module = {kubenix, ...}: {
imports = [kubenix.modules.testing];
module = { kubenix, ... }: {
imports = [ kubenix.modules.testing ];
testing = {
tests = [./test.nix];
common = [
{
features = ["k8s"];
options = {
kubernetes.version = "1.24";
};
}
];
tests = [ ./test.nix ];
common = [{
features = [ "k8s" ];
options = {
kubernetes.version = "1.24";
};
}];
};
};
}

View file

@ -1,9 +1,5 @@
{
kubenix,
test,
...
}: {
imports = [kubenix.modules.test];
{ kubenix, test, ... }: {
imports = [ kubenix.modules.test ];
test = {
name = "example";

View file

@ -1,14 +1,10 @@
# adapted from: https://discourse.nixos.org/t/franken-script-to-generate-nixos-options-docs-with-custom-modules/1674/4
{
pkgs,
options,
}: let
extraSources = [];
{ pkgs, options }:
let
extraSources = [ ];
lib = pkgs.lib;
optionsListVisible =
lib.filter (opt: opt.visible && !opt.internal)
(lib.optionAttrSetToDocList options);
optionsListVisible = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
# Replace functions by the string <function>
substFunction = x:
@ -24,78 +20,75 @@
isPath = x: (builtins.typeOf x) == "path";
optionsListDesc = lib.flip map optionsListVisible (
opt:
opt
// {
description = let
optionsListDesc = lib.flip map optionsListVisible (opt:
opt // {
description =
let
attempt = builtins.tryEval opt.description;
in
if attempt.success
then attempt.value
else "N/A";
declarations = map stripAnyPrefixes opt.declarations;
}
// lib.optionalAttrs (opt ? example) {
example = substFunction opt.example;
}
// lib.optionalAttrs (opt ? default) {
default = substFunction opt.default;
}
// lib.optionalAttrs (opt ? type) {
type = substFunction opt.type;
}
// lib.optionalAttrs
(opt ? relatedPackages && opt.relatedPackages != [])
{
relatedPackages = genRelatedPackages opt.relatedPackages;
}
if attempt.success
then attempt.value
else "N/A";
declarations = map stripAnyPrefixes opt.declarations;
} // lib.optionalAttrs (opt ? example) {
example = substFunction opt.example;
} // lib.optionalAttrs (opt ? default) {
default = substFunction opt.default;
} // lib.optionalAttrs (opt ? type) {
type = substFunction opt.type;
} // lib.optionalAttrs (opt ? relatedPackages && opt.relatedPackages != [ ]) {
relatedPackages = genRelatedPackages opt.relatedPackages;
}
);
genRelatedPackages = packages: let
unpack = p:
if lib.isString p
then {name = p;}
else if lib.isList p
then {path = p;}
else p;
describe = args: let
title = args.title or null;
name = args.name or (lib.concatStringsSep "." args.path);
path = args.path or [args.name];
package =
args.package
or (lib.attrByPath path
(throw
"Invalid package attribute path '${toString path}'")
pkgs);
in
"<listitem>"
+ "<para><literal>${lib.optionalString (title != null)
genRelatedPackages = packages:
let
unpack = p:
if lib.isString p
then { name = p; }
else if lib.isList p
then { path = p; }
else p;
describe = args:
let
title = args.title or null;
name = args.name or (lib.concatStringsSep "." args.path);
path = args.path or [ args.name ];
package =
args.package
or (lib.attrByPath path
(throw
"Invalid package attribute path '${toString path}'")
pkgs);
in
"<listitem>"
+ "<para><literal>${lib.optionalString (title != null)
"${title} aka "}pkgs.${name} (${package.meta.name})</literal>"
+ lib.optionalString (!package.meta.available)
" <emphasis>[UNAVAILABLE]</emphasis>"
+ ": ${package.meta.description or "???"}.</para>"
+ lib.optionalString (args ? comment)
"\n<para>${args.comment}</para>"
+ lib.optionalString (package.meta ? longDescription)
"\n<programlisting>${package.meta.longDescription}"
+ "</programlisting>"
+ "</listitem>";
in "<itemizedlist>${lib.concatStringsSep "\n" (map (p:
+ lib.optionalString (!package.meta.available)
" <emphasis>[UNAVAILABLE]</emphasis>"
+ ": ${package.meta.description or "???"}.</para>"
+ lib.optionalString (args ? comment)
"\n<para>${args.comment}</para>"
+ lib.optionalString (package.meta ? longDescription)
"\n<programlisting>${package.meta.longDescription}"
+ "</programlisting>"
+ "</listitem>";
in
"<itemizedlist>${lib.concatStringsSep "\n" (map (p:
describe (unpack p))
packages)}</itemizedlist>";
optionLess = a: b: let
ise = lib.hasPrefix "enable";
isp = lib.hasPrefix "package";
cmp =
lib.splitByAndCompare ise lib.compare
(lib.splitByAndCompare isp lib.compare lib.compare);
in
optionLess = a: b:
let
ise = lib.hasPrefix "enable";
isp = lib.hasPrefix "package";
cmp =
lib.splitByAndCompare ise lib.compare
(lib.splitByAndCompare isp lib.compare lib.compare);
in
lib.compareLists cmp a.loc b.loc < 0;
prefixesToStrip = map (p: "${toString p}/") ([../../..] ++ extraSources);
prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
###############################################################################
@ -119,4 +112,4 @@
})
optionsList)));
in
pkgs.writeText "options.json" optionsJSON
pkgs.writeText "options.json" optionsJSON