diff --git a/.envrc b/.envrc new file mode 100644 --- /dev/null +++ b/.envrc @@ -0,0 +1,11 @@ +# reload when these files change +watch_file flake.nix +watch_file flake.lock + +{ + # shell gc root dir, to avoid nix cleaning up nix packages + mkdir -p "$(direnv_layout_dir)" + + # load nix development environment + eval "$(nix print-dev-env --profile $(direnv_layout_dir)/flake-profile)" +} || use nix diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ # Nix result result-* + +# Direnv +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1641404362, + "narHash": "sha256-8j21rw0xwwuiz8uOybm6gbeQIfAga/cwovzr3z1xzOg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "defafc9a220440180a34f923be9772d9c89a8197", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "Comm flake"; + + inputs = { + utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, nixpkgs, utils, ... }: + let + # put devShell and any other required packages into local overlay + localOverlay = import ./nix/overlay.nix; + overlays = [ + localOverlay + ]; + + pkgsForSystem = system: import nixpkgs { + # if you have additional overlays, you may add them here + overlays = [ + localOverlay # this should expose devShell + ]; + inherit system; + }; + # https://github.com/numtide/flake-utils#usage for more examples + in utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system: rec { + legacyPackages = pkgsForSystem system; + inherit (legacyPackages) devShell; + }) // { + inherit overlays; + overlay = nixpkgs.lib.composeManyExtensions overlays; + }; +} diff --git a/nix/dev-shell.nix b/nix/dev-shell.nix new file mode 100644 --- /dev/null +++ b/nix/dev-shell.nix @@ -0,0 +1,40 @@ +{ mkShell +, stdenv +, lib +, arcanist +, darwin +, nodejs-16_x +, openjdk11 +, protobuf3_15 +, yarn +}: + +mkShell rec { + + # programs which are meant to be executed should go here + nativeBuildInputs = [ + arcanist + nodejs-16_x + protobuf3_15 + yarn + ]; + + # include any libraries or programs in buildInputs + buildInputs = [ + protobuf3_15 + ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ + CoreFoundation + Security + ]); + + # shell commands to be ran upon entering shell + shellHook = '' + # For NixOS, the pre-compiled binaries from npm will not be able to find + # the c++ libraries, so we set them on LD_LIBRARY_PATH + if [ -f /etc/NIXOS ]; then + export LD_LIBRARY_PATH=${stdenv.cc.cc.lib}/lib + fi + + echo "Welcome to Comm dev environment! :)" + ''; +} diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,5 @@ +prev: final: { + # add packages meant for just this repository + + devShell = final.callPackage ./dev-shell.nix { }; +}