diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c824d65 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-0gsh4bmn8mfc1iszxvpinkkq652b3wr238qcrqp8rwybmn7pwrqf=" +fi + +use flake . diff --git a/.gitignore b/.gitignore index ea8c4bf..3816ff8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +TODO diff --git a/Cargo.lock b/Cargo.lock index c08475b..0400c5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,15 +4,15 @@ version = 3 [[package]] name = "cc" -version = "1.0.68" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "libc" -version = "0.2.97" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "ncurses" @@ -27,9 +27,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "todo-rs" diff --git a/TODO b/TODO index 0e8447e..b2a9e3c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1 @@ -TODO: Make a cup of tea -TODO: Buy a bread -TODO: Write the todo app -DONE: Make a cup of tea -DONE: Start the stream -DONE: Have a breakfast +TODO: Rust Module diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..7948169 --- /dev/null +++ b/default.nix @@ -0,0 +1,56 @@ +# default.nix +{ lib +, naersk +, stdenv +, clangStdenv +, hostPlatform +, targetPlatform +, pkg-config +, libiconv +, rustfmt +, cargo +, rustc + # , llvmPackages # Optional + # , protobuf # Optional +}: + +let + cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); +in + +naersk.lib."${targetPlatform.system}".buildPackage rec { + src = ./.; + + buildInputs = [ + rustfmt + pkg-config + cargo + rustc + libiconv + ]; + checkInputs = [ cargo rustc ]; + + doCheck = true; + CARGO_BUILD_INCREMENTAL = "false"; + RUST_BACKTRACE = "full"; + copyLibs = true; + + # Optional things you might need: + # + # If you depend on `libclang`: + # LIBCLANG_PATH = "${llvmPackages.libclang}/lib"; + # + # If you depend on protobuf: + # PROTOC = "${protobuf}/bin/protoc"; + # PROTOC_INCLUDE = "${protobuf}/include"; + + name = cargoToml.package.name; + version = cargoToml.package.version; + + meta = with lib; { + description = cargoToml.package.description; + homepage = cargoToml.package.homepage; + license = with licenses; [ mit ]; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1b510f6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1671096816, + "narHash": "sha256-ezQCsNgmpUHdZANDCILm3RvtO1xH8uujk/+EqNvzIOg=", + "owner": "nmattia", + "repo": "naersk", + "rev": "d998160d6a076cfe8f9741e56aeec7e267e3e114", + "type": "github" + }, + "original": { + "owner": "nmattia", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1678724065, + "narHash": "sha256-MjeRjunqfGTBGU401nxIjs7PC9PZZ1FBCZp/bRB3C2M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b8afc8489dc96f29f69bec50fdc51e27883f89c1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..186d355 --- /dev/null +++ b/flake.nix @@ -0,0 +1,84 @@ +# flake.nix +{ + description = "todo-rs"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + naersk.url = "github:nmattia/naersk"; + naersk.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, naersk }: + let + cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + in + { + overlay = final: prev: { + "${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; }; + }; + + packages = forAllSystems (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlay + ]; + }; + in + { + "${cargoToml.package.name}" = pkgs."${cargoToml.package.name}"; + }); + + + defaultPackage = forAllSystems (system: (import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + })."${cargoToml.package.name}"); + + checks = forAllSystems (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlay + ]; + }; + in + { + format = pkgs.runCommand "check-format" + { + buildInputs = with pkgs; [ cargo rustc ncurses ]; + } '' + ${pkgs.rustfmt}/bin/cargo-fmt fmt --manifest-path ${./.}/Cargo.toml -- --check + ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.} + touch $out # it worked! + ''; + "${cargoToml.package.name}" = pkgs."${cargoToml.package.name}"; + }); + devShell = forAllSystems (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }; + in + pkgs.mkShell { + inputsFrom = with pkgs; [ + pkgs."${cargoToml.package.name}" + ]; + # shellHook = '' + # echo "starting todo list app" + # cargo run TODO + # ''; + buildInputs = with pkgs; [ + cargo + rustc + ncurses + ]; + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + }); + }; +} \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..f69b473 --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ pkgs ? import { } }: +let + todoScript = pkgs.writeScriptBin "todo-rs" '' + cargo run TODO + ''; +in pkgs.mkShell { + name = "todo-rs"; + buildInputs = [ pkgs.cargo pkgs.rustc pkgs.glibc pkgs.ncurses ]; + + shellHook = '' + cargo run TODO + ''; +}