Skip to content

The Nix pipelines #1573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/audit.toml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work in the sandbox

What happens in the sandbox? Does it fail to send HTTP requests to crates.io?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not checked (this is crane generated defaults) but I suppose yes it fails

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Doesn't work in the sandbox
[yanked]
enabled = false # Warn for yanked crates in Cargo.lock (default: true)
update_index = false # Auto-update the crates.io index (default: true)
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
24 changes: 24 additions & 0 deletions .github/flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: update-flake-lock

on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 0 * * 0' # runs weekly on Sunday at 00:00

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Determinate Nix
uses: DeterminateSystems/nix-installer-action@main
with:
determinate: true
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@main
with:
pr-title: "Update flake.lock" # Title of PR to be created
pr-labels: | # Labels to be set on the PR
dependencies
automated
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/stage
/parts
/prime
.direnv
.gitignore.swp
.DS_Store
result
Expand Down
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[licenses]
allow = ["MIT"]
94 changes: 94 additions & 0 deletions flake.lock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to research flake later, but could you discuss the pros of tracking the lock file in the repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same pros of tracking cargo.lock in repository - to be sure the shell will be SAME, and to be sure it is going to behave same way anywhere.

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

139 changes: 139 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
description = "Git repository summary on your terminal";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

crane.url = "github:ipetkov/crane";

flake-utils.url = "github:numtide/flake-utils";

advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};

outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

inherit (pkgs) lib;

craneLib = crane.mkLib pkgs;
src = ./.;

# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;

buildInputs = with pkgs;
[
# package dependencies
zstd
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
# additional dependencies on Darwin systems
CoreFoundation
libresolv
Security
]);
nativeBuildInputs = with pkgs; [ cmake pkg-config ];
nativeCheckInputs = with pkgs; [ git ];

# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};

# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

# Build the actual crate itself, reusing the dependency
# artifacts from above.
onefetch =
craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
in {
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit onefetch;

# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
onefetch-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});

onefetch-doc =
craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; });

# Check formatting
onefetch-fmt = craneLib.cargoFmt { inherit src; };

onefetch-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};

# Audit dependencies
onefetch-audit = craneLib.cargoAudit { inherit src advisory-db; };

# Audit licenses
onefetch-deny = craneLib.cargoDeny { inherit src; };

# Run tests with cargo-nextest
# Consider setting `doCheck = false` on `my-crate` if you do not want
# the tests to run twice
onefetch-nextest = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
});
};

packages = rec {
onefetch-debug = onefetch // {
cargoExtraArgs = lib.concatStringsSep " " [
# Just to get more human-readable look
"--profile dev"
];
};
inherit onefetch;
default = onefetch-debug;
};

apps.default = flake-utils.lib.mkApp { drv = onefetch; };

devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};

# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";

# Extra inputs can be added here; cargo and rustc are provided by default.
packages = with pkgs; [
# pkgs.ripgrep
nixd
nixfmt
];
};
});
# Sets substituters to avoid locally building something already built
nixConfig = {
extra-substituters =
[ "https://crane.cachix.org" "https://cache.garnix.io" ];
extra-trusted-public-keys = [
"crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk="
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
];
};
}
13 changes: 13 additions & 0 deletions taplo.toml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting up TOML formatting sounds good to me, but TBH I think this can go in a separate PR. That way we can get TOML formatting merged in faster while we still discuss flake.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sorts `Cargo.toml` dependencies. All other `.toml` files are formatted with the default config.
#
# https://taplo.tamasfe.dev/configuration/file.html#configuration-file

[formatting]
reorder_keys = false

[[rule]]
include = ["**/Cargo.toml"]
keys = ["dependencies"]

[rule.formatting]
reorder_keys = true