-
Notifications
You must be signed in to change notification settings - Fork 201
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
Draft: Add Nix flake, use flake-parts module #1705
Conversation
I wonder if this will help us with #1706 |
I don't have a qualified enough opinion about flake.parts itself, other than that I briefly tested Only running On the other hand, we should maybe consider what to do with breaking changes in IHP here as it will be easy to skip the upgrade guide, and potentially not know what IHP version you are running.
Lots of good points here that should probably separate Github issues to not derail the core discussion here 👍 |
Good point. The smoothest approach to that problem would probably be the one nixpkgs takes: release branches. E.g. you would specify Would require maintaining such branches here in the repo, but that shouldn't be much work.
Yes, absolutely, I only included the "future" part in here to tease some of the stuff we'll be able to do with flakes etc., I'll definitely open separate issues and PRs for that stuff. |
really like the release branches idea 👍 |
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 like this is mostly ready to merge, good job 👍
Does it make sense to already adjust the documentation inside this PR? Especially things in https://github.com/digitallyinduced/ihp/blob/master/Guide/package-management.markdown and the UPGRADE.md
flake-module.nix
Outdated
|
||
# Set optimized = true to get more optimized binaries, but slower build times | ||
# TODO make configurable via option | ||
optimized = false; |
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.
The old Make system has two targets to archive this:
make build/bin/RunOptimizedProdServer # Slow build, optimized binary
make build/bin/RunUnoptimizedProdServer # Fast build, no optimizations
Can we do something similiar here? Like two output binaries in our flake, so the end user can decide to get either an optimized or unoptimized build?
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.
Makes sense, we should be able to provide two flake outputs for optimized/unoptimized builds, so you can build them with something like nix build .#optimizedServer
or nix build .#unoptimizedServer
and additionally provide an optional option that controls what is built as default package, i.e. what's build with a plain nix build
. I'll figure something out.
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.
Okay, there are now separate output packages for the optimized and unoptimized prod servers, build them with nix build .#optimized-prod-server
or nix build .#unoptimized-prod-server
. The default package built by nix build
is the unoptimized one. I've decided to leave out an additional config option for that for now, I think that would probably only confuse people, but I can still add it.
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.
Great thanks 👍
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.
We should likely add these nix build commands to the documentation later on
Sounds good, will do! |
Any updates? |
Sorry for the delay, my plan is currently to wait with writing documentation for this until we figure out what the cause of #1714 is and know what changes in our devenv/flake stuff we need to fix it |
I've updated the package management and upgrade documentation accordingly. |
as we can use .follows now
I've removed the devenv installation from UPGRADE.md, as the flake module pulls in devenv automatically via direnv / |
@Eisfunke can you also fix the failing github actions? Besides that it looks ready to merge 👍 |
devenv implements and internally uses various features from Nix flakes and flake.parts, but hides a lot of that stuff to keep things easier for beginners. However, for a project like IHP I believe we can get a lot of advantages by using Nix flakes and flake-parts directly, as we don't just need the development environment, but a lot more. E.g. the devenv docs say:
"Using devenv configuration in flakes is useful for projects that need to define other Nix flake features in addition to the development shell. Additional flake features may include the Nix package for the project or NixOS and Home Manager modules related to the project. Using the same lock file for the development shell and other features ensures that everything is based on the same nixpkgs."
I'd be happy about any feedback about this PR and the approach!
Summary
This is still a WIP draft, but should be enough to see what I'm going for.
For simplicity, I also describe the changes from digitallyinduced/ihp-boilerplate#25 here, as they complement each other.
flake-module.nix
providing options for IHP, which is what would be imported by individual IHP apps, see my changes to ihp-boilerplate in: TODONixSupport/devenv.nix
and inflake.nix
on the app side in the ihp-boilerplate repo.devenv.yaml
is now replaced by the inputs section offlake.nix
. There's no need for a devenv.lock anymore, we have a flake.lock now instead.nix flake init
.devenv.nix
is now indevenv-module.nix
used byflake.nix
to provide a devShell for IHP itself.A thing I noticed:
RunDevServer
uses nix-shell, which uses default.nix in the boilerplate, which in turn uses flake-compat, which in turn usesdefaultPackage
/packages.default
from the flake. And that's currently set to be the release build, which I copied over from the previous boilerplate code. Is it intended like that?Advantages
Some advantages of this approach using flakes:
nix flake update
to get those improvements, instead of individually patching their local flakes. New features could also be configured by adding options in the module without breaking backward compatiblity.nix develop
to enter the devShell (or use direnv, but that's optional), then devenv is available and you candevenv up
to run the devserver.Future
In the future, I would also like to add and refactor some stuff in IHP to use a more flake-centric approach based on this as a start. For example:
--impure
builds for better cache-ability, better reproducibility and easier deployments e.g. with Shipnixbuild/ihp-lib
, I'd like to stream some of thatRunDevServer
still uses the legacydefault.nix
through flake-compat, it should use the flake directly instead