NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.46k stars 12.95k forks source link

Package request: daisyui #247043

Open srid opened 11 months ago

srid commented 11 months ago

Project description

daisyui is a component library for tailwindcss

Metadata

srid commented 11 months ago

Where this package can be used? As a tailwind plugin, viz.:

pkgs.nodePackages.tailwindcss.overrideAttrs
  (oa: {
    plugins = [
      pkgs.nodePackages."@tailwindcss/aspect-ratio"
      pkgs.nodePackages."@tailwindcss/forms"
      pkgs.nodePackages."@tailwindcss/language-server"
      pkgs.nodePackages."@tailwindcss/line-clamp"
      pkgs.nodePackages."@tailwindcss/typography"
    ];
  })
srid commented 11 months ago

Upstream repo has no package-lock.json (https://github.com/saadeghi/daisyui/discussions/2217) so I suppose we would have to maintain one, and use that in postPatch. Are there other ways?

grantshandy commented 6 months ago

@srid - did you ever find a way to use daisyui w/ tailwindcss?

osmano807 commented 4 months ago

I resorted to generating a lockfile with

npm i --package-lock-only

and creating a daisyui package inside my project flake.nix using a random nixpkgs package as basis, overriding tailwindcss like above.

Something like this:

packages.tailwindCss = pkgs.nodePackages.tailwindcss.overrideAttrs (oa: {
          plugins = [
            pkgs.nodePackages."@tailwindcss/aspect-ratio"
            pkgs.nodePackages."@tailwindcss/forms"
            pkgs.nodePackages."@tailwindcss/language-server"
            pkgs.nodePackages."@tailwindcss/line-clamp"
            pkgs.nodePackages."@tailwindcss/typography"
            self'.packages.daisyui
          ];
        });

 packages.daisyui = pkgs.buildNpmPackage rec {
          pname = "daisyui";
          version = "4.6.3";

          src = pkgs.fetchFromGitHub {
            owner = "saadeghi";
            repo = pname;
            rev = "v${version}";
            hash = "sha256-O1YZF2mMNWnoj6sRrbQKJBTqlQ+NIcpZf0kawDDeVxM=";
          };

          npmDepsHash = "sha256-hbcgdk4Q9pf/Pif/zVyxEtYUspKhYkd8OUi73LG88nw=";

          # use generated package-lock.json as upstream does not provide one
          postPatch = ''
            cp ${./daisyui-package-lock.json} ./package-lock.json
          '';

          # The prepack script runs the build script, which we'd rather do in the build phase.
          npmPackFlags = ["--ignore-scripts"];

          NODE_OPTIONS = "--openssl-legacy-provider";

          meta = with lib; {
            description = "A free and open-source Tailwind CSS component library ";
            homepage = "https://daisyui.com/";
            license = licenses.mit;
          };
        };

And using self'.packages.tailwindCss as a nativeBuildInputs for mkShell

larstvei commented 3 months ago

I followed these steps, without any problems:

https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#adding-and-updating-javascript-packages-in-nixpkgs-javascript-adding-or-updating-packages

I can try opening a PR.

osmano807 commented 3 months ago

@larstvei Try my pull request

As explained in the pull request, don't know the feasibility of this package in the nixpkgs repo, maybe we should put all npm or web development packages in another repo. For example, I'm maintaining private packages of prettier-plugin-jinja-template and prettier-plugin-tailwindcss, with a patched prettier package to add the node_modules to it similar to the nixpkgs tailwindcss definition. Nevertheless, I can't make VSCode tailwindcss-intellisense work as it needs a project node_modules, and I'm not too inclined to hack a nix derivation to add all those packages node_modules right now.

This web world have a serious dependency management problem...

larstvei commented 3 months ago

Nice, that worked well for as well. I didn't know using nodePackages was discouraged when I added the PR 😅