refactor(dhall-*): put common parts into build.nix

The files are very self-similar, and provided upstream doesn’t do
something completely crazy, they should stay that way.

dhall-json is more complicated, and it wasn’t worth it implemented
something more complicated in build.nix, so for now it stays the same.
This commit is contained in:
Profpatsch 2020-08-04 20:56:48 +02:00
parent 7c22a145fc
commit e207b5c2c6
6 changed files with 51 additions and 125 deletions

30
build.nix Normal file
View file

@ -0,0 +1,30 @@
{ pkgs, release }:
{ simpleName, binName, attrName, completionName ? binName }:
let
release = import ./release.nix;
in
pkgs.stdenv.mkDerivation rec {
name = simpleName;
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.${"${attrName}-darwin"}.url;
sha256 = release.${"${attrName}-darwin"}.hash;
}
else pkgs.fetchzip {
url = release.${"${attrName}-linux"}.url;
sha256 = release.${"${attrName}-linux"}.hash;
};
installPhase = ''
mkdir -p $out/bin
binPath="$out/bin/${binName}"
install -D -m555 -T ${binName} "$binPath"
mkdir -p $out/etc/bash_completion.d/
"$binPath" --bash-completion-script "$binPath" > "$out/etc/bash_completion.d/${completionName}-completion.bash"
'';
}

View file

@ -1,28 +1,7 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let import ./build.nix { inherit pkgs; release = import ./release.nix; } {
release = import ./release.nix; simpleName = "dhall-bash-simple";
in binName = "dhall-to-bash";
attrName = "dhall-bash";
pkgs.stdenv.mkDerivation rec {
name = "dhall-bash-simple";
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.dhall-bash-darwin.url;
sha256 = release.dhall-bash-darwin.hash;
}
else pkgs.fetchzip {
url = release.dhall-bash-linux.url;
sha256 = release.dhall-bash-linux.hash;
};
installPhase = ''
mkdir -p $out/bin
DHALL_TO_BASH=$out/bin/dhall-to-bash
install -D -m555 -T dhall-to-bash $DHALL_TO_BASH
mkdir -p $out/etc/bash_completion.d/
$DHALL_TO_BASH --bash-completion-script $DHALL_TO_BASH > $out/etc/bash_completion.d/dhall-to-bash-completion.bash
'';
} }

View file

@ -1,28 +1,7 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let import ./build.nix { inherit pkgs; release = import ./release.nix; } {
release = import ./release.nix; simpleName = "dhall-lsp-simple";
in binName = "dhall-lsp-server";
attrName = "dhall-lsp-server";
pkgs.stdenv.mkDerivation rec {
name = "dhall-lsp-simple";
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.dhall-lsp-server-darwin.url;
sha256 = release.dhall-lsp-server-darwin.hash;
}
else pkgs.fetchzip {
url = release.dhall-lsp-server-linux.url;
sha256 = release.dhall-lsp-server-linux.hash;
};
installPhase = ''
mkdir -p $out/bin
DHALL_LSP=$out/bin/dhall-lsp-server
install -D -m555 -T dhall-lsp-server $DHALL_LSP
mkdir -p $out/etc/bash_completion.d/
$DHALL_LSP --bash-completion-script $DHALL_LSP > $out/etc/bash_completion.d/dhall-lsp-server-completion.bash
'';
} }

View file

@ -1,28 +1,7 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let import ./build.nix { inherit pkgs; release = import ./release.nix; } {
release = import ./release.nix; simpleName = "dhall-nix-simple";
in binName = "dhall-to-nix";
attrName = "dhall-nix";
pkgs.stdenv.mkDerivation rec {
name = "dhall-nix-simple";
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.dhall-nix-darwin.url;
sha256 = release.dhall-nix-darwin.hash;
}
else pkgs.fetchzip {
url = release.dhall-nix-linux.url;
sha256 = release.dhall-nix-linux.hash;
};
installPhase = ''
mkdir -p $out/bin
DHALL_TO_NIX=$out/bin/dhall-to-nix
install -D -m555 -T dhall-to-nix $DHALL_TO_NIX
mkdir -p $out/etc/bash_completion.d/
$DHALL_TO_NIX --bash-completion-script $DHALL_TO_NIX > $out/etc/bash_completion.d/dhall-to-nix-completion.bash
'';
} }

View file

@ -1,28 +1,7 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let import ./build.nix { inherit pkgs; release = import ./release.nix; } {
release = import ./release.nix; simpleName = "dhall-simple";
in binName = "dhall";
attrName = "dhall";
pkgs.stdenv.mkDerivation rec {
name = "dhall-simple";
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.dhall-darwin.url;
sha256 = release.dhall-darwin.hash;
}
else pkgs.fetchzip {
url = release.dhall-linux.url;
sha256 = release.dhall-linux.hash;
};
installPhase = ''
mkdir -p $out/bin
DHALL=$out/bin/dhall
install -D -m555 -T dhall $DHALL
mkdir -p $out/etc/bash_completion.d/
$DHALL --bash-completion-script $DHALL > $out/etc/bash_completion.d/dhall-completion.bash
'';
} }

View file

@ -1,28 +1,8 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let import ./build.nix { inherit pkgs; release = import ./release.nix; } {
release = import ./release.nix; simpleName = "dhall-yaml-simple";
in binName = "dhall-to-yaml-ng";
attrName = "dhall-yaml";
pkgs.stdenv.mkDerivation rec { completionName = "dhall-to-yaml";
name = "dhall-yaml-simple";
src = if pkgs.stdenv.isDarwin
then pkgs.fetchzip {
url = release.dhall-yaml-darwin.url;
sha256 = release.dhall-yaml-darwin.hash;
}
else pkgs.fetchzip {
url = release.dhall-yaml-linux.url;
sha256 = release.dhall-yaml-linux.hash;
};
installPhase = ''
mkdir -p $out/bin
DHALL_TO_YAML=$out/bin/dhall-to-yaml-ng
install -D -m555 -T dhall-to-yaml-ng $DHALL_TO_YAML
mkdir -p $out/etc/bash_completion.d/
$DHALL_TO_YAML --bash-completion-script $DHALL_TO_YAML > $out/etc/bash_completion.d/dhall-to-yaml-completion.bash
'';
} }