git.delta.rocks / jrsonnet / refs/commits / b56a5a338d1e

difftreelog

source

flake.nix4.9 KiBsourcehistory
1{2  description = "NixOS configuration management";34  inputs = {5    nixpkgs.url = "github:nixos/nixpkgs/master";6    nixpkgs-stable-for-tests.url = "github:nixos/nixpkgs/nixos-24.05";7    rust-overlay = {8      url = "github:oxalica/rust-overlay";9      inputs = {10        nixpkgs.follows = "nixpkgs";11      };12    };13    flake-parts.url = "github:hercules-ci/flake-parts";14    crane = {15      url = "github:ipetkov/crane";16      inputs.nixpkgs.follows = "nixpkgs";17    };18  };19  outputs = {20    self,21    rust-overlay,22    flake-parts,23    nixpkgs,24    nixpkgs-stable-for-tests,25    crane,26  }:27    flake-parts.lib.mkFlake {28      # Not passing inputs through inputs for better visibility.29      inputs = {};30    } {31      flake = {32        lib = import ./lib {33          fleetPkgsForPkgs = pkgs:34            import ./pkgs {35              inherit (pkgs) callPackage;36              craneLib = crane.mkLib pkgs;37            };38        };39        # To be used with https://github.com/NixOS/nix/pull/889240        schemas = {41          fleetConfigurations = {42            version = 1;43            doc = ''44              The `fleetConfigurations` flake output defines fleet cluster configurations.45            '';46            inventory = output: {47              children =48                builtins.mapAttrs (configName: cluster: {49                  what = "fleet cluster configuration";5051                  children =52                    builtins.mapAttrs (hostName: host: {53                      what = "host [${host.system}]";54                    })55                    cluster.config.hosts;56                  # It is possible to implement this inventory right now, but I want to57                  # get rid of `fleet.nix` file in the future.58                  # children.secrets = { };59                })60                output;61            };62          };63        };64      };65      # Supported and tested list of deployment targets.66      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];67      perSystem = {68        config,69        system,70        ...71      }: let72        # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.73        # I have no hardware for such testing, thus only adding machines I actually have and use.74        #75        # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.76        deployerSystems = ["aarch64-linux" "x86_64-linux"];77        deployerSystem = builtins.elem system deployerSystems;78        pkgs = import nixpkgs {79          inherit system;80          overlays = [(rust-overlay.overlays.default)];81        };82        lib = pkgs.lib;83        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;84        craneLib = (crane.mkLib pkgs).overrideToolchain rust;85      in {86        # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.87        packages = lib.mkIf deployerSystem (let88          packages = import ./pkgs {89            inherit (pkgs) callPackage;90            inherit craneLib;91          };92        in93          packages // {default = packages.fleet;});94        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole95        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?96        devShells = lib.mkIf deployerSystem {97          default = craneLib.devShell {98            packages = with pkgs; [99              rust100              alejandra101              cargo-edit102              cargo-udeps103              cargo-fuzz104              cargo-watch105              cargo-outdated106107              pkg-config108              openssl109              bacon110            ];111          };112        };113        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.114        # checks there build packages for default nixpkgs rustPlatform packages.115        checks = let116          packages = import ./pkgs {117            inherit (pkgs) callPackage;118            craneLib = crane.mkLib (import nixpkgs {inherit system;});119          };120          packages-with-nixpkgs-stable = import ./pkgs {121            inherit (pkgs) callPackage;122            craneLib = crane.mkLib (import nixpkgs-stable-for-tests {inherit system;});123          };124          prefixAttrs = prefix: attrs:125            nixpkgs.lib.attrsets.mapAttrs' (name: value: {126              name = "${prefix}${name}";127              value = value.overrideAttrs (prev: {128                pname = "${prefix}${prev.pname}";129              });130            })131            attrs;132        in133          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.134          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]))135          // (prefixAttrs "nixpkgs-stable-" (removeAttrs packages-with-nixpkgs-stable ["fleet"]));136        formatter = pkgs.alejandra;137      };138    };139}