flake: add initial nix flake

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
This commit is contained in:
Christoph Heiss 2024-07-04 12:36:35 +02:00
parent ba01119eb6
commit 77ff1dc9a4
Signed by: c8h4
GPG key ID: 1538094429952F86
2 changed files with 206 additions and 0 deletions

107
flake.lock Normal file
View file

@ -0,0 +1,107 @@
{
"nodes": {
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1710886643,
"narHash": "sha256-saTZuv9YeZ9COHPuj8oedGdUwJZcbQ3vyRqe7NVJMsQ=",
"owner": "ipetkov",
"repo": "crane",
"rev": "5bace74e9a65165c918205cf67ad3977fe79c584",
"type": "github"
},
"original": {
"owner": "ipetkov",
"ref": "v0.16.3",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706741902,
"narHash": "sha256-sZEirOfilnVXOlEoLIxD4RR0jxPIxOfWl/qbTUYHxPg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "54622e4828f7f66d1e3ccc1fab3dc03cc95aeb8e",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "54622e4828f7f66d1e3ccc1fab3dc03cc95aeb8e",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1712110341,
"narHash": "sha256-8LU2IM4ctHz043hlzoFUwQS1QIdhiMGEH/oIfPCxoWU=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "74deb67494783168f5b6d2071d73177e6bccab65",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

99
flake.nix Normal file
View file

@ -0,0 +1,99 @@
{
description = "bwtui";
inputs = {
nixpkgs.url =
"github:NixOS/nixpkgs/54622e4828f7f66d1e3ccc1fab3dc03cc95aeb8e"; # 31-01-2024
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane/v0.16.3";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib;
rustToolchain = pkgs.rust-bin.stable."1.77.1".default.override {
extensions = [ "rust-analyzer" ];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
inherit src;
cargoVendorDir = null;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
commonArgsWithArtifacts = commonArgs // { inherit cargoArtifacts; };
cargoTypos = args:
craneLib.mkCargoDerivation (commonArgs // args // {
cargoArtifacts = null;
buildPhaseCargoCommand = "typos";
pnameSuffix = "-typos";
nativeBuildInputs = (args.nativeBuildInputs or [ ])
++ (with pkgs; [ typos protobuf ]);
preInstallPhases = [ "ensureTargetDir" ]
++ (args.preInstallPhases or [ ]);
ensureTargetDir = ''
mkdir -p ''${CARGO_TARGET_DIR:-target}
'';
});
shouldRunCoverage = system == "x86_64-linux"
&& ((builtins.getEnv "CI") != "");
bwtui = craneLib.buildPackage commonArgsWithArtifacts;
in {
checks = {
inherit bwtui;
default = bwtui;
bwtui-clippy = craneLib.cargoClippy commonArgsWithArtifacts // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
bwtui-doc = craneLib.cargoDoc commonArgsWithArtifacts;
bwtui-fmt = craneLib.cargoFmt commonArgs;
bwtui-typos = cargoTypos commonArgs;
} // lib.optionalAttrs shouldRunCoverage {
bwtui-coverage = craneLib.cargoTarpaulin commonArgsWithArtifacts;
};
packages = rec {
inherit bwtui;
default = bwtui;
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks.${system};
nativeBuildInputs = with pkgs; [
cargo-expand
deadnix
nixfmt
nodePackages.prettier
rustToolchain
statix
xorg.libxcb
openssl
];
};
});
}