From d03ec53f168e4e28464c1592665dbd594307d8b1 Mon Sep 17 00:00:00 2001 From: ocfox Date: Fri, 24 Mar 2023 21:55:08 +0800 Subject: [PATCH] add flake support --- .envrc | 11 ++++++ .gitignore | 2 ++ flake.lock | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 42 ++++++++++++++++++++++ 4 files changed, 157 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..ce4386f --- /dev/null +++ b/.envrc @@ -0,0 +1,11 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +nix_direnv_watch_file devenv.nix +nix_direnv_watch_file devenv.lock +nix_direnv_watch_file devenv.yaml +if ! use flake . --impure +then + echo "devenv could not be build. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore index eb5a316..895f7d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ target +.devenv +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7d912ee --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1679638953, + "narHash": "sha256-OFATLLft/9vXHf+zqa6OQGTQ2rrCuD97KRzsrPsJRdY=", + "owner": "nix-community", + "repo": "fenix", + "rev": "1336152ce31c0f781ae121aa297a5699c642a9fe", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1679567394, + "narHash": "sha256-ZvLuzPeARDLiQUt6zSZFGOs+HZmE+3g4QURc8mkBsfM=", + "owner": "nix-community", + "repo": "naersk", + "rev": "88cd22380154a2c36799fe8098888f0f59861a15", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1679437018, + "narHash": "sha256-vOuiDPLHSEo/7NkiWtxpHpHgoXoNmrm+wkXZ6a072Fc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "19cf008bb18e47b6e3b4e16e32a9a4bdd4b45f7e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1679520343, + "narHash": "sha256-AJGSGWRfoKWD5IVTu1wEsR990wHbX0kIaolPqNMEh0c=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "eb791f31e688ae00908eb75d4c704ef60c430a92", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7c6b8f7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,42 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + naersk = { + url = "github:nix-community/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, fenix, flake-utils, naersk, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: { + packages.default = + let + pkgs = nixpkgs.legacyPackages.${system}; + toolchain = with fenix.packages.${system}; combine [ + minimal.cargo + minimal.rustc + ]; + in + (naersk.lib.${system}.override { + cargo = toolchain; + rustc = toolchain; + }).buildPackage { + hardeningDisable = [ "all" ]; + buildInputs = with pkgs; [ + clang + zlib + ]; + nativeBuildInputs = with pkgs; [ + elfutils + pkg-config + ]; + src = ./.; + }; + }); +} +