-
-
Notifications
You must be signed in to change notification settings - Fork 108
Revamp nur-package-template #109
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
base: main
Are you sure you want to change the base?
Conversation
60771fe to
bfe4802
Compare
bfe4802 to
0715588
Compare
|
I'm half tempted to merge this now, but I'll wait until a week has passed. It makes nur-packages-template a lot more opinionated, which I think is probably actually a good thing. |
|
|
||
| ## README template | ||
| 3. Configure CI: Change your NUR repo name and optionally add a cachix name in | ||
| [CMakeLists.txt](./CMakeLists.txt). |
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.
Link to the correct file that is imported by ci and the templates
| [CMakeLists.txt](./CMakeLists.txt). | |
| [config.yml](./config.yml). |
| isReserved = n: n == "lib" || n == "overlays" || n == "modules"; | ||
| isDerivation = p: isAttrs p && p ? type && p.type == "derivation"; | ||
| isBuildable = p: let | ||
| licenseFromMeta = p.meta.license or []; | ||
| licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [licenseFromMeta]; | ||
| in !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList; | ||
| isBuildable = | ||
| p: | ||
| let | ||
| licenseFromMeta = p.meta.license or [ ]; | ||
| licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [ licenseFromMeta ]; | ||
| in | ||
| !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList; | ||
| isCacheable = p: !(p.preferLocalBuild or false); | ||
| shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false; | ||
|
|
||
| nameValuePair = n: v: { name = n; value = v; }; | ||
| nameValuePair = n: v: { | ||
| name = n; | ||
| value = v; | ||
| }; | ||
|
|
||
| concatMap = builtins.concatMap or (f: xs: concatLists (map f xs)); | ||
|
|
||
| flattenPkgs = s: | ||
| flattenPkgs = | ||
| s: | ||
| let | ||
| f = p: | ||
| if shouldRecurseForDerivations p then flattenPkgs p | ||
| else if isDerivation p then [ p ] | ||
| else [ ]; | ||
| f = | ||
| p: | ||
| if shouldRecurseForDerivations p then | ||
| flattenPkgs p | ||
| else if isDerivation p then | ||
| [ p ] | ||
| else | ||
| [ ]; | ||
| in | ||
| concatMap f (attrValues s); | ||
|
|
||
| outputsOf = p: map (o: p.${o}) p.outputs; |
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.
would it make sense to move these functions to lib/default.nix with the other internally used functions and add a with nurAttrs.lib;?
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 considered this. The reason I decided against it was because I didn't want people removing the functions from lib/default.nix (which is meant to be user-editable) and breaking their config. I could still be convinced otherwise but I'll keep it like this for now.
| ) | ||
| ); | ||
|
|
||
| in |
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.
add the with nurAttrs.lib; here
| isReserved = n: n == "lib" || n == "overlays" || n == "modules"; | ||
| nameValuePair = n: v: { name = n; value = v; }; | ||
| nameValuePair = n: v: { | ||
| name = n; | ||
| value = v; | ||
| }; |
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.
if we moved the other functions, then these functions will already be available using with nurAttrs.lib;, or inherit
| formatter = pkgs.treefmt.withConfig { | ||
| runtimeInputs = with pkgs; [ | ||
| nixfmt-rfc-style | ||
| black | ||
| yamlfmt | ||
| markdownlint-cli2 | ||
| ]; | ||
|
|
||
| settings = { | ||
| on-unmatched = "info"; | ||
| tree-root-file = "flake.nix"; | ||
|
|
||
| formatter = { | ||
| nixfmt = { | ||
| command = "nixfmt"; | ||
| includes = [ "*.nix" ]; | ||
| }; | ||
| black = { | ||
| command = "black"; | ||
| includes = [ "*.py" ]; | ||
| }; | ||
| yamlfmt = { | ||
| command = "yamlfmt"; | ||
| includes = [ "*.yml" ]; | ||
| }; | ||
| markdownlint = { | ||
| command = "markdownlint-cli2"; | ||
| options = [ "--fix" ]; | ||
| includes = [ "*.md" ]; | ||
| }; | ||
| }; | ||
| }; | ||
| }; |
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.
suggestion: use https://github.com/numtide/treefmt-nix
could look like
treefmt = {
programs = {
black.enable = true;
mdformat.enable = true;
nixfmt.enable = true;
yamlfmt.enable = true;
}
}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've intentionally tried to reduce the number of flake inputs here; I was until recently using numtide's treefmt module in NUR but it got removed in a recent PR.
| return yaml.safe_load(f) | ||
|
|
||
|
|
||
| def render_all_templates(src_dir=".", config_path="config.yml"): |
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.
you might want to use https://staticjinja.readthedocs.io, it's in nixpkgs
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.
Interesting, I'll check it out!
| { | ||
| stdenvNoCC, | ||
| makeWrapper, | ||
| python3, | ||
| }: | ||
|
|
||
| { | ||
| render_templates = stdenvNoCC.mkDerivation { | ||
| name = "render_templates"; | ||
|
|
||
| src = self; | ||
|
|
||
| nativeBuildInputs = [ makeWrapper ]; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
| mkdir -p $out/bin | ||
| makeWrapper ${python3.interpreter} $out/bin/render_templates \ | ||
| --add-flags "${./scripts/render_templates.py}" | ||
| runHook postInstall | ||
| ''; | ||
| }; | ||
| } |
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 tested this following the suggestion by @fgaz https://github.com/nix-community/nur-packages-template/pull/109/files#r2202868549
| { | |
| stdenvNoCC, | |
| makeWrapper, | |
| python3, | |
| }: | |
| { | |
| render_templates = stdenvNoCC.mkDerivation { | |
| name = "render_templates"; | |
| src = self; | |
| nativeBuildInputs = [ makeWrapper ]; | |
| installPhase = '' | |
| runHook preInstall | |
| mkdir -p $out/bin | |
| makeWrapper ${python3.interpreter} $out/bin/render_templates \ | |
| --add-flags "${./scripts/render_templates.py}" | |
| runHook postInstall | |
| ''; | |
| }; | |
| } | |
| { | |
| jinja2-cli, | |
| writeShellScriptBin, | |
| }: | |
| { | |
| render_templates = writeShellScriptBin "render_templates" '' | |
| find . -name "*.j2" -print0 | while read -d $'\0' file; do | |
| ${jinja2-cli}/bin/jinja2 "$file" config.yml --format=yml > "''${file%.j2}" | |
| done | |
| ''; | |
| } |
| strategy: | ||
| matrix: | ||
| # Set this to notify the global nur package registry that changes are | ||
| # available. | ||
| # | ||
| # The repo name as used in | ||
| # https://github.com/nix-community/NUR/blob/master/repos.json | ||
| nurRepo: | ||
| - <YOUR_REPO_NAME> | ||
| # Set this to cache your build results in cachix for faster builds | ||
| # in CI and for everyone who uses your cache. | ||
| # | ||
| # Format: Your cachix cache host name without the ".cachix.org" suffix. | ||
| # Example: mycache (for mycache.cachix.org) | ||
| # | ||
| # For this to work, you also need to set the CACHIX_SIGNING_KEY or | ||
| # CACHIX_AUTH_TOKEN secret in your repository secrets settings in | ||
| # Github found at | ||
| # https://github.com/<your_githubname>/nur-packages/settings/secrets | ||
| cachixName: | ||
| - <YOUR_CACHIX_NAME> | ||
| nixPath: | ||
| - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz | ||
| - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz | ||
| - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-25.05.tar.gz | ||
| runs-on: ubuntu-latest |
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.
To help nix-darwin users, I wish the runs-on value could be defined with the nixPath.
See what I've done in my nur-packages repository: https://github.com/anttiharju/nur-packages/blob/09429286cd108e174d0065a74404cd8d78a3c747/.github/workflows/build.yml#L13-L24
strategy:
matrix:
include:
- nixPath: nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz
runner: ubuntu-latest
- nixPath: nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz
runner: ubuntu-latest
- nixPath: nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-25.11.tar.gz
runner: ubuntu-latest
- nixPath: nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-25.11-darwin.tar.gz
runner: macos-26
runs-on: ${{ matrix.runner }}I think it would be fair to leave macos-latest entry commented out by default because macOS runners are fairly expensive, but making it easy to toggle on would be much appreciated by nix-darwin users I think 🙏
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.
Happy to submit a separate PR though, this one appears to have been inactive since Jul 17
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.
It must have fell off my TODO. I'll see about getting this done.
Fixes #88
Fixes #89
Fixes #96
TODO:
lib.fixin lib, pass calculated packages to overlay (somehow?) and moduleci.nix