diff --git a/default.nix b/default.nix index fec8859..1596a26 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,4 @@ -{system ? builtins.currentSystem}: let -in - ( +{system ? builtins.currentSystem}: ( (import ./compat.nix).flake-compat { src = ./.; inherit system; diff --git a/examples/nginx-deployment/default.nix b/examples/nginx-deployment/default.nix index 2b7adf3..e8a015a 100644 --- a/examples/nginx-deployment/default.nix +++ b/examples/nginx-deployment/default.nix @@ -3,8 +3,7 @@ registry, }: let # evaluated configuration - config = - (evalModules { + inherit ((evalModules { module = {kubenix, ...}: { imports = [ kubenix.modules.testing @@ -30,8 +29,7 @@ ]; }; }; - }) - .config; + })) config; in { inherit config; @@ -45,10 +43,10 @@ in { test-script = config.testing.testsByName.nginx-deployment.script; # genreated kubernetes List object - generated = config.kubernetes.generated; + inherit (config.kubernetes) generated; # JSON file you can deploy to kubernetes - result = config.kubernetes.result; + inherit (config.kubernetes) result; # Exported docker images images = config.docker.export; diff --git a/flake.nix b/flake.nix index 21c6066..875c222 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ inherit system; }; - lib = pkgs.lib; + inherit (pkgs) lib; kubenix = { lib = import ./lib {inherit lib pkgs;}; @@ -71,7 +71,7 @@ checks = let wasSuccess = suite: - if suite.success == true + if suite.success then pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-succeeded" {} "echo success > $out" else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" {} "exit 1"; mkExamples = attrs: diff --git a/jobs/generators/istio/default.nix b/jobs/generators/istio/default.nix index 39a349a..cb1de5a 100644 --- a/jobs/generators/istio/default.nix +++ b/jobs/generators/istio/default.nix @@ -84,7 +84,7 @@ with lib; let refDefinition = attr: head (tail (tail (splitString "/" attr."$ref"))); }; - fixJSON = content: replaceStrings ["\\u"] ["u"] content; + fixJSON = replaceStrings ["\\u"] ["u"]; fetchSpecs = path: builtins.fromJSON (fixJSON (builtins.readFile path)); diff --git a/jobs/generators/k8s/default.nix b/jobs/generators/k8s/default.nix index 4dc1991..d3e03e6 100644 --- a/jobs/generators/k8s/default.nix +++ b/jobs/generators/k8s/default.nix @@ -88,7 +88,7 @@ with lib; let refType = attr: head (tail (tail (splitString "/" attr."$ref"))); compareVersions = ver1: ver2: let - getVersion = v: substring 1 10 v; + getVersion = substring 1 10; splitVersion = v: builtins.splitVersion (getVersion v); isAlpha = v: elem "alpha" (splitVersion v); patchVersion = v: @@ -103,7 +103,7 @@ with lib; let in builtins.compareVersions v1 v2; - fixJSON = content: replaceStrings ["\\u"] ["u"] content; + fixJSON = replaceStrings ["\\u"] ["u"]; fetchSpecs = path: builtins.fromJSON (fixJSON (builtins.readFile path)); @@ -266,7 +266,7 @@ with lib; let else group'; version = version'; kind = kind'; - description = swagger.definitions.${ref}.description; + inherit (swagger.definitions.${ref}) description; defintion = refDefinition (head path.post.parameters).schema; }) (filterAttrs @@ -301,7 +301,7 @@ with lib; let resourceTypesByKind; latestResourceTypesByKind = - mapAttrs (_kind: resources: last resources) resourcesTypesByKindSortByVersion; + mapAttrs (_kind: last) resourcesTypesByKindSortByVersion; genResourceOptions = resource: with gen; let @@ -313,7 +313,7 @@ with lib; let definition.version; in mkOption { - description = resource.description; + inherit (resource) description; type = types.attrsOf (submoduleForDefinition' resource); default = {}; }; diff --git a/lib/helm/fetchhelm.nix b/lib/helm/fetchhelm.nix index 177c4dc..19802f2 100644 --- a/lib/helm/fetchhelm.nix +++ b/lib/helm/fetchhelm.nix @@ -4,7 +4,7 @@ kubernetes-helm, cacert, }: let - cleanName = name: lib.replaceStrings ["/"] ["-"] name; + cleanName = lib.replaceStrings ["/"] ["-"]; in { # name of the chart diff --git a/lib/k8s/default.nix b/lib/k8s/default.nix index 20a5495..1edffdb 100644 --- a/lib/k8s/default.nix +++ b/lib/k8s/default.nix @@ -80,6 +80,6 @@ with lib; rec { // labels; }; - toBase64 = lib.toBase64; - octalToDecimal = lib.octalToDecimal; + inherit (lib) toBase64; + inherit (lib) octalToDecimal; } diff --git a/modules/base.nix b/modules/base.nix index a58eb5c..d55c69b 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -18,7 +18,7 @@ with lib; { _m.propagate = mkOption { description = "Module propagation options"; - type = types.listOf (types.submodule ({ ...}: { + type = types.listOf (types.submodule (_: { options = { features = mkOption { description = "List of features that submodule has to have to propagate module"; diff --git a/modules/docker.nix b/modules/docker.nix index f638cef..c033dff 100644 --- a/modules/docker.nix +++ b/modules/docker.nix @@ -86,9 +86,7 @@ in { _m.propagate = [ { features = ["docker"]; - module = { - ... - }: { + module = _: { # propagate registry options docker.registry = cfg.registry; }; diff --git a/modules/generated/v1.19.nix b/modules/generated/v1.19.nix index e07f26f..46d888b 100644 --- a/modules/generated/v1.19.nix +++ b/modules/generated/v1.19.nix @@ -39,8 +39,8 @@ with lib; let else let coerced = coerceFunc val; in assert finalType.check coerced; coerced; in finalType.merge loc (map (def: def // {value = coerceVal def.value;}) defs); - getSubOptions = finalType.getSubOptions; - getSubModules = finalType.getSubModules; + inherit (finalType) getSubOptions; + inherit (finalType) getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = _t1: _t2: null; functor = (defaultFunctor name) // {wrapped = finalType;}; @@ -62,7 +62,7 @@ with lib; let values); submoduleOf = ref: - types.submodule ({ ...}: { + types.submodule (_: { options = definitions."${ref}".options or {}; config = definitions."${ref}".config or {}; }); @@ -74,7 +74,7 @@ with lib; let then toInt name else name; in { - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = definitions."${ref}".config // { @@ -90,7 +90,7 @@ with lib; let in types.submodule ({name, ...}: { imports = getDefaults resource group version kind; - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = mkMerge [ definitions."${ref}".config { diff --git a/modules/generated/v1.20.nix b/modules/generated/v1.20.nix index d04735a..07772f0 100644 --- a/modules/generated/v1.20.nix +++ b/modules/generated/v1.20.nix @@ -39,8 +39,8 @@ with lib; let else let coerced = coerceFunc val; in assert finalType.check coerced; coerced; in finalType.merge loc (map (def: def // {value = coerceVal def.value;}) defs); - getSubOptions = finalType.getSubOptions; - getSubModules = finalType.getSubModules; + inherit (finalType) getSubOptions; + inherit (finalType) getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = _t1: _t2: null; functor = (defaultFunctor name) // {wrapped = finalType;}; @@ -62,7 +62,7 @@ with lib; let values); submoduleOf = ref: - types.submodule ({ ...}: { + types.submodule (_: { options = definitions."${ref}".options or {}; config = definitions."${ref}".config or {}; }); @@ -74,7 +74,7 @@ with lib; let then toInt name else name; in { - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = definitions."${ref}".config // { @@ -90,7 +90,7 @@ with lib; let in types.submodule ({name, ...}: { imports = getDefaults resource group version kind; - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = mkMerge [ definitions."${ref}".config { diff --git a/modules/generated/v1.21.nix b/modules/generated/v1.21.nix index 31546a7..e764077 100644 --- a/modules/generated/v1.21.nix +++ b/modules/generated/v1.21.nix @@ -39,8 +39,8 @@ with lib; let else let coerced = coerceFunc val; in assert finalType.check coerced; coerced; in finalType.merge loc (map (def: def // {value = coerceVal def.value;}) defs); - getSubOptions = finalType.getSubOptions; - getSubModules = finalType.getSubModules; + inherit (finalType) getSubOptions; + inherit (finalType) getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = _t1: _t2: null; functor = (defaultFunctor name) // {wrapped = finalType;}; @@ -62,7 +62,7 @@ with lib; let values); submoduleOf = ref: - types.submodule ({ ...}: { + types.submodule (_: { options = definitions."${ref}".options or {}; config = definitions."${ref}".config or {}; }); @@ -74,7 +74,7 @@ with lib; let then toInt name else name; in { - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = definitions."${ref}".config // { @@ -90,7 +90,7 @@ with lib; let in types.submodule ({name, ...}: { imports = getDefaults resource group version kind; - options = definitions."${ref}".options; + inherit (definitions."${ref}") options; config = mkMerge [ definitions."${ref}".config { diff --git a/modules/helm.nix b/modules/helm.nix index 2905a83..4294151 100644 --- a/modules/helm.nix +++ b/modules/helm.nix @@ -112,7 +112,7 @@ in { map (object: let apiVersion = parseApiVersion object.apiVersion; - name = object.metadata.name; + inherit (object.metadata) name; in { "${apiVersion.group}"."${apiVersion.version}".${object.kind}."${name}" = mkMerge ([ object diff --git a/modules/istio.nix b/modules/istio.nix index 0f6324f..1ca6e44 100644 --- a/modules/istio.nix +++ b/modules/istio.nix @@ -32,8 +32,8 @@ with lib; let assert finalType.check coerced; coerced; in finalType.merge loc (map (def: def // {value = coerceVal def.value;}) defs); - getSubOptions = finalType.getSubOptions; - getSubModules = finalType.getSubModules; + inherit (finalType) getSubOptions; + inherit (finalType) getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = _t1: _t2: null; functor = (defaultFunctor name) // {wrapped = finalType;}; @@ -41,9 +41,9 @@ with lib; let }; submoduleOf = ref: - types.submodule ({ ...}: { - options = definitions."${ref}".options; - config = definitions."${ref}".config; + types.submodule (_: { + inherit (definitions."${ref}") options; + inherit (definitions."${ref}") config; }); definitions = diff --git a/modules/k8s.nix b/modules/k8s.nix index b22ddba..71f3ed0 100644 --- a/modules/k8s.nix +++ b/modules/k8s.nix @@ -25,9 +25,9 @@ with lib; let moduleToAttrs = value: if isAttrs value - then mapAttrs (_n: v: moduleToAttrs v) (filterAttrs (n: v: v != null && !(hasPrefix "_" n)) value) + then mapAttrs (_n: moduleToAttrs) (filterAttrs (n: v: v != null && !(hasPrefix "_" n)) value) else if isList value - then map (v: moduleToAttrs v) value + then map moduleToAttrs value else value; apiOptions = {config, ...}: { @@ -38,7 +38,7 @@ with lib; let defaults = mkOption { description = "Kubernetes defaults to apply to resources"; - type = types.listOf (types.submodule ({ ...}: { + type = types.listOf (types.submodule (_: { options = { group = mkOption { description = "Group to apply default to (all by default)"; @@ -132,7 +132,7 @@ with lib; let lst)); compareVersions = ver1: ver2: let - getVersion = v: substring 1 10 v; + getVersion = substring 1 10; splittedVer1 = builtins.splitVersion (getVersion ver1); splittedVer2 = builtins.splitVersion (getVersion ver2); @@ -167,7 +167,7 @@ with lib; let customResourceTypesByAttrName; latestCustomResourceTypes = - mapAttrsToList (_: resources: last resources) customResourceTypesByAttrNameSortByVersion; + mapAttrsToList (_: last) customResourceTypesByAttrNameSortByVersion; customResourceModuleForType = config: ct: {name, ...}: { imports = getDefaults ct.name ct.group ct.version ct.kind; @@ -207,7 +207,7 @@ with lib; let module = customResourceModuleForType config ct; in { options.resources.${ct.group}.${ct.version}.${ct.kind} = mkOption { - description = ct.description; + inherit (ct) description; type = types.attrsOf (types.submodule module); default = {}; }; @@ -222,7 +222,7 @@ with lib; let module = customResourceModuleForType config ct; in { options.resources.${ct.attrName} = mkOption { - description = ct.description; + inherit (ct) description; type = types.attrsOf (types.submodule module); default = {}; }; @@ -255,8 +255,8 @@ with lib; let else let coerced = coerceFunc val; in assert finalType.check coerced; coerced; in finalType.merge loc (map (def: def // {value = coerceVal def.value;}) defs); - getSubOptions = finalType.getSubOptions; - getSubModules = finalType.getSubModules; + inherit (finalType) getSubOptions; + inherit (finalType) getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = _t1: _t2: null; functor = (defaultFunctor name) // {wrapped = finalType;}; @@ -405,7 +405,7 @@ in { _m.propagate = [ { features = ["k8s"]; - module = { ...}: { + module = _: { # propagate kubernetes version and namespace kubernetes.version = mkDefault cfg.version; kubernetes.namespace = mkDefault cfg.namespace; @@ -415,9 +415,7 @@ in { features = ["k8s" "submodule"]; module = {config, ...}: { # set module defaults - kubernetes.api.defaults = ( - # propagate defaults if default propagation is enabled - (filter (default: default.propagate) cfg.api.defaults) + kubernetes.api.defaults = (filter (default: default.propagate) cfg.api.defaults) ++ [ # set module name and version for all kuberentes resources { @@ -426,8 +424,7 @@ in { "kubenix/module-version" = config.submodule.version; }; } - ] - ); + ]; }; } ]; @@ -470,13 +467,13 @@ in { # load yaml file object = importYAML i; groupVersion = splitString "/" object.apiVersion; - name = object.metadata.name; + inherit (object.metadata) name; version = last groupVersion; group = if version == (head groupVersion) then "core" else head groupVersion; - kind = object.kind; + inherit (object) kind; in { resources.${group}.${version}.${kind}.${name} = object; }) @@ -485,7 +482,7 @@ in { kubernetes.objects = flatten (mapAttrsToList ( _: type: - mapAttrsToList (_name: resource: moduleToAttrs resource) + mapAttrsToList (_name: moduleToAttrs) cfg.api.resources.${type.group}.${type.version}.${type.kind} ) cfg.api.types); @@ -500,6 +497,6 @@ in { pkgs.writeText "${config.kubenix.project}-generated.json" (builtins.toJSON cfg.generated); kubernetes.resultYAML = - toMultiDocumentYaml "${config.kubenix.project}-generated.yaml" (config.kubernetes.objects); + toMultiDocumentYaml "${config.kubenix.project}-generated.yaml" config.kubernetes.objects; }; } diff --git a/modules/submodules.nix b/modules/submodules.nix index 4734cc4..5abec05 100644 --- a/modules/submodules.nix +++ b/modules/submodules.nix @@ -177,7 +177,7 @@ in { submodules.defaults = mkOption { description = "List of defaults to apply to submodule instances"; - type = types.listOf (types.submodule ({ ...}: { + type = types.listOf (types.submodule (_: { options = { name = mkOption { description = "Name of the submodule to apply defaults for"; @@ -279,7 +279,7 @@ in { inherit (evaledSubmodule.config.submodule) name description version tags exports; }; - features = evaledSubmodule.config._m.features; + inherit (evaledSubmodule.config._m) features; }; }) ) @@ -299,7 +299,7 @@ in { # submodule associated with submodule = findSubmodule { name = config.submodule; - version = config.version; + inherit (config) version; }; # definition of a submodule @@ -307,10 +307,10 @@ in { # submodule defaults defaults = getDefaults { - name = submoduleDefinition.name; - version = submoduleDefinition.version; - tags = submoduleDefinition.tags; - features = submodule.features; + inherit (submoduleDefinition) name; + inherit (submoduleDefinition) version; + inherit (submoduleDefinition) tags; + inherit (submodule) features; }; in { options = { @@ -390,7 +390,7 @@ in { (map (propagate: { - features = propagate.features; + inherit (propagate) features; default = propagate.module; }) config._m.propagate) @@ -404,8 +404,8 @@ in { features = ["submodules"]; default = { submodules = { - defaults = cfg.defaults; - imports = cfg.imports; + inherit (cfg) defaults; + inherit (cfg) imports; }; }; } diff --git a/modules/testing/default.nix b/modules/testing/default.nix index f77ad8e..95ee1c7 100644 --- a/modules/testing/default.nix +++ b/modules/testing/default.nix @@ -43,7 +43,7 @@ in { common = mkOption { description = "List of common options to apply to tests"; - type = types.listOf (types.submodule ({ ...}: { + type = types.listOf (types.submodule (_: { options = { features = mkOption { description = "List of features that test has to have to apply options"; @@ -70,7 +70,7 @@ in { inherit module; }) (types.submodule testModule)); - apply = tests: filter isTestEnabled tests; + apply = filter isTestEnabled; }; testsByName = mkOption { diff --git a/modules/testing/docker.nix b/modules/testing/docker.nix index 53b589c..ec519c6 100644 --- a/modules/testing/docker.nix +++ b/modules/testing/docker.nix @@ -6,7 +6,7 @@ }: with lib; with import ../../lib/docker {inherit lib pkgs;}; let - testing = config.testing; + inherit (config) testing; allImages = unique (flatten (map (t: t.evaled.config.docker.export or []) testing.tests)); @@ -33,7 +33,7 @@ in { images = allImages; copyScript = copyDockerImages { - images = cfg.images; + inherit (cfg) images; dest = "docker://" + cfg.registryUrl; }; }; diff --git a/modules/testing/driver/kubetest.nix b/modules/testing/driver/kubetest.nix index 65ef084..8edbe49 100644 --- a/modules/testing/driver/kubetest.nix +++ b/modules/testing/driver/kubetest.nix @@ -5,7 +5,7 @@ ... }: with lib; let - testing = config.testing; + inherit (config) testing; cfg = testing.driver.kubetest; kubetest = import ./kubetestdrv.nix {inherit pkgs;}; diff --git a/modules/testing/runtime/local.nix b/modules/testing/runtime/local.nix index 3862a76..b443f20 100644 --- a/modules/testing/runtime/local.nix +++ b/modules/testing/runtime/local.nix @@ -5,7 +5,7 @@ ... }: with lib; let - testing = config.testing; + inherit (config) testing; script = pkgs.writeScript "run-local-k8s-tests-${testing.name}.sh" '' #!${pkgs.runtimeShell} diff --git a/modules/testing/runtime/nixos-k8s.nix b/modules/testing/runtime/nixos-k8s.nix index 41a1be2..ea55a1c 100644 --- a/modules/testing/runtime/nixos-k8s.nix +++ b/modules/testing/runtime/nixos-k8s.nix @@ -6,7 +6,7 @@ ... }: with lib; let - testing = config.testing; + inherit (config) testing; # kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}"; kubeconfig = "/etc/kubernetes/cluster-admin.kubeconfig"; kubecerts = "/var/lib/kubernetes/secrets"; diff --git a/shell.nix b/shell.nix index 9fddb78..6b2af31 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,4 @@ -{system ? builtins.currentSystem}: let -in - ( +{system ? builtins.currentSystem}: ( (import ./compat.nix).flake-compat { src = ./.; inherit system; diff --git a/tests/default.nix b/tests/default.nix index e454a9b..df57e09 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -7,8 +7,7 @@ doThrowError ? true, # whether any testing error should throw an error enabledTests ? null, }: let - config = - (evalModules { + inherit ((evalModules { module = { kubenix, pkgs, @@ -49,7 +48,6 @@ ]; }; }; - }) - .config; + })) config; in config.testing // {recurseForDerivations = true;} diff --git a/tests/k8s/defaults.nix b/tests/k8s/defaults.nix index 91e4de3..2cb8b1c 100644 --- a/tests/k8s/defaults.nix +++ b/tests/k8s/defaults.nix @@ -5,8 +5,8 @@ ... }: with lib; let - pod1 = config.kubernetes.api.resources.pods.pod1; - pod2 = config.kubernetes.api.resources.pods.pod2; + inherit (config.kubernetes.api.resources.pods) pod1; + inherit (config.kubernetes.api.resources.pods) pod2; in { imports = with kubenix.modules; [test k8s]; diff --git a/tests/k8s/deployment.nix b/tests/k8s/deployment.nix index 7819bce..768c242 100644 --- a/tests/k8s/deployment.nix +++ b/tests/k8s/deployment.nix @@ -14,7 +14,7 @@ with lib; let apiVersion = "v1"; kind = "Pod"; metadata = { - namespace = config.kubernetes.namespace; + inherit (config.kubernetes) namespace; name = "curl"; }; spec.containers = [ diff --git a/tests/submodules/defaults.nix b/tests/submodules/defaults.nix index d4dca40..e9de06a 100644 --- a/tests/submodules/defaults.nix +++ b/tests/submodules/defaults.nix @@ -6,12 +6,12 @@ ... }: with lib; let - instance1 = config.submodules.instances.instance1; - instance2 = config.submodules.instances.instance2; - instance3 = config.submodules.instances.instance3; - instance4 = config.submodules.instances.instance4; - instance5 = config.submodules.instances.instance5; - versioned-submodule = config.submodules.instances.versioned-submodule; + inherit (config.submodules.instances) instance1; + inherit (config.submodules.instances) instance2; + inherit (config.submodules.instances) instance3; + inherit (config.submodules.instances) instance4; + inherit (config.submodules.instances) instance5; + inherit (config.submodules.instances) versioned-submodule; submodule = { ...}: { imports = [kubenix.modules.submodule]; diff --git a/tests/submodules/simple.nix b/tests/submodules/simple.nix index 40ea7ef..a109abf 100644 --- a/tests/submodules/simple.nix +++ b/tests/submodules/simple.nix @@ -7,7 +7,7 @@ }: with lib; let cfg = config.submodules.instances.instance; - args = cfg.config.submodule.args; + inherit (cfg.config.submodule) args; in { imports = with kubenix.modules; [test submodules]; @@ -37,7 +37,7 @@ in { } { message = "should have tag set"; - assertion = elem "tag" (cfg.config.submodule.tags); + assertion = elem "tag" cfg.config.submodule.tags; } ]; };