git.delta.rocks / jrsonnet / refs/commits / 05eaddea6c83

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 = {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        fleetModules.tf = ./modules/extras/tf.nix;4142        # To be used with https://github.com/NixOS/nix/pull/889243        schemas = let44          inherit (inputs.nixpkgs.lib) mapAttrs;45        in {46          fleetConfigurations = {47            version = 1;48            doc = ''49              The `fleetConfigurations` flake output defines fleet cluster configurations.50            '';51            inventory = output: {52              children =53                mapAttrs (configName: cluster: {54                  what = "fleet cluster configuration";5556                  children =57                    mapAttrs (hostName: host: {58                      what = "host [${host.system}]";59                    })60                    cluster.config.hosts;61                  # It is possible to implement this inventory right now, but I want to62                  # get rid of `fleet.nix` file in the future.63                  # children.secrets = { };64                })65                output;66            };67          };68        };69      };70      # Supported and tested list of deployment targets.71      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];72      perSystem = {73        config,74        system,75        pkgs,76        ...77      }: let78        inherit (lib.attrsets) mapAttrs';79        inherit (lib.lists) elem;80        # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.81        # I have no hardware for such testing, thus only adding machines I actually have and use.82        #83        # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.84        deployerSystems = ["aarch64-linux" "x86_64-linux"];85        deployerSystem = elem system deployerSystems;86        lib = pkgs.lib;87        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;88        craneLib = (crane.mkLib pkgs).overrideToolchain rust;89      in {90        _module.args.pkgs = import inputs.nixpkgs {91          inherit system;92          overlays = [(inputs.rust-overlay.overlays.default)];93        };94        # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.95        packages = lib.mkIf deployerSystem (let96          packages = pkgs.callPackages ./pkgs {97            inherit craneLib;98          };99        in100          packages // {default = packages.fleet;});101        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.102        # checks there build packages for default nixpkgs rustPlatform packages.103        checks = let104          packages = pkgs.callPackages ./pkgs {105            inherit craneLib;106          };107          prefixAttrs = prefix: attrs:108            mapAttrs' (name: value: {109              name = "${prefix}${name}";110              value = value.overrideAttrs (prev: {111                pname = "${prefix}${prev.pname}";112              });113            })114            attrs;115        in116          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.117          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]));118        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole119        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?120        devShells = lib.mkIf deployerSystem {121          default = craneLib.devShell {122            packages = with pkgs; [123              rust124              alejandra125              cargo-edit126              cargo-udeps127              cargo-fuzz128              cargo-watch129              cargo-outdated130131              pkg-config132              openssl133              bacon134              nil135            ];136            env.PROTOC = "${pkgs.protobuf}/bin/protoc";137          };138        };139        formatter = pkgs.alejandra;140      };141    };142}