From 0469fc1fbae7d891ae0e0819089bae45bb10b221 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 13 Dec 2022 17:21:48 +0300 Subject: [PATCH] refac structure --- flake.nix | 33 ++++++------ pkgs/d2.nix | 52 ------------------- pkgs/d2/d2-unwrapped.nix | 36 +++++++++++++ pkgs/{ => d2}/d2plugin-tala.nix | 0 pkgs/d2/default.nix | 17 ++++++ ...402_preserve_leading_comment_spacing.patch | 0 6 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 pkgs/d2.nix create mode 100644 pkgs/d2/d2-unwrapped.nix rename pkgs/{ => d2}/d2plugin-tala.nix (100%) create mode 100644 pkgs/d2/default.nix rename {patches/d2 => pkgs/d2/patches}/402_preserve_leading_comment_spacing.patch (100%) diff --git a/flake.nix b/flake.nix index 49d644b..3a000ac 100644 --- a/flake.nix +++ b/flake.nix @@ -7,22 +7,24 @@ let inherit (builtins) listToAttrs mapAttrs; - mkPackage = pkgs': name: - pkgs'.callPackage ./pkgs/${name}.nix ( - if name == "d2" then { d2plugin-tala = mkPackage pkgs' "d2plugin-tala"; } - else { } - ); + allPackageNames = [ "d2" "d2plugin-tala" "d2full" ]; + mkAllPackages = pkgs': + let + d2-unwrapped = pkgs'.callPackage ./pkgs/d2/d2-unwrapped.nix { }; + d2plugin-tala = pkgs'.callPackage ./pkgs/d2/d2plugin-tala.nix { }; + d2 = pkgs'.callPackage ./pkgs/d2 { + inherit d2-unwrapped d2plugin-tala; + }; + in + { + inherit d2 d2plugin-tala; + d2full = d2.override { withTala = true; }; + }; + mkApp = drv: flake-utils.lib.mkApp { inherit drv; }; mkOverlay = name: final: prev: - final.setAttrByPath [ name ] (mkPackage name prev); - - allPackageNames = [ "d2" "d2plugin-tala" ]; - mkAllPackages = pkgs': - listToAttrs - (map - (name: { inherit name; value = mkPackage pkgs' name; }) - allPackageNames); + final.filterAttrs (n: v: n == name) (mkAllPackages prev); in { overlays = (listToAttrs @@ -37,10 +39,7 @@ // flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - basePackages = mkAllPackages pkgs; - packages = with basePackages; { - d2full = d2.override { withTala = true; }; - } // basePackages; + packages = mkAllPackages pkgs; in { check = packages; diff --git a/pkgs/d2.nix b/pkgs/d2.nix deleted file mode 100644 index 5fd36d1..0000000 --- a/pkgs/d2.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ lib -, buildGoModule -, makeWrapper -, symlinkJoin -, fetchFromGitHub -, installShellFiles -, d2plugin-tala -, withTala ? false -}: - -let - version = "2022-12-12"; - d2 = buildGoModule - { - pname = "d2"; - inherit version; - - src = fetchFromGitHub { - owner = "terrastruct"; - repo = "d2"; - rev = "a557d1a6edeb18d692c1e1c20c3c0f0cffc2ed21"; - sha256 = "sha256-EzaBURGLnxSX+1FjYQLP7oxov7dGk7xhAnpV8DPzW/g="; - }; - - vendorSha256 = "sha256-p0os+ap2k5nYWI4+Hf4pwJfHTXaPJldJmf6nznhuRFA="; - - ldflags = [ - "-s" - "-w" - "-X oss.terrastruct.com/d2/lib/version.Version=${version}" - ]; - - nativeBuildInputs = [ installShellFiles ]; - - patches = [ - ../patches/d2/402_preserve_leading_comment_spacing.patch - ]; - - postInstall = "installManPage ci/release/template/man/d2.1"; - - subPackages = [ "." ]; - }; -in -symlinkJoin { - name = "d2"; - paths = [ d2 ] ++ lib.optional withTala [ d2plugin-tala ]; - buildInputs = [ makeWrapper ]; - postBuild = '' - wrapProgram $out/bin/d2 \ - --prefix PATH : "$out/bin" - ''; -} diff --git a/pkgs/d2/d2-unwrapped.nix b/pkgs/d2/d2-unwrapped.nix new file mode 100644 index 0000000..8c7a2a4 --- /dev/null +++ b/pkgs/d2/d2-unwrapped.nix @@ -0,0 +1,36 @@ +{ lib +, buildGoModule +, fetchFromGitHub +, installShellFiles +}: + +let version = "2022-12-12"; in +buildGoModule { + pname = "d2"; + inherit version; + + src = fetchFromGitHub { + owner = "terrastruct"; + repo = "d2"; + rev = "a557d1a6edeb18d692c1e1c20c3c0f0cffc2ed21"; + sha256 = "sha256-EzaBURGLnxSX+1FjYQLP7oxov7dGk7xhAnpV8DPzW/g="; + }; + + vendorSha256 = "sha256-p0os+ap2k5nYWI4+Hf4pwJfHTXaPJldJmf6nznhuRFA="; + + ldflags = [ + "-s" + "-w" + "-X oss.terrastruct.com/d2/lib/version.Version=${version}" + ]; + + nativeBuildInputs = [ installShellFiles ]; + + patches = [ + ./patches/402_preserve_leading_comment_spacing.patch + ]; + + postInstall = "installManPage ci/release/template/man/d2.1"; + + subPackages = [ "." ]; +} diff --git a/pkgs/d2plugin-tala.nix b/pkgs/d2/d2plugin-tala.nix similarity index 100% rename from pkgs/d2plugin-tala.nix rename to pkgs/d2/d2plugin-tala.nix diff --git a/pkgs/d2/default.nix b/pkgs/d2/default.nix new file mode 100644 index 0000000..7bb91d5 --- /dev/null +++ b/pkgs/d2/default.nix @@ -0,0 +1,17 @@ +{ lib +, makeWrapper +, symlinkJoin +, d2-unwrapped +, d2plugin-tala +, withTala ? false +}: + +symlinkJoin { + name = "d2"; + paths = [ d2-unwrapped ] ++ lib.optional withTala [ d2plugin-tala ]; + buildInputs = [ makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/d2 \ + --prefix PATH : "$out/bin" + ''; +} diff --git a/patches/d2/402_preserve_leading_comment_spacing.patch b/pkgs/d2/patches/402_preserve_leading_comment_spacing.patch similarity index 100% rename from patches/d2/402_preserve_leading_comment_spacing.patch rename to pkgs/d2/patches/402_preserve_leading_comment_spacing.patch