1{2 description = "NixOS cluster configuration management";34 inputs = {5 nixpkgs.url = "github:nixos/nixpkgs/release-25.05";6 rust-overlay = {7 url = "github:oxalica/rust-overlay";8 inputs.nixpkgs.follows = "nixpkgs";9 };10 flake-parts = {11 url = "github:hercules-ci/flake-parts";12 inputs.nixpkgs-lib.follows = "nixpkgs";13 };14 crane.url = "github:ipetkov/crane";15 shelly.url = "github:CertainLach/shelly";16 treefmt-nix = {17 url = "github:numtide/treefmt-nix";18 inputs.nixpkgs.follows = "nixpkgs";19 };20 };21 outputs =22 inputs:23 inputs.flake-parts.lib.mkFlake24 {25 inherit inputs;26 }27 {28 imports = [ inputs.shelly.flakeModule ];29 flake = rec {30 lib =31 (import ./lib {32 inherit (inputs.nixpkgs) lib;33 })34 // {35 fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";36 };37 flakeModules.default = import ./lib/flakePart.nix {38 inherit (inputs) crane;39 };40 flakeModule = flakeModules.default;4142 fleetModules.tf = ./modules/extras/tf.nix;4344 45 schemas =46 let47 inherit (inputs.nixpkgs.lib) mapAttrs;48 in49 {50 fleetConfigurations = {51 version = 1;52 doc = ''53 The `fleetConfigurations` flake output defines fleet cluster configurations.54 '';55 inventory = output: {56 children = mapAttrs (configName: cluster: {57 what = "fleet cluster configuration";5859 children = mapAttrs (hostName: host: {60 what = "host [${host.system}]";61 }) cluster.config.hosts;62 63 64 65 }) output;66 };67 };68 };69 };70 71 systems = [72 "x86_64-linux"73 "aarch64-linux"74 "armv7l-linux"75 "armv6l-linux"76 ];77 perSystem =78 {79 config,80 system,81 pkgs,82 self,83 ...84 }:85 let86 inherit (lib.attrsets) mapAttrs';87 inherit (lib.lists) elem;88 89 90 91 92 deployerSystems = [93 "aarch64-linux"94 "x86_64-linux"95 ];96 deployerSystem = elem system deployerSystems;97 lib = pkgs.lib;98 rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;99 craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;100 treefmt = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;101 in102 {103 _module.args.pkgs = import inputs.nixpkgs {104 inherit system;105 overlays = [ (inputs.rust-overlay.overlays.default) ];106 };107 108 packages = lib.mkIf deployerSystem (109 let110 packages = pkgs.callPackages ./pkgs {111 inherit craneLib;112 };113 in114 packages // { default = packages.fleet; }115 );116 117 118 checks =119 let120 nixpkgsCraneLib = inputs.crane.mkLib pkgs;121 packages = pkgs.callPackages ./pkgs {122 craneLib = nixpkgsCraneLib;123 };124 prefixAttrs =125 prefix: attrs:126 mapAttrs' (name: value: {127 name = "${prefix}${name}";128 value = value.overrideAttrs (prev: {129 pname = "${prefix}${prev.pname}";130 });131 }) attrs;132 in133 134 135 (prefixAttrs "nixpkgs-" {136 inherit (packages) fleet-install-secrets;137 })138 // {139 formatting = treefmt.check self;140 };141 142 143 shelly.shells.default = lib.mkIf deployerSystem {144 factory = craneLib.devShell;145 packages = with pkgs; [146 rust147 alejandra148 cargo-edit149 cargo-udeps150 cargo-fuzz151 cargo-watch152 cargo-outdated153154 pkg-config155 openssl156 bacon157 nil158 rustPlatform.bindgenHook159 160 ];161 environment.PROTOC = "${pkgs.protobuf}/bin/protoc";162 };163 formatter = treefmt.wrapper;164 };165 };166}