about summary refs log tree commit diff
path: root/flake.nix
blob: f820e513b91c45015adefc393a86e88b28e040fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils/main";
    crane.url = "github:ipetkov/crane";
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs = {
        nixpkgs.follows = "nixpkgs";
      };
    };
  };
  outputs = { self, nixpkgs, flake-utils, crane, rust-overlay }: let
    supportedSystems = ["aarch64-linux" "x86_64-linux"];
    forAllSystems = f: flake-utils.lib.eachSystem supportedSystems f;
  in {
    nixosModules.default = import ./configuration.nix self;
  } // forAllSystems (system: let
    pkgs = import nixpkgs {
      overlays = [ rust-overlay.overlays.default ];
      localSystem = { inherit system; };
    };
    crane' = crane.mkLib pkgs;
    cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
    crane-msrv' = crane'.overrideToolchain (p: p.rust-bin.stable."${cargoToml.package.rust-version}".default);

    kittybox = pkgs.callPackage ./kittybox.nix {
      # TODO: this may break cross-compilation. It may be better to
      # inject it as an overlay. However, I am unsure whether Crane
      # can recognize it's being passed a cross-compilation set.
      crane = crane';

      nixosTests = {
        smokeTest = self.checks.${system}.nixos-test;
        postgresSmokeTest = self.checks.${system}.nixos-test-postgres;
      };
    };
  in {
    packages = {
      kittybox = kittybox;
      default = self.packages.${system}.kittybox;
    };

    checks = {
      kittybox = self.packages.${system}.kittybox;

      deps = self.packages.${system}.kittybox.cargoArtifacts;
      clippy = self.packages.${system}.kittybox.clippy;

      distributed-test = pkgs.nixosTest (import ./nixos-tests/distributed-test.nix self);
      nixos-test = pkgs.nixosTest (import ./nixos-tests/smoke-test.nix self);
      nixos-test-postgres = pkgs.nixosTest (import ./nixos-tests/postgres-smoke-test.nix self);
      webmention-test = pkgs.nixosTest (import ./nixos-tests/webmention-test.nix self);

      msrv-check = (self.packages.${system}.kittybox.override { crane = crane-msrv'; });
    };

    devShells.default = pkgs.callPackage ./shell.nix {};
    devShells.msrv = let
      rust = pkgs.rust-bin.stable."${cargoToml.package.rust-version}".default;
    in pkgs.callPackage ./shell.nix {
      cargo = rust; rustc = rust; rust-analyzer = rust;
    };
  });
}