git.delta.rocks / jrsonnet / refs/commits / b56a5a338d1e

difftreelog

ci add flake outputs formatter, schemas

Yaroslav Bolyukin2024-06-03parent: #7c29776.patch.diff
in: trunk

4 files changed

modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -36,6 +36,31 @@
               craneLib = crane.mkLib pkgs;
             };
         };
+        # To be used with https://github.com/NixOS/nix/pull/8892
+        schemas = {
+          fleetConfigurations = {
+            version = 1;
+            doc = ''
+              The `fleetConfigurations` flake output defines fleet cluster configurations.
+            '';
+            inventory = output: {
+              children =
+                builtins.mapAttrs (configName: cluster: {
+                  what = "fleet cluster configuration";
+
+                  children =
+                    builtins.mapAttrs (hostName: host: {
+                      what = "host [${host.system}]";
+                    })
+                    cluster.config.hosts;
+                  # It is possible to implement this inventory right now, but I want to
+                  # get rid of `fleet.nix` file in the future.
+                  # children.secrets = { };
+                })
+                output;
+            };
+          };
+        };
       };
       # Supported and tested list of deployment targets.
       systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];
@@ -108,6 +133,7 @@
           # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.
           (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]))
           // (prefixAttrs "nixpkgs-stable-" (removeAttrs packages-with-nixpkgs-stable ["fleet"]));
+        formatter = pkgs.alejandra;
       };
     };
 }
modifiedlib/default.nixdiffbeforeafterboth
before · lib/default.nix
1{2  fleetPkgsForPkgs,3}: {4  fleetConfiguration = {5    # TODO: Provide by fleet, instead of requesting user to provide it.6    # This is not good that user needs to provide it, as it becomes a flake data, and fleet arbitrarily rewriting it7    # always dirnets the flake. Instead, fleetConfiguration should return function, parameters of which should be filled8    # by fleet itself, which is possible since fleet moving to nix repl execution.9    data,10    nixpkgs,11    overlays ? [],12    hosts,13    fleetModules,14    nixosModules ? [],15    extraFleetLib ? {},16  }: let17    hostNames = nixpkgs.lib.attrNames hosts;18    fleetLib =19      (import ./fleetLib.nix {20        inherit nixpkgs hostNames;21      })22      // extraFleetLib;23  in let24    root = nixpkgs.lib.evalModules {25      modules =26        (import ../modules/fleet/_modules.nix)27        ++ [28          data29          ({...}: {30            inherit nixosModules hosts;31            overlays = [(final: prev: (fleetPkgsForPkgs final))] ++ overlays;32          })33        ]34        ++ fleetModules;35      specialArgs = {36        inherit nixpkgs fleetLib;37      };38    };39    failedAssertions = map (x: x.message) (nixpkgs.lib.filter (x: !x.assertion) root.config.assertions);40    checkedRoot =41      if failedAssertions != []42      then throw "Fleet failed assertions:\n${nixpkgs.lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"43      else nixpkgs.lib.showWarnings root.config.warnings root;44    withData = {45      root,46      data,47    }: {48      config = root.config;49    };50    defaultData = withData {51      inherit data;52      root = checkedRoot;53    };54    uncheckedData = withData {inherit data root;};55  in {56    inherit nixpkgs overlays;57    inherit (defaultData) config;58    unchecked = {59      inherit (uncheckedData) config;60    };61  };62}
after · lib/default.nix
1{fleetPkgsForPkgs}: {2  fleetConfiguration = {3    # TODO: Provide by fleet, instead of requesting user to provide it.4    # This is not good that user needs to provide it, as it becomes a flake data, and fleet arbitrarily rewriting it5    # always dirnets the flake. Instead, fleetConfiguration should return function, parameters of which should be filled6    # by fleet itself, which is possible since fleet moving to nix repl execution.7    data,8    nixpkgs,9    overlays ? [],10    hosts,11    fleetModules,12    nixosModules ? [],13    extraFleetLib ? {},14  }: let15    hostNames = nixpkgs.lib.attrNames hosts;16    fleetLib =17      (import ./fleetLib.nix {18        inherit nixpkgs hostNames;19      })20      // extraFleetLib;21  in let22    root = nixpkgs.lib.evalModules {23      modules =24        (import ../modules/fleet/_modules.nix)25        ++ [26          data27          ({...}: {28            inherit nixosModules hosts;29            overlays = [(final: prev: (fleetPkgsForPkgs final))] ++ overlays;30          })31        ]32        ++ fleetModules;33      specialArgs = {34        inherit nixpkgs fleetLib;35      };36    };37    failedAssertions = map (x: x.message) (nixpkgs.lib.filter (x: !x.assertion) root.config.assertions);38    checkedRoot =39      if failedAssertions != []40      then throw "Fleet failed assertions:\n${nixpkgs.lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"41      else nixpkgs.lib.showWarnings root.config.warnings root;42    withData = {43      root,44      data,45    }: {46      config = root.config;47    };48    defaultData = withData {49      inherit data;50      root = checkedRoot;51    };52    uncheckedData = withData {inherit data root;};53  in {54    inherit nixpkgs overlays;55    inherit (defaultData) config;56    unchecked = {57      inherit (uncheckedData) config;58    };59  };60}
modifiedmodules/fleet/assertions.nixdiffbeforeafterboth
--- a/modules/fleet/assertions.nix
+++ b/modules/fleet/assertions.nix
@@ -1,16 +1,16 @@
-{ lib, ... }:
-
-with lib;
-
-{
-
+{lib, ...}:
+with lib; {
   options = {
-
     assertions = mkOption {
       type = types.listOf types.unspecified;
       internal = true;
-      default = [ ];
-      example = [{ assertion = false; message = "you can't enable this for that reason"; }];
+      default = [];
+      example = [
+        {
+          assertion = false;
+          message = "you can't enable this for that reason";
+        }
+      ];
       description = ''
         This option allows modules to express conditions that must
         hold for the evaluation of the system configuration to
@@ -20,15 +20,14 @@
 
     warnings = mkOption {
       internal = true;
-      default = [ ];
+      default = [];
       type = types.listOf types.str;
-      example = [ "The `foo' service is deprecated and will go away soon!" ];
+      example = ["The `foo' service is deprecated and will go away soon!"];
       description = ''
         This option allows modules to show warnings to users during
         the evaluation of the system configuration.
       '';
     };
-
   };
   # impl of assertions is in <fleet/lib/default.nix>
 }
modifiedpkgs/generator-helper.nixdiffbeforeafterboth
--- a/pkgs/generator-helper.nix
+++ b/pkgs/generator-helper.nix
@@ -1,4 +1,3 @@
-
 {craneLib}:
 craneLib.buildPackage rec {
   pname = "fleet-generator-helper";
@@ -9,6 +8,6 @@
   cargoExtraArgs = "--locked -p ${pname}";
 
   postInstall = ''
-		mv bin/${pname} bin/genhelper
+    mv bin/${pname} bin/genhelper
   '';
 }