Skip to content

Conversation

@Pandapip1
Copy link
Member

@Pandapip1 Pandapip1 commented Jul 7, 2025

Fixes #88

Fixes #89

Fixes #96

TODO:

  • Actual revamp
  • Linting
  • Configuration in its own file, templates where config can't be read at runtime
  • Example package
  • Example overlay
  • Example module
  • (Maybe) upstream the new stuff to lib
  • (Maybe) use lib.fix in lib, pass calculated packages to overlay (somehow?) and module
  • (Maybe) Redo check-meta: Expose checkValidity and add to all-packages NixOS/nixpkgs#339597, can be used to get rid of most of ci.nix
  • (Maybe) First-time configuration script
  • (Maybe) Move maintainers scripts out of the flake (and exclude from NUR, somehow?)

@Pandapip1 Pandapip1 force-pushed the flake-parts-revamp branch 2 times, most recently from 60771fe to bfe4802 Compare July 7, 2025 20:00
@Pandapip1 Pandapip1 force-pushed the flake-parts-revamp branch from bfe4802 to 0715588 Compare July 7, 2025 20:21
@Pandapip1 Pandapip1 marked this pull request as ready for review July 7, 2025 21:25
@Pandapip1
Copy link
Member Author

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).
Copy link

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

Suggested change
[CMakeLists.txt](./CMakeLists.txt).
[config.yml](./config.yml).

Comment on lines 18 to 51
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;
Copy link

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;?

Copy link
Member Author

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
Copy link

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

Comment on lines 7 to +11
isReserved = n: n == "lib" || n == "overlays" || n == "modules";
nameValuePair = n: v: { name = n; value = v; };
nameValuePair = n: v: {
name = n;
value = v;
};
Copy link

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

Comment on lines +60 to +92
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" ];
};
};
};
};
Copy link

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;
  }
}

Copy link
Member Author

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"):
Copy link
Collaborator

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

Copy link
Member Author

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!

Comment on lines +1 to +25
{
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
'';
};
}
Copy link

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

Suggested change
{
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
'';
}

Comment on lines 16 to 22
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

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 🙏

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

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copyright notice modification in repositories based on this template don't re-import nixpkgs for no reason Use by-name

5 participants