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

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 = inputs @ {20    self,21    flake-parts,22    crane,23    ...24  }:25    flake-parts.lib.mkFlake {26      inherit inputs;27    } {28      flake = let29        inherit (inputs.nixpkgs.lib) mapAttrs;30      in {31        lib = import ./lib {32          fleetPkgsForPkgs = pkgs:33            import ./pkgs {34              inherit (pkgs) callPackage;35              craneLib = crane.mkLib pkgs;36            };37        };38        # To be used with https://github.com/NixOS/nix/pull/889239        schemas = {40          fleetConfigurations = {41            version = 1;42            doc = ''43              The `fleetConfigurations` flake output defines fleet cluster configurations.44            '';45            inventory = output: {46              children =47                mapAttrs (configName: cluster: {48                  what = "fleet cluster configuration";4950                  children =51                    mapAttrs (hostName: host: {52                      what = "host [${host.system}]";53                    })54                    cluster.config.hosts;55                  # It is possible to implement this inventory right now, but I want to56                  # get rid of `fleet.nix` file in the future.57                  # children.secrets = { };58                })59                output;60            };61          };62        };63      };64      # Supported and tested list of deployment targets.65      systems = ["x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux"];66      perSystem = {67        config,68        system,69        pkgs,70        ...71      }: let72        inherit (lib) mapAttrs' 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 = (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 = import ./pkgs {90            inherit (pkgs) callPackage;91            inherit craneLib;92          };93        in94          packages // {default = packages.fleet;});95        # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole96        # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?97        devShells = lib.mkIf deployerSystem {98          default = craneLib.devShell {99            packages = with pkgs; [100              rust101              alejandra102              cargo-edit103              cargo-udeps104              cargo-fuzz105              cargo-watch106              cargo-outdated107108              pkg-config109              openssl110              bacon111            ];112          };113        };114        # fleet-install-secrets will not be built normally, because they are not ran directly by user most of the time.115        # checks there build packages for default nixpkgs rustPlatform packages.116        checks = let117          packages = import ./pkgs {118            inherit (pkgs) callPackage;119            craneLib = crane.mkLib pkgs;120          };121          packages-with-nixpkgs-stable = import ./pkgs {122            inherit (pkgs) callPackage;123            craneLib = crane.mkLib (import inputs.nixpkgs-stable-for-tests {inherit system;});124          };125          prefixAttrs = prefix: attrs:126            mapAttrs' (name: value: {127              name = "${prefix}${name}";128              value = value.overrideAttrs (prev: {129                pname = "${prefix}${prev.pname}";130              });131            })132            attrs;133        in134          # `fleet` crate wants nightly rust, also little sense of supporting it on stable nixpkgs.135          (prefixAttrs "nixpkgs-" (removeAttrs packages ["fleet"]))136          // (prefixAttrs "nixpkgs-stable-" (removeAttrs packages-with-nixpkgs-stable ["fleet"]));137        formatter = pkgs.alejandra;138      };139    };140}