aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 242ba02254ae46fd27ffe938f06c16a8e79274cf (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
{
  inputs = {
    utils.url = "github:numtide/flake-utils";
    naersk.url = "github:nmattia/naersk";
    mozillapkgs = {
      url = "github:mozilla/nixpkgs-mozilla";
      flake = false;
    };
    gitignore = {
      url = "github:hercules-ci/gitignore";
      flake = false;
    };
    flake-compat = {
      url = "github:edolstra/flake-compat";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, utils, naersk, mozillapkgs, gitignore, ... }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages."${system}";
        inherit (import gitignore { inherit (pkgs) lib; }) gitignoreSource;

        # Get a specific rust version
        mozilla = pkgs.callPackage (mozillapkgs + "/package-set.nix") { };
        chanspec = {
          date = "2021-03-31";
          channel = "nightly";
          sha256 = "oK5ebje09MRn988saJMT3Zze/tRE7u9zTeFPV1CEeLc="; # set zeros after modifying channel or date
        };

        rustChannel = mozilla.rustChannelOf chanspec;
        rust = rustChannel.rust;
        rust-src = rustChannel.rust-src;

        naersk-lib = naersk.lib."${system}".override {
          cargo = rust;
          rustc = rust;
        };

        nativeBuildInputs = with pkgs; [
          SDL2
          SDL2_ttf
        ];

      in
      rec {
        packages.sdl-tests = naersk-lib.buildPackage {
          pname = "sdl-tests";
          version = "0.1.0";
          root = gitignoreSource ./.;
          inherit nativeBuildInputs;
        };
        defaultPackage = packages.sdl-tests;
        apps.sdl-tests = utils.lib.mkApp {
          drv = packages.sdl-tests;
        };
        apps.check = {
          type = "app";
          program = "${pkgs.cargo-watch}/bin/cargo-watch";
        };
        defaultApp = apps.sdl-tests;
        devShell = pkgs.mkShell {
          nativeBuildInputs = nativeBuildInputs ++ [
            rust
            rust-src
            pkgs.rust-analyzer
            pkgs.rustfmt
            pkgs.cargo
            pkgs.cargo-watch
          ];
          RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library";
          RUST_LOG = "info";
          RUST_BACKTRACE = 1;
        };
      });
}