nix: add flake

main
Bruno BELANYI 1 year ago
parent 7b7e77e98a
commit d4fa00263f

@ -0,0 +1,116 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1634851050,
"narHash": "sha256-N83GlSGPJJdcqhUxSCS/WwW5pksYf3VP1M13cDRTSVA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c91f3de5adaf1de973b797ef7485e441a65b8935",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "master",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1636103400,
"narHash": "sha256-6DRg/0P9oT5I/V02sloqGVHf8F6f+7DFoBZNPdr+hOI=",
"owner": "nix-community",
"repo": "naersk",
"rev": "074d81b1a45145f076b2adf93184073fc9615397",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1636254356,
"narHash": "sha256-eBujs6+KrAa0WqYwo/zUmzRohKFBqP52x2EcNw5arwE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "81d15682625635d93ba66def75fd13fd16c0515b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1634595438,
"narHash": "sha256-hV9D41fqTateTligwNd9dmJKQ0R0w6RpCN92xR3LhHk=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "06fa80325b6fe3b28d136071dd0ce55d4817e9fd",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "master",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1636337726,
"narHash": "sha256-Yhhb84u7/zykA/XzltuIm7g9HPJFlsUE/eanW1iMxRg=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "1eb86a50e2afda6bae23526249a927127b67e35e",
"type": "github"
},
"original": {
"owner": "oxalica",
"ref": "master",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

@ -0,0 +1,160 @@
{
description = "A simple Tiger compiler";
inputs = {
flake-utils = {
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "master";
};
naersk = {
type = "github";
owner = "nix-community";
repo = "naersk";
ref = "master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixpkgs-unstable";
};
pre-commit-hooks = {
type = "github";
owner = "cachix";
repo = "pre-commit-hooks.nix";
ref = "master";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
rust-overlay = {
type = "github";
owner = "oxalica";
repo = "rust-overlay";
ref = "master";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
};
outputs =
{ self
, flake-utils
, naersk
, nixpkgs
, pre-commit-hooks
, rust-overlay
}:
{
overlay = final: prev: {
tig-rs =
let
inherit (final) system;
overlays = [
(import rust-overlay)
];
pkgs = import nixpkgs { inherit overlays system; };
my-rust = pkgs.rust-bin.stable.latest;
naersk-lib = naersk.lib."${system}".override {
cargo = my-rust.default;
rustc = my-rust.default;
};
in
naersk-lib.buildPackage {
pname = "tig-rs";
version = "0.0.0";
src = ./.;
nativeBuildInputs = with final; [
pkg-config
];
buildInputs = with final; [
openssl
];
passthru = {
inherit my-rust;
};
meta = with final.lib; {
homepage = "https://gitea.belanyi.fr/ambroisie/tig-rs";
license = with licenses; [ mit asl20 ];
maintainers = with maintainers; [ ambroisie ];
platforms = platforms.unix;
};
};
};
} // (flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ self.overlay ];
pkgs = import nixpkgs { inherit overlays system; };
inherit (pkgs) lib;
inherit (pkgs.tig-rs.passthru) my-rust;
in
rec {
apps = {
tig-rs = flake-utils.lib.mkApp { drv = packages.tig-rs; };
};
checks = {
pre-commit = pre-commit-hooks.lib.${system}.run {
src = ./.;
# FIXME: clippy and rustfmt fail when inside `nix flake check`
# but `pre-commit run --all` works properly...
# Also a problem when not overriding the `entry`
hooks = {
clippy = {
enable = true;
entry = lib.mkForce "${my-rust.clippy}/bin/cargo-clippy clippy";
};
nixpkgs-fmt = {
enable = true;
};
rustfmt = {
enable = true;
entry = lib.mkForce "${my-rust.rustfmt}/bin/cargo-fmt fmt -- --check --color always";
};
};
};
};
defaultApp = apps.tig-rs;
defaultPackage = packages.tig-rs;
devShell = pkgs.mkShell {
inputsFrom = [
defaultPackage
];
nativeBuildInputs = with pkgs; [
rust-analyzer
];
inherit (checks.pre-commit) shellHook;
RUST_SRC_PATH = "${my-rust.rust-src}/lib/rustlib/src/rust/library";
};
packages = {
inherit (pkgs) tig-rs;
};
}));
}
Loading…
Cancel
Save