From 50bb6b14a57a3953ff35afd189e244adca7d93bb Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 25 Nov 2022 00:13:47 +0300 Subject: [PATCH] initial commit --- .gitignore | 6 ++++++ flake.lock | 41 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ pkgs/d2.nix | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pkgs/d2.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bf12ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# direnv +.direnv +.envrc + +# nix builds +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cee0bf3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669261230, + "narHash": "sha256-AjddxRPd5y5jge77281P3O8+Cnafj842Xg59rwV4x+0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8e8b5f3b1e899bf5d250279578c0283705b8cdb4", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..26963b1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + let + inherit (builtins) listToAttrs mapAttrs; + + mkPackage = pkgs: name: pkgs.callPackage ./pkgs/${name}.nix { }; + mkApp = drv: flake-utils.lib.mkApp { inherit drv; }; + mkOverlay = name: + final: prev: + final.setAttrByPath [ name ] (mkPackage name prev); + + allPackageNames = [ "d2" ]; + mkAllPackages = pkgs': + listToAttrs + (map + (name: { inherit name; value = mkPackage pkgs' name; }) + allPackageNames); + in + { + overlays = (listToAttrs + (map + (name: { inherit name; value = mkOverlay name; }) + allPackageNames + ) + ) // { + all = final: prev: mkAllPackages prev; + }; + } + // flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + packages = mkAllPackages pkgs; + in + { + check = packages; + + inherit packages; + apps = mapAttrs (name: mkApp) packages; + }); +} diff --git a/pkgs/d2.nix b/pkgs/d2.nix new file mode 100644 index 0000000..d7e16c8 --- /dev/null +++ b/pkgs/d2.nix @@ -0,0 +1,33 @@ +{ lib +, buildGoModule +, fetchFromGitHub +, installShellFiles +}: + +let version = "0.0.13"; in + +buildGoModule { + pname = "d2"; + inherit version; + + src = fetchFromGitHub { + owner = "terrastruct"; + repo = "d2"; + rev = "v${version}"; + sha256 = "sha256-2abGQmgwqxWFk7NScdgfEjRYZF2rw8kxTKRwcl2LRg0="; + }; + + vendorSha256 = "sha256-/BEl4UqOL4Ux7I2eubNH2YGGl4DxntpI5WN9ggvYu80="; + + ldflags = [ + "-s" + "-w" + "-X oss.terrastruct.com/d2/lib/version.Version=${version}" + ]; + + nativeBuildInputs = [ installShellFiles ]; + + postInstall = "installManPage ci/release/template/man/d2.1"; + + subPackages = [ "cmd/d2" ]; +}