atagen

monolith

public
Star0
Watch0
14c8fedad3a32c11a254160a2f29996a4d0f802d
1
ssh://brewery@pls.lobotomise.me:33/atagen/monolith.git
flake.nixNix116 lines3.2 KB
1
{
2
  inputs = {
3
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
4
    crane.url = "github:ipetkov/crane";
5
  };
6
7
  outputs =
8
    {
9
      self,
10
      nixpkgs,
11
      crane,
12
    }:
13
    let
14
      lib = nixpkgs.lib;
15
      systems = [
16
        "x86_64-linux"
17
        "aarch64-linux"
18
      ];
19
      forAllSystems = f: lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
20
21
      mkProject =
22
        pkgs:
23
        let
24
          craneLib = crane.mkLib pkgs;
25
          src = lib.cleanSourceWith {
26
            src = ./.;
27
            filter = path: type: (craneLib.filterCargoSources path type) || lib.hasInfix "/shaders" path || lib.hasInfix "/res" path;
28
            name = "source";
29
          };
30
          lavapipeIcd = "${pkgs.mesa}/share/vulkan/icd.d/lvp_icd.${pkgs.stdenv.hostPlatform.parsed.cpu.name}.json";
31
          commonArgs = {
32
            inherit src;
33
            pname = "monolith";
34
            version = "0.0.0";
35
            strictDeps = true;
36
            nativeBuildInputs = [
37
              pkgs.pkg-config
38
              pkgs.glslang
39
            ];
40
            buildInputs = with pkgs; [
41
              libxkbcommon
42
              vulkan-loader
43
              libinput
44
              seatd
45
              libgbm
46
              libdrm
47
              udev
48
            ];
49
          };
50
          cargoArtifacts = craneLib.buildDepsOnly commonArgs;
51
        in
52
        {
53
          inherit craneLib lavapipeIcd commonArgs;
54
55
          package = craneLib.buildPackage (
56
            commonArgs
57
            // {
58
              inherit cargoArtifacts;
59
              doCheck = false;
60
              postInstall = ''
61
                install -Dm644 res/monolith-portals.conf -t $out/share/xdg-desktop-portal
62
                install -Dm644 res/monolith.desktop -t $out/share/wayland-sessions
63
              '';
64
            }
65
          );
66
67
          checks = {
68
            clippy = craneLib.cargoClippy (
69
              commonArgs
70
              // {
71
                inherit cargoArtifacts;
72
                cargoClippyExtraArgs = "--all-targets -- --deny warnings";
73
              }
74
            );
75
            fmt = craneLib.cargoFmt { inherit src; pname = "monolith"; version = "0.0.0"; };
76
            test = craneLib.cargoTest (
77
              commonArgs
78
              // {
79
                inherit cargoArtifacts;
80
                VK_DRIVER_FILES = lavapipeIcd;
81
                LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.vulkan-loader ];
82
              }
83
            );
84
          };
85
        };
86
    in
87
    {
88
      packages = forAllSystems (pkgs: {
89
        default = (mkProject pkgs).package;
90
      });
91
92
      checks = forAllSystems (pkgs: (mkProject pkgs).checks);
93
94
      devShells = forAllSystems (
95
        pkgs:
96
        let
97
          project = mkProject pkgs;
98
        in
99
        {
100
          default = project.craneLib.devShell {
101
            inputsFrom = [ project.package ];
102
            packages = with pkgs; [
103
              rust-analyzer
104
              vulkan-tools
105
              vulkan-validation-layers
106
              tracy
107
            ];
108
            LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.vulkan-loader ];
109
            LAVAPIPE_ICD = project.lavapipeIcd;
110
          };
111
        }
112
      );
113
114
      formatter = forAllSystems (pkgs: pkgs.nixfmt);
115
    };
116
}