feat(flake): add flake

This commit is contained in:
Patrick 2024-07-13 22:37:31 +02:00
parent def403a4cb
commit 255a6f1459
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
5 changed files with 438 additions and 0 deletions

2
.envrc Normal file
View file

@ -0,0 +1,2 @@
watch_file ./devshell.nix
use flake

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
/target
.direnv

1
.pre-commit-config.yaml Symbolic link
View file

@ -0,0 +1 @@
/nix/store/gw2875m1b8srd62xpzx3zc2avhwa1d8g-pre-commit-config.json

252
flake.lock Normal file
View file

@ -0,0 +1,252 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1720572893,
"narHash": "sha256-EQfU1yMnebn7LoJNjjsQimyuWwz+2YzazqUZu8aX/r4=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "97a2dc75838f19a5fd63dc3f8e3f57e0c4c8cfe6",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1720546058,
"narHash": "sha256-iU2yVaPIZm5vMGdlT0+57vdB/aPq/V5oZFBRwYw+HBM=",
"owner": "ipetkov",
"repo": "crane",
"rev": "2d83156f23c43598cf44e152c33a59d3892f8b29",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1717408969,
"narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=",
"owner": "numtide",
"repo": "devshell",
"rev": "1ebbe68d57457c8cae98145410b164b5477761f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"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"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1720781449,
"narHash": "sha256-po3TZO9kcZwzvkyMJKb0WCzzDtiHWD34XeRaX1lWXp0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8b5a3d5a1d951344d683b442c0739010b80039db",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1720386169,
"narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "194846768975b7ad2c4988bdb82572c00222c0d7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1720524665,
"narHash": "sha256-ni/87oHPZm6Gv0ECYxr1f6uxB0UKBWJ6HvS7lwLU6oY=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "8d6a17d0cdf411c55f12602624df6368ad86fac1",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"devshell": "devshell",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1720837122,
"narHash": "sha256-WMwo/kZ3o2h5Bls4dEyQ3XFZ4nw2UbbOUFpq3aVlkms=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "92f0608ab66c9770e931056b1c7a1b6249dbc43a",
"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"
}
},
"systems_2": {
"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
}

182
flake.nix Normal file
View file

@ -0,0 +1,182 @@
{
description = "Finding things to do";
inputs = {
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
advisory-db,
devshell,
crane,
flake-utils,
nixpkgs,
pre-commit-hooks,
rust-overlay,
} @ inputs:
flake-utils.lib.eachDefaultSystem (localSystem: let
pkgs = import nixpkgs {
inherit localSystem;
overlays = [
devshell.overlays.default
rust-overlay.overlays.default
];
};
inherit (pkgs) lib;
# TODO: change this to your desired project name
projectName = "pr-tracker";
# Use that toolchain to get a crane lib. Crane is used here to write the
# nix packages that compile and test our rust code.
craneLib = crane.mkLib pkgs;
# For each of the classical cargo "functions" like build, doc, test, ...,
# crane exposes a function that takes some configuration arguments.
# Common settings that we need for all of these are grouped here.
commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
# External packages required to compile this project.
# For normal rust applications this would contain runtime dependencies,
# but since we are compiling for a foreign platform this is most likely
# going to stay empty except for the linker.
buildInputs =
[
pkgs.systemd
pkgs.openssl
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
# 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 package
package = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
});
in {
# Define checks that can be run with `nix flake check`
checks =
{
# Build the crate normally as part of checking, for convenience
${projectName} = package;
# Run clippy (and deny all warnings) on the crate source,
# again, resuing 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.
"${projectName}-clippy" = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
"${projectName}-doc" = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});
# Check formatting
"${projectName}-fmt" = craneLib.cargoFmt {
inherit (commonArgs) src;
};
# Audit dependencies
"${projectName}-audit" = craneLib.cargoAudit {
inherit (commonArgs) src;
inherit advisory-db;
};
}
// {
pre-commit = pre-commit-hooks.lib.${localSystem}.run {
src = ./.;
hooks = {
alejandra.enable = true;
cargo-check.enable = true;
rustfmt.enable = true;
statix.enable = true;
};
};
};
packages.default = package; # `nix build`
packages.${projectName} = package; # `nix build .#${projectName}`
# `nix develop`
devShells.default = pkgs.devshell.mkShell {
name = projectName;
imports = [
"${devshell}/extra/language/c.nix"
"${devshell}/extra/language/rust.nix"
];
language.c.libraries = with pkgs; [
systemd
openssl
];
language.c.includes = with pkgs; [
openssl
];
commands = [
{
package = pkgs.alejandra;
help = "Format nix code";
}
{
package = pkgs.statix;
help = "Lint nix code";
}
{
package = pkgs.deadnix;
help = "Find unused expressions in nix code";
}
];
devshell.startup.pre-commit.text = self.checks.${localSystem}.pre-commit.shellHook;
packages =
commonArgs.buildInputs
++ [
pkgs.pkg-config
pkgs.rust-analyzer
];
};
formatter = pkgs.alejandra; # `nix fmt`
});
}