From 861bb26b836abf8270b59356dbd82c6977766892 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 1 Dec 2023 06:15:57 -0600 Subject: [PATCH] build: add nix flake --- .gitignore | 1 + flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++++++++++++++++++++++++++++++++++++ shell.nix | 1 + 4 files changed, 112 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 0f9d898..6396399 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target out +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..893f1d5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701253981, + "narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "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..79e4365 --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +# Credit to https://github.com/srid/rust-nix-template/blob/master/flake.nix +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + pkgs = nixpkgs.legacyPackages.${system}; + rust-toolchain = pkgs.symlinkJoin { + name = "rust-toolchain"; + paths = with pkgs; [ + rustc + cargo + cargo-watch + rust-analyzer + rustfmt + ]; + }; + in + rec { + # This builds the blog binary then runs it and collects the output. Once done it throws away the binary and + # shoves the newly created static site into the result. + packages.default = pkgs.rustPlatform.buildRustPackage { + name = "blog"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + postBuild = '' + ./target/*/release/blog + ''; + installPhase = '' + cp -r ./out $out + ''; + }; + + overlays.default = packages.default; + # Rust dev environment + devShells.default = pkgs.mkShell { + shellHook = '' + # For rust-analyzer 'hover' tooltips to work. + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} + ''; + nativeBuildInputs = [ rust-toolchain ]; + }; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..8745f50 --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default