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 22 nix.url = "/home/lach/build/nix-src";23 };24 outputs =25 inputs:26 inputs.flake-parts.lib.mkFlake27 {28 inherit inputs;29 }30 {31 imports = [ inputs.shelly.flakeModule ];32 flake = rec {33 lib =34 (import ./lib {35 inherit (inputs.nixpkgs) lib;36 })37 // {38 fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";39 };40 flakeModules.default = import ./lib/flakePart.nix {41 inherit (inputs) crane;42 };43 flakeModule = flakeModules.default;4445 fleetModules.tf = ./modules/extras/tf.nix;4647 testObj = {48 v = "Hello";49 };50 testString = "hello";5152 53 schemas =54 let55 inherit (inputs.nixpkgs.lib) mapAttrs;56 in57 {58 fleetConfigurations = {59 version = 1;60 doc = ''61 The `fleetConfigurations` flake output defines fleet cluster configurations.62 '';63 inventory = output: {64 children = mapAttrs (configName: cluster: {65 what = "fleet cluster configuration";6667 children = mapAttrs (hostName: host: {68 what = "host [${host.system}]";69 }) cluster.config.hosts;70 71 72 73 }) output;74 };75 };76 };77 };78 79 systems = [80 "x86_64-linux"81 "aarch64-linux"82 "armv7l-linux"83 "armv6l-linux"84 ];85 perSystem =86 {87 config,88 system,89 pkgs,90 self,91 inputs',92 ...93 }:94 let95 inherit (lib.attrsets) mapAttrs';96 inherit (lib.lists) elem;97 98 99 100 101 deployerSystems = [102 "aarch64-linux"103 "x86_64-linux"104 ];105 deployerSystem = elem system deployerSystems;106 lib = pkgs.lib;107 rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;108 craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;109 treefmt = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;110 in111 {112 _module.args.pkgs = import inputs.nixpkgs {113 inherit system;114 overlays = [ (inputs.rust-overlay.overlays.default) ];115 };116 117 packages = lib.mkIf deployerSystem (118 let119 packages = pkgs.callPackages ./pkgs {120 inherit craneLib inputs';121 };122 in123 packages // { default = packages.fleet; }124 );125 126 127 checks =128 let129 nixpkgsCraneLib = inputs.crane.mkLib pkgs;130 packages = pkgs.callPackages ./pkgs {131 craneLib = nixpkgsCraneLib;132 inherit inputs;133 };134 prefixAttrs =135 prefix: attrs:136 mapAttrs' (name: value: {137 name = "${prefix}${name}";138 value = value.overrideAttrs (prev: {139 pname = "${prefix}${prev.pname}";140 });141 }) attrs;142 in143 144 145 (prefixAttrs "nixpkgs-" {146 inherit (packages) fleet-install-secrets;147 })148 // {149 formatting = treefmt.check self;150 };151 152 153 shelly.shells.default = lib.mkIf deployerSystem {154 factory = craneLib.devShell;155 packages = with pkgs; [156 rust157 alejandra158 cargo-edit159 cargo-udeps160 cargo-fuzz161 cargo-watch162 cargo-outdated163 gdb164165 pkg-config166 openssl167 bacon168 nil169 rustPlatform.bindgenHook170 inputs'.nix.packages.nix-expr-c171 inputs'.nix.packages.nix-flake-c172 inputs'.nix.packages.nix-fetchers-c173 ];174 environment.PROTOC = "${pkgs.protobuf}/bin/protoc";175 };176 formatter = treefmt.wrapper;177 };178 };179}