From 0397180be349a79c1ac55a3df004e166763fd6c2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 1 Sep 2024 12:22:16 +0200 Subject: [PATCH] init --- .envrc | 1 + .gitignore | 3 + Cargo.lock | 7 ++ Cargo.toml | 6 ++ flake.lock | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 198 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 + 7 files changed, 431 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fe4aed --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +.direnv +.pre-commit-config.yaml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f58c354 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "signal-to-blog" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8ca375e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "signal-to-blog" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c543b6e --- /dev/null +++ b/flake.lock @@ -0,0 +1,213 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1724775741, + "narHash": "sha256-xuj7Ye3Y2EgunLiEEV5zYxUQuLTURV5mgbXDB1fA7h8=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "fe4d5979b34444815287d61bd2a4e193cebbc7a6", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1725125250, + "narHash": "sha256-CB20rDD5eHikF6mMTTJdwPP1qvyoiyyw1RDUzwIaIF8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "96fd12c7100e9e05fa1a0a5bd108525600ce282f", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722113426, + "narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=", + "owner": "numtide", + "repo": "devshell", + "rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae", + "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": 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": 1725099143, + "narHash": "sha256-CHgumPZaC7z+WYx72WgaLt2XF0yUVzJS60rO4GZ7ytY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5629520edecb69630a3f4d17d3d33fc96c13f6fe", + "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": 1724857454, + "narHash": "sha256-Qyl9Q4QMTLZnnBb/8OuQ9LSkzWjBU1T5l5zIzTxkkhk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "4509ca64f1084e73bc7a721b20c669a8d4c5ebe6", + "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", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1725157860, + "narHash": "sha256-DhqyM7XJYKj+WAEaYwMtXaYX66tA+lOd31sd5QkxLDM=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1fd72e343c6890f695243a37b367a1e3b90a49ee", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..91ee9ec --- /dev/null +++ b/flake.nix @@ -0,0 +1,198 @@ +{ + 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"; + inputs.flake-utils.follows = "flake-utils"; + }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + }; + + 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 = "wheeloftodos"; + + # 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.lib.${localSystem}; + + # 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 = + [ + # 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; [ + udev + alsa-lib + vulkan-loader + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + alsa-lib + libxkbcommon + wayland.dev + ]; + language.c.includes = with pkgs; [ + udev + alsa-lib + vulkan-loader + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + alsa-lib + libxkbcommon + ]; + + 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` + }); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}