From 29cfdbdfa85457b6df14ad91a34ce68784fe878f Mon Sep 17 00:00:00 2001 From: Elnu Date: Tue, 31 Oct 2023 13:33:46 -0700 Subject: [PATCH] Initial commit --- .envrc | 1 + .gitignore | 3 ++ .vscode/settings.json | 5 ++ Cargo.lock | 7 +++ Cargo.toml | 3 ++ flake.nix | 110 +++++++++++++++++++++++++++++++++++++++++ helloworld/Cargo.toml | 8 +++ helloworld/src/main.rs | 3 ++ 8 files changed, 140 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.nix create mode 100644 helloworld/Cargo.toml create mode 100644 helloworld/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..9624092 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +.direnv +result diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0baf00e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "rust-analyzer.linkedProjects": [ + "./helloworld/Cargo.toml", + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..97a944e --- /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 = "helloworld" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3076892 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["helloworld"] +resolver = "2" diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ff7dbee --- /dev/null +++ b/flake.nix @@ -0,0 +1,110 @@ +/* +TODO +1. Find and replace "helloworld" with your package name for **ALL FILES IN REPOSITORY** +2. Add a flake description that describes the workspace on line 27 +3. Add a package description on line 70 +4. (optional) uncomment `nativeBuildInputs` and `buildInputs` on lines 43 and 44 if you need openssl +5. (optional) set your project homepage, license, and maintainers list on lines 48-51 +6. (optional) uncomment the NixOS module and update it for your needs +7. Delete this comment block +*/ + +/* +Some utility commands: +- `nix flake update --commit-lock-file` +- `nix flake lock update-input ` +- `nix build .#helloworld` or `nix build .` +- `nix run .#helloworld` or `nix run .` +*/ + +{ + description = ""; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, rust-overlay }: + let + overlays = [ (import rust-overlay) ]; + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system overlays; + }; + rustSettings = with pkgs; { + src = ./.; + #nativeBuildInputs = [ pkg-config ]; + #buildInputs = [ openssl ]; + cargoHash = nixpkgs.lib.fakeHash; + }; + meta = with nixpkgs.lib; { + #homepage = "https://example.com"; + #license = [ licenses.gpl3 ]; + platforms = [ system ]; + #maintainers = with maintainers; [ ]; + }; + in { + devShells.${system}.default = with pkgs; mkShell { + packages = [ + (pkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" ]; + }) + cargo-edit + bacon + ]; + inputsFrom = with self.packages.${system}; [ helloworld ]; + }; + packages.${system} = { + default = self.packages.${system}.helloworld; + helloworld = pkgs.rustPlatform.buildRustPackage (rustSettings // { + pname = "helloworld"; + version = "0.1.0"; + buildAndTestSubdir = "helloworld"; + cargoHash = "sha256-+TaGIiKf+Pz2bTABeG8aCZz0/ZTCKl5398+qbas4Nvo="; + meta = meta // { + description = ""; + }; + }); + }; + /* + nixosModules.default = { config, ... }: let + lib = nixpkgs.lib; + in { + options.services.helloworld = { + enable = lib.mkEnableOption (lib.mdDoc "helloworld service"); + package = lib.mkOption { + type = lib.types.package; + default = self.packages.${system}.helloworld; + defaultText = "pkgs.helloworld"; + description = lib.mdDoc '' + The helloworld package that should be used. + ''; + }; + port = lib.mkOption { + type = lib.types.port; + default = 8000; + description = lib.mdDoc '' + The port at which to run. + ''; + }; + }; + config.systemd.services.helloworld = let + cfg = config.services.helloworld; + pkg = self.packages.${system}.helloworld; + in lib.mkIf cfg.enable { + description = pkg.meta.description; + after = [ "network.target" ]; + wantedBy = [ "network.target" ]; + serviceConfig = { + ExecStart = '' + ${cfg.package}/bin/helloworld --port ${builtins.toString cfg.port} + ''; + Restart = "always"; + DynamicUser = true; + }; + }; + }; + */ + }; +} diff --git a/helloworld/Cargo.toml b/helloworld/Cargo.toml new file mode 100644 index 0000000..5371865 --- /dev/null +++ b/helloworld/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "helloworld" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/helloworld/src/main.rs b/helloworld/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/helloworld/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}