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

difftreelog

source

flake.nix5.1 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 = inputs @ {20    self,21    flake-parts,22    crane,23    ...24  }:25    flake-parts.lib.mkFlake {26      inherit inputs;27    } {28      flake = rec {29        lib =30          (import ./lib {31            inherit (inputs.nixpkgs) lib;32          })33          // {34            fleetConfiguration = throw "function-based interface is deprecated, use flake-parts syntax instead";35          };36        flakeModules.default = (import ./lib/flakePart.nix {37          inherit crane;38        });39        flakeModule = flakeModules.default;4041        # To be used with https://github.com/NixOS/nix/pull/889242        schemas = let43          inherit (inputs.nixpkgs.lib) mapAttrs;44        in {45          fleetConfigurations = {46            version = 1;47            doc = ''48              The `fleetConfigurations` flake output defines fleet cluster configurations.49            '';50            inventory = output: {51              children =52                mapAttrs (configName: cluster: {53                  what = "fleet cluster configuration";5455                  children =56                    mapAttrs (hostName: host: {57                      what = "host [${host.system}]";58                    })59                    cluster.config.hosts;60                  # It is possible to implement this inventory right now, but I want to61                  # get rid of `fleet.nix` file in the future.62                  # children.secrets = { };63                })64                output;65            };66          };67        };68      };69      # Supported and tested list of deployment targets.70      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];71      perSystem = {72        config,73        system,74        pkgs,75        ...76      }: let77        inherit (lib.attrSets) mapAttrs';78        inherit (lib.lists) elem;79        # Can also be built for darwin, through it is not usual to deploy nixos systems from macos machines.80        # I have no hardware for such testing, thus only adding machines I actually have and use.81        #82        # It is not possible to deploy any host from armv6/armv7 hardware, and I don't think it even makes sense.83        deployerSystems = ["aarch64-linux" "x86_64-linux"];84        deployerSystem = elem system deployerSystems;85        lib = pkgs.lib;86        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;87        craneLib = (crane.mkLib pkgs).overrideToolchain rust;88      in {89        _module.args.pkgs = import inputs.nixpkgs {90          inherit system;91          overlays = [(inputs.rust-overlay.overlays.default)];92        };93        # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml.94        packages = lib.mkIf deployerSystem (let95          packages = import ./pkgs {96            inherit (pkgs) callPackage;97            inherit craneLib;98          };99        in100          packages // {default = packages.fleet;});101        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole102        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?103        devShells = lib.mkIf deployerSystem {104          default = craneLib.devShell {105            packages = with pkgs; [106              rust107              alejandra108              cargo-edit109              cargo-udeps110              cargo-fuzz111              cargo-watch112              cargo-outdated113114              pkg-config115              openssl116              bacon117              nil118            ];119          };120        };121        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.122        # checks there build packages for default nixpkgs rustPlatform packages.123        checks = let124          packages = import ./pkgs {125            inherit (pkgs) callPackage;126            craneLib = crane.mkLib pkgs;127          };128          packages-with-nixpkgs-stable = import ./pkgs {129            inherit (pkgs) callPackage;130            craneLib = crane.mkLib (import inputs.nixpkgs-stable-for-tests {inherit system;});131          };132          prefixAttrs = prefix: attrs:133            mapAttrs' (name: value: {134              name = "${prefix}${name}";135              value = value.overrideAttrs (prev: {136                pname = "${prefix}${prev.pname}";137              });138            })139            attrs;140        in141          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.142          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]))143          // (prefixAttrs "nixpkgs-stable-" (removeAttrs packages-with-nixpkgs-stable ["fleet"]));144        formatter = pkgs.alejandra;145      };146    };147}