From cd417d2b126d0aef4d8ab77258bffb9104f1a0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 28 Aug 2025 11:55:04 +0200 Subject: [PATCH] feat: init --- .envrc | 1 + .gitignore | 23 ++++++++++++++ Cargo.toml | 6 ++++ flake.lock | 69 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 ++ 6 files changed, 193 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore 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..6a28a7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +### direnv ### +.direnv + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +# Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..058a91c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "complete-rss" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..eacf47d --- /dev/null +++ b/flake.lock @@ -0,0 +1,69 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1754487366, + "narHash": "sha256-pHYj8gUBapuUzKV/kN/tR3Zvqc7o6gdFB9XKXIp1SQ8=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "af66ad14b28a127c5c0f3bbb298218fc63528a18", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1756266583, + "narHash": "sha256-cr748nSmpfvnhqSXPiCfUPxRz2FJnvf/RjJGvFfaCsM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8a6d5427d99ec71c64f0b93d45778c889005d9c2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1756348497, + "narHash": "sha256-xJp3VnoYh4kpsaKFO/7SsGbwOz7pI1ZmjbqpXEuR2cw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "0adf92c70d23fb4f703aea5d3ebb51ac65994f7f", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d2c918e --- /dev/null +++ b/flake.nix @@ -0,0 +1,91 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # wild = { + # url = "github:davidlattimore/wild"; + # inputs.nixpkgs.follows = "nixpkgs"; + # }; + }; + + outputs = inputs: + inputs.flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux"]; + perSystem = { + self', + pkgs, + system, + ... + }: let + runtimeDeps = with pkgs; []; + buildDeps = with pkgs; [pkg-config rustPlatform.bindgenHook]; + devDeps = with pkgs; []; + + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + msrv = cargoToml.package.rust-version; + + rustPackage = features: + (pkgs.makeRustPlatform { + cargo = pkgs.rust-bin.stable.latest.minimal; + rustc = pkgs.rust-bin.stable.latest.minimal; + }).buildRustPackage { + inherit (cargoToml.package) name version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + buildFeatures = features; + buildInputs = runtimeDeps; + nativeBuildInputs = buildDeps; + # Uncomment if your cargo tests require networking or otherwise + # don't play nicely with the Nix build sandbox: + # doCheck = false; + }; + + mkDevShell = rustc: + pkgs.mkShell.override { + stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; + # stdenv = pkgs.useWildLinker pkgs.stdenv; + } { + shellHook = '' + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} + ''; + buildInputs = runtimeDeps; + nativeBuildInputs = buildDeps ++ devDeps ++ [rustc]; + }; + in { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + (import inputs.rust-overlay) + # inputs.wild.overlays.default + ]; + }; + + packages.default = self'.packages.example; + devShells.default = self'.devShells.nightly; + + packages.example = rustPackage ""; + + devShells.nightly = let + nightly = (pkgs.rust-bin.selectLatestNightlyWith + (toolchain: toolchain.default)).override { + extensions = ["rustc-codegen-cranelift-preview"]; + }; + devShell = mkDevShell nightly; + in + devShell.overrideAttrs (old: { + shellHook = + old.shellHook or "" + + '' + export RUSTFLAGS="-Zcodegen-backend=cranelift" + ''; + }); + devShells.stable = mkDevShell pkgs.rust-bin.stable.latest.default; + devShells.msrv = mkDevShell pkgs.rust-bin.stable.${msrv}.default; + }; + }; +} 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!"); +}