git.delta.rocks / jrsonnet / refs/commits / 521a65806d80

difftreelog

source

flake.nix6.3 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    # DeterminateSystem's nix fork is controversial, but I don't mind it,21    # and it has lazy-trees support which is useful for fleet.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          # To be used with https://github.com/NixOS/nix/pull/889253          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                    # It is possible to implement this inventory right now, but I want to71                    # get rid of `fleet.nix` file in the future.72                    # children.secrets = { };73                  }) output;74                };75              };76            };77        };78        # Supported and tested list of deployment targets.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            # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.98            # I have no hardware for such testing, thus only adding machines I actually have and use.99            #100            # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.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            # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.117            packages = lib.mkIf deployerSystem (118              let119                packages = pkgs.callPackages ./pkgs {120                  inherit craneLib inputs';121                };122              in123              packages // { default = packages.fleet; }124            );125            # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.126            # checks there build packages for default nixpkgs rustPlatform packages.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              # fleet-install-secrets is installed to remote systems, thus needs to work144              # with rust in nixpkgs.145              (prefixAttrs "nixpkgs-" {146                inherit (packages) fleet-install-secrets;147              })148              // {149                formatting = treefmt.check self;150              };151            # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole152            # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?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}