git.delta.rocks / jrsonnet / refs/commits / 3e7b063c34a7

difftreelog

source

flake.nix4.8 KiBsourcehistory
1{2  description = "NixOS configuration management";34  inputs = {5    nixpkgs.url = "github:nixos/nixpkgs/master";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  };16  outputs = inputs:17    inputs.flake-parts.lib.mkFlake {18      inherit inputs;19    } {20      flake = rec {21        lib =22          (import ./lib {23            inherit (inputs.nixpkgs) lib;24          })25          // {26            fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";27          };28        flakeModules.default = import ./lib/flakePart.nix {29          inherit (inputs) crane;30        };31        flakeModule = flakeModules.default;3233        fleetModules.tf = ./modules/extras/tf.nix;3435        # To be used with https://github.com/NixOS/nix/pull/889236        schemas = let37          inherit (inputs.nixpkgs.lib) mapAttrs;38        in {39          fleetConfigurations = {40            version = 1;41            doc = ''42              The `fleetConfigurations` flake output defines fleet cluster configurations.43            '';44            inventory = output: {45              children =46                mapAttrs (configName: cluster: {47                  what = "fleet cluster configuration";4849                  children =50                    mapAttrs (hostName: host: {51                      what = "host [${host.system}]";52                    })53                    cluster.config.hosts;54                  # It is possible to implement this inventory right now, but I want to55                  # get rid of `fleet.nix` file in the future.56                  # children.secrets = { };57                })58                output;59            };60          };61        };62      };63      # Supported and tested list of deployment targets.64      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];65      perSystem = {66        config,67        system,68        pkgs,69        ...70      }: let71        inherit (lib.attrsets) mapAttrs';72        inherit (lib.lists) elem;73        # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.74        # I have no hardware for such testing, thus only adding machines I actually have and use.75        #76        # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.77        deployerSystems = ["aarch64-linux" "x86_64-linux"];78        deployerSystem = elem system deployerSystems;79        lib = pkgs.lib;80        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;81        craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;82      in {83        _module.args.pkgs = import inputs.nixpkgs {84          inherit system;85          overlays = [(inputs.rust-overlay.overlays.default)];86        };87        # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.88        packages = lib.mkIf deployerSystem (let89          packages = pkgs.callPackages ./pkgs {90            inherit craneLib;91          };92        in93          packages // {default = packages.fleet;});94        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.95        # checks there build packages for default nixpkgs rustPlatform packages.96        checks = let97          packages = pkgs.callPackages ./pkgs {98            inherit craneLib;99          };100          prefixAttrs = prefix: attrs:101            mapAttrs' (name: value: {102              name = "${prefix}${name}";103              value = value.overrideAttrs (prev: {104                pname = "${prefix}${prev.pname}";105              });106            })107            attrs;108        in109          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.110          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]));111        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole112        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?113        devShells = lib.mkIf deployerSystem {114          default = craneLib.devShell {115            packages = with pkgs; [116              rust117              alejandra118              cargo-edit119              cargo-udeps120              cargo-fuzz121              cargo-watch122              cargo-outdated123124              pkg-config125              openssl126              bacon127              nil128              rustPlatform.bindgenHook129              nixVersions.nix_2_22130            ];131            env.PROTOC = "${pkgs.protobuf}/bin/protoc";132          };133        };134        formatter = pkgs.alejandra;135      };136    };137}