From a3b1c13c074383669c6b3db302569c6fbb8442eb Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Mon, 18 Dec 2023 17:11:41 +0100 Subject: [PATCH] adding flake and rust-toolchain.toml --- .envrc | 1 + .gitignore | 3 +- flake.lock | 112 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 70 +++++++++++++++++++++++++++ rust-toolchain.toml | 2 + 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml 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 index 2a0038a..c1c8ad7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -.idea \ No newline at end of file +.idea +.direnv/ \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..de60d88 --- /dev/null +++ b/flake.lock @@ -0,0 +1,112 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1702312524, + "narHash": "sha256-gkZJRDBUCpTPBvQk25G0B7vfbpEYM5s5OZqghkjZsnE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a9bf124c46ef298113270b1f84a164865987a91c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "systems": "systems_2" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1702865809, + "narHash": "sha256-K7caQe+KqjqTBFmJawmBjmm25S6bza5CXhAqbXFLyH8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b2aafcee4a8842cecfc877ff7dd271f333dc0fa8", + "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": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0306880 --- /dev/null +++ b/flake.nix @@ -0,0 +1,70 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + systems.url = "github:nix-systems/default-linux"; + }; + + outputs = { self, nixpkgs, rust-overlay, systems, ... }: + let + eachSystem = nixpkgs.lib.genAttrs (import systems); + + mkLipsumCli = { rustPlatform, lib, ... }: rustPlatform.buildRustPackage rec { + pname = "lipsum-cli"; + version = "0.3.0"; + + src = builtins.path { + path = ./.; + name = pname; + }; + cargoLock.lockFile = ./Cargo.lock; + + meta = { + description = "A small terminal application written in Rust language. "; + homepage = "https://github.com/xlith/lipsum-cli"; + license = lib.licenses.mit; + }; + }; + in + { + apps = eachSystem (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/lipsum-cli"; + }; + }); + + packages = eachSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + { + default = pkgs.callPackage mkLipsumCli { }; + }); + + overlays.default = final: prev: { + lipsum-cli = prev.callPackage mkLipsumCli { }; + }; + + devShells = eachSystem (system: + let + pkgs = import nixpkgs { + inherit system; + + overlays = [ rust-overlay.overlays.default ]; + }; + + toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + extensions = [ "rust-src" "rust-analyzer" ]; + }; + in + { + default = pkgs.mkShell { + packages = [ toolchain ]; + }; + }); + }; +} + diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..292fe49 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable"