Skip to content

Commit 933db1a

Browse files
authored
Add Nix Flake (#27)
* Add Nix Flake * Add CI job to test-drive Nix Flake
1 parent 713333f commit 933db1a

4 files changed

Lines changed: 145 additions & 0 deletions

File tree

.github/workflows/quick-check.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,23 @@ jobs:
8080
with:
8181
command: check
8282
args: ${{ matrix.feature-flags }}
83+
84+
quick_check-flake:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Install Nix
88+
uses: DeterminateSystems/nix-installer-action@v4
89+
90+
- name: Cache Nix dependencies
91+
uses: DeterminateSystems/magic-nix-cache-action@v2
92+
93+
- uses: actions/checkout@v2
94+
95+
- name: Check flake
96+
run: nix flake check
97+
98+
- name: Build flake
99+
run: nix build
100+
101+
- name: Test run flake
102+
run: nix run . -- --version

default.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{ lib
2+
, naersk
3+
, stdenv
4+
, hostPlatform
5+
, targetPlatform
6+
, cargo
7+
, rustc
8+
}:
9+
let
10+
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
11+
in
12+
naersk.lib."${targetPlatform.system}".buildPackage rec {
13+
src = ./.;
14+
buildInputs = [
15+
cargo
16+
rustc
17+
];
18+
cargoBuildOptions = final: final ++ [ "--all-features" ];
19+
CARGO_BUILD_INCREMENTAL = "false";
20+
copyLibs = true;
21+
name = cargoToml.package.name;
22+
version = cargoToml.package.version;
23+
meta = with lib; {
24+
description = cargoToml.package.description;
25+
homepage = cargoToml.package.homepage;
26+
license = with licenses; [ mit ];
27+
maintainers = with maintainers; [ ];
28+
mainProgram = "tera";
29+
};
30+
}

flake.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
description = "A command line utility written in Rust to render templates from json|toml|yaml && ENV, using the tera templating engine";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
naersk.url = "github:nmattia/naersk";
6+
naersk.inputs.nixpkgs.follows = "nixpkgs";
7+
};
8+
outputs = { self, nixpkgs, naersk }:
9+
let
10+
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
11+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
12+
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
13+
in
14+
{
15+
overlay = final: prev: {
16+
"${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; };
17+
};
18+
packages = forAllSystems (system:
19+
let
20+
pkgs = import nixpkgs {
21+
inherit system;
22+
overlays = [
23+
self.overlay
24+
];
25+
};
26+
in
27+
{
28+
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
29+
});
30+
defaultPackage = forAllSystems (system: (import nixpkgs {
31+
inherit system;
32+
overlays = [ self.overlay ];
33+
})."${cargoToml.package.name}");
34+
devShell = forAllSystems (system:
35+
let
36+
pkgs = import nixpkgs {
37+
inherit system;
38+
overlays = [ self.overlay ];
39+
};
40+
in
41+
pkgs.mkShell {
42+
inputsFrom = with pkgs; [
43+
pkgs."${cargoToml.package.name}"
44+
];
45+
});
46+
};
47+
}

0 commit comments

Comments
 (0)