git.delta.rocks / fleet / refs/heads / push-kyumtlkprzyo

difftreelog

source

flake.nix7.1 KiBsourcehistory
1{2  description = "NixOS cluster configuration management";34  inputs = {5    nixpkgs.url = "github:nixos/nixpkgs/release-26.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    nocargo = {16      url = "gitlab:deltaex/nocargo";17      inputs.nixpkgs.follows = "nixpkgs";18      inputs.registry-crates-io.follows = "registry-crates-io";19    };20    registry-crates-io = {21      url = "github:rust-lang/crates.io-index";22      flake = false;23    };24    shelly.url = "github:CertainLach/shelly";25    fleet-tf = {26      url = "github:CertainLach/fleet-tf";27      inputs.nixpkgs.follows = "nixpkgs";28      inputs.shelly.follows = "shelly";29      inputs.flake-parts.follows = "flake-parts";30    };31    treefmt-nix = {32      url = "github:numtide/treefmt-nix";33      inputs.nixpkgs.follows = "nixpkgs";34    };35    # DeterminateSystem's nix fork is controversial, but I don't mind it,36    # and it has lazy-trees support which is useful for fleet.37    nix = {38      url = "github:deltarocks/nix/fleet";39      inputs.nixpkgs.follows = "nixpkgs";40      inputs.flake-parts.follows = "flake-parts";41    };42  };43  outputs =44    inputs:45    inputs.flake-parts.lib.mkFlake46      {47        inherit inputs;48      }49      {50        imports = [ inputs.shelly.flakeModule ];51        flake = rec {52          lib =53            (import ./lib {54              inherit (inputs.nixpkgs) lib;55            })56            // {57              fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";58            };59          flakeModules.default = import ./lib/flakePart.nix {60            inherit (inputs) crane;61          };62          flakeModule = flakeModules.default;6364          flakeModules.fleet-tf = ./modules/extras/tf.nix;6566          # Used to test nix-eval bindings67          testData = {68            testObj = {69              v = "Hello";70            };71            testString = "hello";72            testPrimop = op: "PREFIX_" + (op "body" "_SUFFIX");73          };7475          # To be used with https://github.com/NixOS/nix/pull/889276          # schemas =77          #   let78          #     inherit (inputs.nixpkgs.lib) mapAttrs;79          #   in80          #   {81          #     fleetConfigurations = {82          #       version = 1;83          #       doc = ''84          #         The `fleetConfigurations` flake output defines fleet cluster configurations.85          #       '';86          #       inventory = output: {87          #         children = mapAttrs (configName: cluster: {88          #           what = "fleet cluster configuration";89          #90          #           children = mapAttrs (hostName: host: {91          #             what = "host [${host.system}]";92          #           }) cluster.config.hosts;93          #           # It is possible to implement this inventory right now, but I want to94          #           # get rid of `fleet.nix` file in the future.95          #           # children.secrets = { };96          #         }) output;97          #       };98          #     };99          #   };100        };101        # Supported and tested list of deployment targets.102        systems = [103          "x86_64-linux"104          "aarch64-linux"105          "armv7l-linux"106          "armv6l-linux"107        ];108        perSystem =109          {110            config,111            system,112            pkgs,113            self,114            inputs',115            ...116          }:117          let118            inherit (lib.attrsets) mapAttrs';119            inherit (lib.lists) elem;120            # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.121            # I have no hardware for such testing, thus only adding machines I actually have and use.122            #123            # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.124            deployerSystems = [125              "aarch64-linux"126              "x86_64-linux"127            ];128            deployerSystem = elem system deployerSystems;129            lib = pkgs.lib;130            rust = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {131              enableLibsecret = false;132            };133            craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;134            treefmt = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;135          in136          {137            _module.args.pkgs = import inputs.nixpkgs {138              inherit system;139              overlays = [140                inputs.rust-overlay.overlays.default141              ];142            };143            # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.144            packages = lib.mkIf deployerSystem (145              let146                packages = pkgs.callPackages ./pkgs {147                  inherit craneLib inputs;148                  rustToolchain = rust;149                };150              in151              packages // { default = packages.fleet; }152            );153            # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.154            # checks there build packages for default nixpkgs rustPlatform packages.155            checks =156              let157                nixpkgsCraneLib = inputs.crane.mkLib pkgs;158                packages = pkgs.callPackages ./pkgs {159                  craneLib = nixpkgsCraneLib;160                  inherit inputs;161                };162                prefixAttrs =163                  prefix: attrs:164                  mapAttrs' (name: value: {165                    name = "${prefix}${name}";166                    value = value.overrideAttrs (prev: {167                      pname = "${prefix}${prev.pname}";168                    });169                  }) attrs;170              in171              # fleet-install-secrets is installed to remote systems, thus needs to work172              # with rust in nixpkgs.173              (prefixAttrs "nixpkgs-" {174                inherit (packages) fleet-install-secrets;175              })176              // {177                formatting = treefmt.check self;178              };179            # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole180            # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?181            shelly.shells.default = lib.mkIf deployerSystem {182              factory = craneLib.devShell;183              packages = with pkgs; [184                rust185186                pkg-config187                openssl188                udev189                rustPlatform.bindgenHook190                inputs'.nix.packages.nix-expr-c191                inputs'.nix.packages.nix-flake-c192                inputs'.nix.packages.nix-fetchers-c193                inputs'.nix.packages.nix-store-c194                inputs'.nix.packages.nix195196                (rage.overrideAttrs { cargoFeatures = [ "plugin" ]; })197              ];198              environment.PROTOC = "${pkgs.protobuf}/bin/protoc";199            };200            formatter = treefmt.wrapper;201          };202      };203}