git.delta.rocks / jrsonnet / refs/commits / 94ece5cae749

difftreelog

source

flake.nix5.8 KiBsourcehistory
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          # To be used with https://github.com/NixOS/nix/pull/889245          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                    # It is possible to implement this inventory right now, but I want to63                    # get rid of `fleet.nix` file in the future.64                    # children.secrets = { };65                  }) output;66                };67              };68            };69        };70        # Supported and tested list of deployment targets.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            # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.89            # I have no hardware for such testing, thus only adding machines I actually have and use.90            #91            # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.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            # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.108            packages = lib.mkIf deployerSystem (109              let110                packages = pkgs.callPackages ./pkgs {111                  inherit craneLib;112                };113              in114              packages // { default = packages.fleet; }115            );116            # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.117            # checks there build packages for default nixpkgs rustPlatform packages.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              # fleet-install-secrets is installed to remote systems, thus needs to work134              # with rust in nixpkgs.135              (prefixAttrs "nixpkgs-" {136                inherit (packages) fleet-install-secrets;137              })138              // {139                formatting = treefmt.check self;140              };141            # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole142            # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?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                # nixVersions.nix_2_22160              ];161              environment.PROTOC = "${pkgs.protobuf}/bin/protoc";162            };163            formatter = treefmt.wrapper;164          };165      };166}