Skip to content

Commit

Permalink
Feature: add nix support (#2)
Browse files Browse the repository at this point in the history
* Initial commit

* Improve flake.nix

* Remove hello-world print in flake.nix

* Improve flake

* Add default package
  • Loading branch information
RitheeshBaradwaj authored Sep 17, 2023
1 parent 1d76996 commit 573e6f6
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@

/build/
/bazel-*
/.direnv
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "cosmos-cli")
7 changes: 7 additions & 0 deletions devshell.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[env]
FOO = "barh"

[devshell]
packages = [
"bazel",
]
57 changes: 57 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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) ];
# };

});
}
1 change: 1 addition & 0 deletions result
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default
4 changes: 4 additions & 0 deletions tools/nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

nix flake lock --update-input nixpkgs
nix flake update
2 changes: 2 additions & 0 deletions tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

brew install bazelisk

# sh <(curl -L https://nixos.org/nix/install)

# for linting
brew install clang-format
brew install buildifier
Expand Down

0 comments on commit 573e6f6

Please sign in to comment.