Skip to content

Commit

Permalink
Merge pull request #97 from mattpolzin/nix-flake
Browse files Browse the repository at this point in the history
Nix flake
  • Loading branch information
mattpolzin authored Dec 2, 2023
2 parents f26f35f + 4a1612d commit 8c98a2a
Show file tree
Hide file tree
Showing 10 changed files with 1,644 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ harmony-npm.tar.gz
.*.swp
*.idr~

result
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,51 @@ idris2-version = $(shell $(idris2) --version | sed -En 's/Idris 2, version ([^-]
idris2-build = $(shell $(idris2) --version | sed -En 's/Idris 2, version [^-]+(.*)/\1/p')
idris2-minor-version = $(shell echo ${idris2-version} | sed -En 's/0\.(.*)\../\1/p')

.PHONY: all build install package publish clean version
.PHONY: all build nix-build install package publish clean version

all: build

depends/idris-adds-${idris-adds-version}:
mkdir -p depends/idris-adds-${idris-adds-version}
mkdir -p build/deps
ifeq ($(IDRIS_ADDS_SRC),)
cd build/deps && \
git clone https://github.com/mattpolzin/idris-adds.git && \
cd idris-adds && \
git checkout ${idris-adds-version} && \
make && \
cp -R ./build/ttc/* ../../../depends/idris-adds-${idris-adds-version}/
else
cd build/deps && \
cp -R $(IDRIS_ADDS_SRC) ./idris-adds && \
chmod -R +rw ./idris-adds && \
cd idris-adds && \
make && \
cp -R ./build/ttc/* ../../../depends/idris-adds-${idris-adds-version}/
endif

node_modules:
./node_modules/: package.json
npm install

build: node_modules depends/idris-adds-${idris-adds-version}
build: ./node_modules/ depends/idris-adds-${idris-adds-version}
IDRIS2_DATA=./support $(idris2) --build harmony.ipkg
@if [[ ${idris2-minor-version} -gt 6 ]] || [[ "${idris2-build}" != '' ]]; then \
cp ./build/exec/harmony ./harmony; \
else \
echo "#!/usr/bin/env node\n" > ./harmony; \
echo "#!/usr/bin/env node" > ./harmony; \
cat ./build/exec/harmony >> ./harmony; \
fi
@chmod +x ./harmony

harmony: build

node2nix ?= nix run nixpkgs\#node2nix

nix-build:
${MAKE} clean
$(node2nix) -- --composition node2nix.nix # -l # <- can't use -l for lockfile because lockfile version 3 not supported yet.
nix build .

version:
@(if [[ "${v}" == '' ]]; then echo "please set the 'v' variable."; exit 1; fi)
sed -I '' "s/version = .*/version = ${v}/" ./harmony.ipkg
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Harmony is a small tool that helps teams keep GitHub reviews running smoothly. I

## Dependencies
### Runtime
Running Harmony only requires NodeJS 14+ (and a local installation of `git`).
Running Harmony requires NodeJS 14+ (and a local installation of `git`) or alternatively Nix with flakes enabled.

If you'd like to try Harmony out without even "installing" it and you have Nix installed with flakes enabled, you can run it as `nix run github:mattpolzin/harmony`.

### Build time
Building the latest commits of Harmony requires a HEAD build of the Idris 2 compiler. Each release page also indicates the version of Idris 2 that particular release will build against.

Expand All @@ -29,6 +32,18 @@ You can install Harmony via npm directly by running `npm install -g @mattpolzin/
### GitHub Release
You can install any Harmony release by downloading the `harmony-npm.tar.gz` file from the GitHub Release page, unzipping it, and running `npm install --global`.

### Nix Flake
You can add Harmony to your Flake inputs as follows:
```nix
inputs = {
...
harmony.url = "github:mattpolzin/harmony";
harmony.inputs.nixpkgs.follows = "nixpkgs";
};
```

Then in your outputs, being Harmony into a package install list as `harmony.packages.<system>.harmony`.

### From Source
The build script assumes a HEAD build of Idris 2 is installed on your system. For an alternative, see the [Docker Build](#docker-build) instructions below.

Expand Down
46 changes: 46 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ stdenv, lib, callPackage, fetchFromGitHub, idris2, makeWrapper, nodejs }:
let
nodeDependencies = (callPackage ./node2nix.nix { inherit nodejs; }).nodeDependencies;
idrisAddsVersion = "0.3.0";
idrisAddsSrc = fetchFromGitHub {
owner = "mattpolzin";
repo = "idris-adds";
rev = "${idrisAddsVersion}";
hash = "sha256-OSu381nUNZqFJs4HzmMxGda60k7xsa1GulQq7kU/R2o=";
};
in
stdenv.mkDerivation {
pname = "harmony";
version = "2.6.1";

nativeBuildInputs = [ idris2 makeWrapper ];
buildInputs = [ nodejs ];

src = ./.;

buildPhase = ''
runHook preBuild
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
export PATH="${nodeDependencies}/bin:$PATH"
export IDRIS_ADDS_SRC="${idrisAddsSrc}"
make build
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp harmony $out/bin/
wrapProgram $out/bin/harmony \
--prefix PATH : ${lib.makeBinPath [ nodeDependencies ]} \
--prefix NODE_PATH : ${nodeDependencies}/lib/node_modules
runHook postInstall
'';

}
26 changes: 26 additions & 0 deletions flake.lock

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

23 changes: 23 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
description = "Harmony GitHub collaboration tool";

inputs = {
nixpkgs.url = github:NixOS/nixpkgs;
};

outputs = { self, nixpkgs }:
let
lib = nixpkgs.lib;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
in
{
packages = forAllSystems (system:
{
harmony = with nixpkgs.legacyPackages.${system};
callPackage ./default.nix {};

default = self.packages.${system}.harmony;
}
);
};
}
Loading

0 comments on commit 8c98a2a

Please sign in to comment.