git.delta.rocks / jrsonnet / refs/commits / 505f82ed3097

difftreelog

source

flake.nix4.6 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 = {9        nixpkgs.follows = "nixpkgs";10      };11    };12    flake-parts.url = "github:hercules-ci/flake-parts";13    crane = {14      url = "github:ipetkov/crane";15      inputs.nixpkgs.follows = "nixpkgs";16    };17  };18  outputs = inputs @ {19    self,20    flake-parts,21    crane,22    ...23  }:24    flake-parts.lib.mkFlake {25      inherit inputs;26    } {27      flake = rec {28        lib =29          (import ./lib {30            inherit (inputs.nixpkgs) lib;31          })32          // {33            fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";34          };35        flakeModules.default = import ./lib/flakePart.nix {36          inherit crane;37        };38        flakeModule = flakeModules.default;3940        # To be used with https://github.com/NixOS/nix/pull/889241        schemas = let42          inherit (inputs.nixpkgs.lib) mapAttrs;43        in {44          fleetConfigurations = {45            version = 1;46            doc = ''47              The `fleetConfigurations` flake output defines fleet cluster configurations.48            '';49            inventory = output: {50              children =51                mapAttrs (configName: cluster: {52                  what = "fleet cluster configuration";5354                  children =55                    mapAttrs (hostName: host: {56                      what = "host [${host.system}]";57                    })58                    cluster.config.hosts;59                  # It is possible to implement this inventory right now, but I want to60                  # get rid of `fleet.nix` file in the future.61                  # children.secrets = { };62                })63                output;64            };65          };66        };67      };68      # Supported and tested list of deployment targets.69      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];70      perSystem = {71        config,72        system,73        pkgs,74        ...75      }: let76        inherit (lib.attrSets) mapAttrs';77        inherit (lib.lists) elem;78        # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.79        # I have no hardware for such testing, thus only adding machines I actually have and use.80        #81        # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.82        deployerSystems = ["aarch64-linux" "x86_64-linux"];83        deployerSystem = elem system deployerSystems;84        lib = pkgs.lib;85        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;86        craneLib = (crane.mkLib pkgs).overrideToolchain rust;87      in {88        _module.args.pkgs = import inputs.nixpkgs {89          inherit system;90          overlays = [(inputs.rust-overlay.overlays.default)];91        };92        # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.93        packages = lib.mkIf deployerSystem (let94          packages = pkgs.callPackages ./pkgs {95            inherit craneLib;96          };97        in98          packages // {default = packages.fleet;});99        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole100        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?101        devShells = lib.mkIf deployerSystem {102          default = craneLib.devShell {103            packages = with pkgs; [104              rust105              alejandra106              cargo-edit107              cargo-udeps108              cargo-fuzz109              cargo-watch110              cargo-outdated111112              pkg-config113              openssl114              bacon115              nil116            ];117          };118        };119        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.120        # checks there build packages for default nixpkgs rustPlatform packages.121        checks = let122          packages = pkgs.callPackages ./pkgs {};123          prefixAttrs = prefix: attrs:124            mapAttrs' (name: value: {125              name = "${prefix}${name}";126              value = value.overrideAttrs (prev: {127                pname = "${prefix}${prev.pname}";128              });129            })130            attrs;131        in132          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.133          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]));134        formatter = pkgs.alejandra;135      };136    };137}