Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flake and docs #241

Merged
merged 2 commits into from
Oct 29, 2023
Merged

Update flake and docs #241

merged 2 commits into from
Oct 29, 2023

Conversation

angaz
Copy link
Contributor

@angaz angaz commented Oct 19, 2023

I've added some extra functionality to the flake to make it easier to install on NixOS, and to use within a flake project.

I also updated the docs to help someone new to flakes to include this project in their own project.

There's also a new package templ-docs, so if you are hosting the docs on a NixOS system, you can host the static files using services.nginx.

@angaz angaz force-pushed the flake branch 2 times, most recently from d2eb49a to 259a45e Compare October 22, 2023 20:21
Copy link
Owner

@a-h a-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the contribution.

The core of it is:

  • Exporting an overlay.
  • Improvements in the templ build step around setting the ldflags, CGO_ENABLED etc.
  • Including a build for the docs.
  • Including a dev shell with some tools.

On the overlay, I'm not convinced it's required, but I could be if there's a good reason. It's common to make your own anyway, e.g. https://github.com/headblockhead/dotfiles/blob/8e137383bd7bc7caf6350b2c67d92f4146e41f49/flake.nix#L62-L95

The rest is great, I'd take those, but would like to avoid the use of more libraries unless really required.

I'm happy to pick up the ideas and take it forward, or if you'd like to rework the PR, I'd also take that!

Just let me know.


To install in your Nix Flake:

This flake exposes an override, so you can add it to your own Flake.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what the point of exposing an override in a Flake is.

The docs at https://flake.parts/options/flake-parts-easyoverlay start with a warning to suggest not using an overlay, and I can use templ etc. without flake-parts, creating an overlay etc, e.g. this flake works fine with nix develop.

{
  description = "example";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
    templ.url = "github:a-h/templ";
    xc.url = "github:joerdav/xc";
  };

  outputs = { self, nixpkgs, templ, xc }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        system = system;
        pkgs = import nixpkgs {
          inherit system;
        };
      });
    in
    {
      # `nix develop` provides a shell containing required tools.
      devShell = forAllSystems
        ({ system, pkgs }:
          pkgs.mkShell {
            buildInputs = [
              pkgs.gotestsum # Alternative test runner.
              xc.packages.${system}.xc
              templ.packages.${system}.default
            ];
          });
    };
}

One of the issues with Nix tooling is having to confront the wider ecosystem of libraries etc., so I'm trying to keep the Flake as vanilla as possible.

flake.nix Outdated
};
};

devshells.default = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with devshell and why I'd want to use it. Not sure why I'd take a library for this instead of using the built-in stuff?

As per above...

      devShell = forAllSystems
        ({ system, pkgs }:
          pkgs.mkShell {
            buildInputs = [
              pkgs.gotestsum # Alternative test runner.
              xc.packages.${system}.xc
              templ.packages.${system}.default
            ];
          });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like devshell because it gives you some extra features like the ability to create commands, basically I use them as aliases to run other scripts.

It also loads much faster than the standard mkShell. I believe it has some extra caching. This is pretty important to me because I work on a lot of stuff and move around a lot, creating many terminals in the same project, so the dev shell loading quickly is big. But it is not needed, so we can revert to vanilla stuff.

flake.nix Outdated
];
};
templ-docs = pkgs.buildNpmPackage rec {
pname = "frontend";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pname = "frontend";
pname = "templ-docs";

@angaz
Copy link
Contributor Author

angaz commented Oct 23, 2023

Sure, if you don't want anything unnecessary, then I will update the PR to keep it vanilla.

@angaz
Copy link
Contributor Author

angaz commented Oct 28, 2023

I believe everything should be good to go.

@angaz
Copy link
Contributor Author

angaz commented Oct 28, 2023

I didn't see gotestsum used anywhere in the project, so I didn't include it in the devShell. Tell me if you would like me to add it.

Copy link
Owner

@a-h a-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks so much!

@a-h a-h merged commit 716517f into a-h:main Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants