-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
Conversation
d2eb49a
to
259a45e
Compare
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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
];
});
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pname = "frontend"; | |
pname = "templ-docs"; |
Sure, if you don't want anything unnecessary, then I will update the PR to keep it vanilla. |
I believe everything should be good to go. |
I didn't see |
There was a problem hiding this 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!
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 usingservices.nginx
.