Skip to content

Commit

Permalink
refactor: Refactor Flake, add legacy Nix support and CI
Browse files Browse the repository at this point in the history
Signed-off-by: Dom Rodriguez <[email protected]>
  • Loading branch information
shymega committed Mar 21, 2024
1 parent 5e00ad3 commit 7958a29
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 98 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci-tests-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: CI tests (Nix)

on:
workflow_call:

jobs:
run-tests:
name: Nix CI tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- name: Build Nix package
run: nix build
- name: Check Flake formatting
run: nix run nixpkgs#nixpkgs-fmt -- --check ./
- name: Check Flake with Nix
run: nix flake check
- name: Check Flake with Statix
run: nix run nixpkgs#statix -- check ./
4 changes: 4 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ jobs:
test-linux:
uses: ./.github/workflows/ci-tests-linux.yml
secrets: inherit

test-nix:
uses: /.github/workflows/ci-tests-nix.yml
secrets: inherit
24 changes: 24 additions & 0 deletions codid.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ lib
, pkgs ? import <nixpkgs>
, rustPlatform
,
}:
rustPlatform.buildRustPackage {
name = "codid";

src = lib.cleanSource ./.;

cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};

nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ systemd.dev ];

meta = with lib; {
description = "";
homepage = "https://github.com/Cosmo-CoDiOS/codid";
license = licenses.mit;
};
}
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
85 changes: 28 additions & 57 deletions flake.lock

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

68 changes: 27 additions & 41 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";

nixpkgs-mozilla = {
url = "github:mozilla/nixpkgs-mozilla";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = { self, flake-utils, naersk, nixpkgs, nixpkgs-mozilla }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{ self
, nixpkgs
, flake-utils
, ...
}:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = (import nixpkgs) {
inherit system;

overlays = [
(import nixpkgs-mozilla)
];
};

toolchain = (pkgs.rustChannelOf {
rustToolchain = ./rust-toolchain;
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
}).rust;

naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};

pkgs = nixpkgs.outputs.legacyPackages.${system};
in
{
# For `nix build` & `nix run`:
packages.codid = naersk'.buildPackage {
src = ./.;
nativeBuildInputs = with pkgs; [ pkg-config cmake ];
buildInputs = with pkgs; [ systemd.dev dbus.dev protobuf protobufc ];
};

packages.codid = pkgs.callPackage ./codid.nix { };
packages.default = self.outputs.packages.${system}.codid;

# For `nix develop` (optional, can be skipped):
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ toolchain ] ++ (with pkgs; [ rustc cargo pkg-config cmake ]);
buildInputs = with pkgs; [ systemd.dev dbus.dev protobuf protobufc ];
};
}) // {
overlays.default = final: prev: {
inherit (self.packages.${final.system}) codid;
};
devShells.default = self.packages.${system}.default.overrideAttrs (super: {
nativeBuildInputs = with pkgs;
super.nativeBuildInputs
++ [
clippy
rustfmt
];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
});
})
// {
overlays.default = final: prev: {
inherit (self.packages.${final.system}) codid;
};
};
}
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix

0 comments on commit 7958a29

Please sign in to comment.