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

difftreelog

source

flake.nix6.4 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 = "github:deltarocks/nix/fleet";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          # Used to test nix-eval bindings48          testData = {49            testObj = {50              v = "Hello";51            };52            testString = "hello";53          };5455          # To be used with https://github.com/NixOS/nix/pull/889256          schemas =57            let58              inherit (inputs.nixpkgs.lib) mapAttrs;59            in60            {61              fleetConfigurations = {62                version = 1;63                doc = ''64                  The `fleetConfigurations` flake output defines fleet cluster configurations.65                '';66                inventory = output: {67                  children = mapAttrs (configName: cluster: {68                    what = "fleet cluster configuration";6970                    children = mapAttrs (hostName: host: {71                      what = "host [${host.system}]";72                    }) cluster.config.hosts;73                    # It is possible to implement this inventory right now, but I want to74                    # get rid of `fleet.nix` file in the future.75                    # children.secrets = { };76                  }) output;77                };78              };79            };80        };81        # Supported and tested list of deployment targets.82        systems = [83          "x86_64-linux"84          "aarch64-linux"85          "armv7l-linux"86          "armv6l-linux"87        ];88        perSystem =89          {90            config,91            system,92            pkgs,93            self,94            inputs',95            ...96          }:97          let98            inherit (lib.attrsets) mapAttrs';99            inherit (lib.lists) elem;100            # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.101            # I have no hardware for such testing, thus only adding machines I actually have and use.102            #103            # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.104            deployerSystems = [105              "aarch64-linux"106              "x86_64-linux"107            ];108            deployerSystem = elem system deployerSystems;109            lib = pkgs.lib;110            rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;111            craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;112            treefmt = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;113          in114          {115            _module.args.pkgs = import inputs.nixpkgs {116              inherit system;117              overlays = [ (inputs.rust-overlay.overlays.default) ];118            };119            # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.120            packages = lib.mkIf deployerSystem (121              let122                packages = pkgs.callPackages ./pkgs {123                  inherit craneLib inputs';124                };125              in126              packages // { default = packages.fleet; }127            );128            # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.129            # checks there build packages for default nixpkgs rustPlatform packages.130            checks =131              let132                nixpkgsCraneLib = inputs.crane.mkLib pkgs;133                packages = pkgs.callPackages ./pkgs {134                  craneLib = nixpkgsCraneLib;135                  inherit inputs;136                };137                prefixAttrs =138                  prefix: attrs:139                  mapAttrs' (name: value: {140                    name = "${prefix}${name}";141                    value = value.overrideAttrs (prev: {142                      pname = "${prefix}${prev.pname}";143                    });144                  }) attrs;145              in146              # fleet-install-secrets is installed to remote systems, thus needs to work147              # with rust in nixpkgs.148              (prefixAttrs "nixpkgs-" {149                inherit (packages) fleet-install-secrets;150              })151              // {152                formatting = treefmt.check self;153              };154            # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole155            # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?156            shelly.shells.default = lib.mkIf deployerSystem {157              factory = craneLib.devShell;158              packages = with pkgs; [159                rust160                alejandra161                cargo-edit162                cargo-udeps163                cargo-fuzz164                cargo-watch165                cargo-outdated166                gdb167168                pkg-config169                openssl170                bacon171                nil172                rustPlatform.bindgenHook173                inputs'.nix.packages.nix-expr-c174                inputs'.nix.packages.nix-flake-c175                inputs'.nix.packages.nix-fetchers-c176              ];177              environment.PROTOC = "${pkgs.protobuf}/bin/protoc";178            };179            formatter = treefmt.wrapper;180          };181      };182}