Skip to content

Commit

Permalink
Add Nix Flake (#27)
Browse files Browse the repository at this point in the history
* Add Nix Flake

* Add CI job to test-drive Nix Flake
  • Loading branch information
alerque committed Jul 24, 2023
1 parent 713333f commit 933db1a
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,23 @@ jobs:
with:
command: check
args: ${{ matrix.feature-flags }}

quick_check-flake:
runs-on: ubuntu-latest
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4

- name: Cache Nix dependencies
uses: DeterminateSystems/magic-nix-cache-action@v2

- uses: actions/checkout@v2

- name: Check flake
run: nix flake check

- name: Build flake
run: nix build

- name: Test run flake
run: nix run . -- --version
30 changes: 30 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ lib
, naersk
, stdenv
, hostPlatform
, targetPlatform
, cargo
, rustc
}:
let
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
in
naersk.lib."${targetPlatform.system}".buildPackage rec {
src = ./.;
buildInputs = [
cargo
rustc
];
cargoBuildOptions = final: final ++ [ "--all-features" ];
CARGO_BUILD_INCREMENTAL = "false";
copyLibs = true;
name = cargoToml.package.name;
version = cargoToml.package.version;
meta = with lib; {
description = cargoToml.package.description;
homepage = cargoToml.package.homepage;
license = with licenses; [ mit ];
maintainers = with maintainers; [ ];
mainProgram = "tera";
};
}
48 changes: 48 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
description = "A command line utility written in Rust to render templates from json|toml|yaml && ENV, using the tera templating engine";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, naersk }:
let
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in
{
overlay = final: prev: {
"${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; };
};
packages = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
];
};
in
{
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
});
defaultPackage = forAllSystems (system: (import nixpkgs {
inherit system;
overlays = [ self.overlay ];
})."${cargoToml.package.name}");
devShell = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
pkgs.mkShell {
inputsFrom = with pkgs; [
pkgs."${cargoToml.package.name}"
];
});
};
}

0 comments on commit 933db1a

Please sign in to comment.