about summary refs log tree commit diff
path: root/templates/rust/flake.nix
blob: 49c2f76d262030ef48d012ab586e03412c72c484 (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
66
{
  description = "A CLI to manage public SSH keys for GitHub.";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
    rust-overlay.url = "github:oxalica/rust-overlay";
    naersk.url = "github:nmattia/naersk";
  };

  outputs =
    { self
    , flake-utils
    , nixpkgs
    , naersk
    , rust-overlay
    }:

    flake-utils.lib.eachDefaultSystem
      (system:
      let
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs { inherit system overlays; };
        rust-toolchain =
          (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
            extensions = [ "rust-src" ];
          };
        naersk-lib = naersk.lib."${system}".override {
          rustc = rust-toolchain;
        };
      in
      rec
      {
        packages.gh-ssh-keys = naersk-lib.buildPackage {
          pname = "gh-ssh-keys";
          root = ./.;
          buildInputs = with pkgs; [
            pkg-config
            openssl
          ];
        };

        defaultPackage = packages.gh-ssh-keys;

        devShell = pkgs.mkShell {
          nativeBuildInputs = with pkgs; [
            rust-toolchain
            openssl
            pkg-config
            cargo-audit
            cargo-deny
            cargo-cross
            rust-analyzer
          ] ++ pkgs.lib.optionals (pkgs.stdenv.isLinux) (with pkgs; [ cargo-watch ]);

          shellHook = ''
            cargo --version
          '';
        };
      })
    // {
      overlay = final: prev: {
        gh-ssh-keys = self.defaultPackage.${prev.system};
      };
    };
}