diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..57095db --- /dev/null +++ b/.envrc @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Watch & reload direnv on change +watch_file devshell.toml + +if [[ $(type -t use_flake) != function ]]; then + echo "ERROR: use_flake function missing." + echo "Please update direnv to v2.30.0 or later." + exit 1 +fi + +use flake diff --git a/.gitignore b/.gitignore index 8b2e868..4a10075 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ /build/ /bazel-* +/.direnv diff --git a/WORKSPACE b/WORKSPACE index e69de29..442239c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -0,0 +1 @@ +workspace(name = "cosmos-cli") diff --git a/devshell.toml b/devshell.toml new file mode 100644 index 0000000..9458329 --- /dev/null +++ b/devshell.toml @@ -0,0 +1,7 @@ +[env] +FOO = "barh" + +[devshell] +packages = [ + "bazel", +] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..957aebb --- /dev/null +++ b/flake.lock @@ -0,0 +1,57 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "ref": "main", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "revCount": 87, + "type": "git", + "url": "https://github.com/numtide/flake-utils" + }, + "original": { + "ref": "main", + "type": "git", + "url": "https://github.com/numtide/flake-utils" + } + }, + "nixpkgs": { + "locked": { + "narHash": "sha256-IIqmex9yVlfdy0+DSx0fqMhprDTEV6ZMFskW4GI4KK0=", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/23.05/nixos-23.05.861.d3bb401dcfc/nixexprs.tar.xz" + }, + "original": { + "type": "tarball", + "url": "https://releases.nixos.org/nixos/23.05/nixos-23.05.861.d3bb401dcfc/nixexprs.tar.xz" + } + }, + "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..4af23b3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + description = "Cosmos CLI"; + + inputs = { + nixpkgs.url = "https://releases.nixos.org/nixos/23.05/nixos-23.05.861.d3bb401dcfc/nixexprs.tar.xz"; + flake-utils.url = "git+https://github.com/numtide/flake-utils?ref=main"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + nativeBuildInputs = with pkgs; + [ + bazel_6 + bazel-buildtools + ]; + cosmos = pkgs.stdenv.mkDerivation { + name = "cosmos"; + version = "0.0.1"; + src = self; + nativeBuildInputs = nativeBuildInputs; + buildPhase = '' + bazel build //src:hello-world; + ''; + + installPhase = '' + mkdir -p $out/bin; + cp -r bazel-bin/src/hello-world $out/bin; + ''; + }; + in rec + { + defaultPackage = cosmos; + devShells.default = pkgs.mkShell { + nativeBuildInputs = nativeBuildInputs ++ [ + cosmos + ]; + }; + + # default = pkgs.devshell.mkShell { + # imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; + # }; + + }); +} diff --git a/result b/result new file mode 120000 index 0000000..2f74c99 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/922i6v34m2r5r8q2qhb8gqflav3zry87-cosmos \ No newline at end of file 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 diff --git a/tools/nix.sh b/tools/nix.sh new file mode 100755 index 0000000..6f7c3b2 --- /dev/null +++ b/tools/nix.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +nix flake lock --update-input nixpkgs +nix flake update diff --git a/tools/setup.sh b/tools/setup.sh index 0418248..6290279 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -4,6 +4,8 @@ brew install bazelisk +# sh <(curl -L https://nixos.org/nix/install) + # for linting brew install clang-format brew install buildifier