git.delta.rocks / fleet / refs/commits / 78bc9187eaae

difftreelog

source

flake.nix7.6 KiBsourcehistory
1{2  description = "NixOS cluster configuration management";34  inputs = {5    nixpkgs.url = "github:nixos/nixpkgs/release-25.11";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    fleet-tf = {17      url = "github:CertainLach/fleet-tf";18      inputs.nixpkgs.follows = "nixpkgs";19      inputs.shelly.follows = "shelly";20      inputs.flake-parts.follows = "flake-parts";21    };22    treefmt-nix = {23      url = "github:numtide/treefmt-nix";24      inputs.nixpkgs.follows = "nixpkgs";25    };26    remowt-agents = {27      url = "git+file:/home/lach/build/remowt-agents";28      inputs.nixpkgs.follows = "nixpkgs";29      inputs.flake-parts.follows = "flake-parts";30      inputs.crane.follows = "crane";31      inputs.shelly.follows = "shelly";32    };33    # DeterminateSystem's nix fork is controversial, but I don't mind it,34    # and it has lazy-trees support which is useful for fleet.35    nix = {36      url = "github:deltarocks/nix/fleet";37      inputs.nixpkgs.follows = "nixpkgs";38      inputs.flake-parts.follows = "flake-parts";39    };40  };41  outputs =42    inputs:43    inputs.flake-parts.lib.mkFlake44      {45        inherit inputs;46      }47      {48        imports = [ inputs.shelly.flakeModule ];49        flake = rec {50          lib =51            (import ./lib {52              inherit (inputs.nixpkgs) lib;53            })54            // {55              fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";56            };57          flakeModules.default = import ./lib/flakePart.nix {58            inherit (inputs) crane;59          };60          flakeModule = flakeModules.default;6162          flakeModules.fleet-tf = ./modules/extras/tf.nix;6364          # Used to test nix-eval bindings65          testData = {66            testObj = {67              v = "Hello";68            };69            testString = "hello";70            testPrimop = op: "PREFIX_" + (op "body" "_SUFFIX");71          };7273          # To be used with https://github.com/NixOS/nix/pull/889274          # schemas =75          #   let76          #     inherit (inputs.nixpkgs.lib) mapAttrs;77          #   in78          #   {79          #     fleetConfigurations = {80          #       version = 1;81          #       doc = ''82          #         The `fleetConfigurations` flake output defines fleet cluster configurations.83          #       '';84          #       inventory = output: {85          #         children = mapAttrs (configName: cluster: {86          #           what = "fleet cluster configuration";87          #88          #           children = mapAttrs (hostName: host: {89          #             what = "host [${host.system}]";90          #           }) cluster.config.hosts;91          #           # It is possible to implement this inventory right now, but I want to92          #           # get rid of `fleet.nix` file in the future.93          #           # children.secrets = { };94          #         }) output;95          #       };96          #     };97          #   };98        };99        # Supported and tested list of deployment targets.100        systems = [101          "x86_64-linux"102          "aarch64-linux"103          "armv7l-linux"104          "armv6l-linux"105        ];106        perSystem =107          {108            config,109            system,110            pkgs,111            self,112            inputs',113            ...114          }:115          let116            inherit (lib.attrsets) mapAttrs';117            inherit (lib.lists) elem;118            # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.119            # I have no hardware for such testing, thus only adding machines I actually have and use.120            #121            # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.122            deployerSystems = [123              "aarch64-linux"124              "x86_64-linux"125            ];126            deployerSystem = elem system deployerSystems;127            lib = pkgs.lib;128            rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;129            craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;130            treefmt = (inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;131          in132          {133            _module.args.pkgs = import inputs.nixpkgs {134              inherit system;135              overlays = [136                (inputs.rust-overlay.overlays.default)137                (final: prev: {138                  # Libsecret is stupidly huge139                  # https://github.com/oxalica/rust-overlay/issues/211140                  libsecret = final.stdenv.mkDerivation {141                    name = "fake-libsecret";142                    version = "1.0.0";143                    unpackPhase = "true";144                    buildPhase = "true";145                    installPhase = ''146                      mkdir -p $out/lib/147                      echo "" | gcc -shared -o $out/lib/libsecret-1.so.0 -x c -148                    '';149                  };150                })151              ];152            };153            # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.154            packages = lib.mkIf deployerSystem (155              let156                packages = pkgs.callPackages ./pkgs {157                  inherit craneLib inputs;158                };159              in160              packages // { default = packages.fleet; }161            );162            # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.163            # checks there build packages for default nixpkgs rustPlatform packages.164            checks =165              let166                nixpkgsCraneLib = inputs.crane.mkLib pkgs;167                packages = pkgs.callPackages ./pkgs {168                  craneLib = nixpkgsCraneLib;169                  inherit inputs;170                };171                prefixAttrs =172                  prefix: attrs:173                  mapAttrs' (name: value: {174                    name = "${prefix}${name}";175                    value = value.overrideAttrs (prev: {176                      pname = "${prefix}${prev.pname}";177                    });178                  }) attrs;179              in180              # fleet-install-secrets is installed to remote systems, thus needs to work181              # with rust in nixpkgs.182              (prefixAttrs "nixpkgs-" {183                inherit (packages) fleet-install-secrets;184              })185              // {186                formatting = treefmt.check self;187              };188            # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole189            # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?190            shelly.shells.default = lib.mkIf deployerSystem {191              factory = craneLib.devShell;192              packages = with pkgs; [193                rust194195                pkg-config196                openssl197                rustPlatform.bindgenHook198                inputs'.nix.packages.nix-expr-c199                inputs'.nix.packages.nix-flake-c200                inputs'.nix.packages.nix-fetchers-c201                inputs'.nix.packages.nix-store-c202                inputs'.nix.packages.nix203204                (rage.overrideAttrs { cargoFeatures = [ "plugin" ]; })205              ];206              environment.PROTOC = "${pkgs.protobuf}/bin/protoc";207            };208            formatter = treefmt.wrapper;209          };210      };211}