From ec11a5511b7702563635eb2b5617ade200c3673e Mon Sep 17 00:00:00 2001 From: Arul Agrawal Date: Fri, 31 May 2024 17:04:43 +0400 Subject: [PATCH] add nix flake --- .envrc | 1 + .gitignore | 4 ++ flake.lock | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 71 +++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix 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 323a69d..a8d371a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ .env # Idea Files .idea/ + +# nix files +.direnv/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4569244 --- /dev/null +++ b/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717025063, + "narHash": "sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "480dff0be03dac0e51a8dfc26e882b0d123a450e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717112898, + "narHash": "sha256-7R2ZvOnvd9h8fDd65p0JnB7wXfUvreox3xFdYWd1BnY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6132b0f6e344ce2fe34fc051b72fb46e34f668e0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717121863, + "narHash": "sha256-/3sxIe7MZqF/jw1RTQCSmgTjwVod43mmrk84m50MJQ4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "2a7b53172ed08f856b8382d7dcfd36a4e0cbd866", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8bcacf6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + description = "Redlib: Private front-end for Reddit"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { nixpkgs, crane, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + inherit (pkgs) lib; + + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "x86_64-unknown-linux-musl" ]; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + + + src = lib.cleanSourceWith { + src = craneLib.path ./.; + filter = path: type: + (lib.hasInfix "/templates/" path) || + (lib.hasInfix "/static/" path) || + (craneLib.filterCargoSources path type); + }; + + redlib = craneLib.buildPackage { + inherit src; + strictDeps = true; + doCheck = false; + + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + }; + in + { + checks = { + my-crate = redlib; + }; + + packages.default = redlib; + packages.docker = pkgs.dockerTools.buildImage { + name = "quay.io/redlib/redlib"; + tag = "latest"; + created = "now"; + copyToRoot = with pkgs.dockerTools; [ caCertificates fakeNss ]; + config.Cmd = "${redlib}/bin/redlib"; + }; + }); +}