diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..529c034 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @drupol diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..4ef201c --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,75 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, nationality, personal appearance, race, religion, or sexual identity +and orientation. + +## Our Standards + +Examples of behaviour that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behaviour by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behaviour and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behaviour. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviours that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behaviour may be +reported by contacting the project team at pol.dellaiera@protonmail.com. The +project team will review and investigate all complaints, and will respond in a +way that it deems appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an +incident. Further details of specific enforcement policies may be posted +separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..acdfc6a --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,6 @@ +# CONTRIBUTING + +We're using [GitHub Actions](https://docs.github.com/en/actions) as a continuous +integration system. + +For details, see the workflows in [.github/workflows](../.github/workflows). diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b4c89d9 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: drupol diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1f95f4b --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,13 @@ +## Steps required to reproduce the problem + +1. +2. +3. + +## Expected Result + +- + +## Actual Result + +- diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..b92faa6 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,10 @@ +This PR: + +- [ ] Fix ... +- [ ] Provide ... +- [ ] It breaks backward compatibility +- [ ] Is covered by tests +- [ ] Has documentation +- [ ] Is an experimental thing + +Follows #. Related to #. Fixes #. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..70181ab --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: monthly + open-pull-requests-limit: 10 diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..ef73884 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,55 @@ +# https://github.com/probot/settings + +branches: + - name: main + protection: + enforce_admins: false + required_pull_request_reviews: + dismiss_stale_reviews: true + require_code_owner_reviews: true + required_approving_review_count: 1 + restrictions: null + required_linear_history: true + +labels: + - name: backward breaking change + color: ff0000 + + - name: bug + color: ee0701 + + - name: dependencies + color: 0366d6 + + - name: enhancement + color: 0e8a16 + + - name: experimentation + color: eeeeee + + - name: question + color: cc317c + + - name: new feature + color: 0e8a16 + + - name: security + color: ee0701 + + - name: stale + color: eeeeee + +repository: + allow_merge_commit: true + allow_rebase_merge: true + allow_squash_merge: true + default_branch: master + description: "A template for maintaining your own Nix expressions in your own repository" + topics: nix + has_downloads: false + has_issues: true + has_pages: false + has_projects: false + has_wiki: false + name: my-own-nixpkgs + private: false diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..150e723 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,9 @@ +daysUntilStale: 60 + +daysUntilClose: 7 + +staleLabel: stale + +markComment: > + This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no + further activity occurs. Thank you for your contributions. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..379cc85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +./result +./direnv diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e52c177 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2024 Pol Dellaiera + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..20f4c52 --- /dev/null +++ b/README.md @@ -0,0 +1,99 @@ +[![Donate!][donate github]][github sponsors link] + +# My Custom Nixpkgs Overlay + +This project provides templates for creating your own collection of custom +Nix expressions, similar to what is done in [`nixpkgs`]. It includes a `default` +[overlay](https://wiki.nixos.org/wiki/Overlays) that exposes all custom +packages, facilitating their integration into other projects. + +While this custom repository provides a platform for developing, integrating and +sharing your own packages, we encourage contributors to also consider submitting +their packages directly to the official [`nixpkgs`] repository. Contributing to +`nixpkgs` helps to enrich the broader Nix community by making your work +available to a wider audience and benefiting from the collective expertise of +Nix developers. However, maintaining your own repository can be advantageous for +experimental, personal, or organization-specific packages that require specific +configurations or are not yet ready for broader adoption. + +## Usage + +### Setting Up Your Own Repository + +1. Use the `my-own-nixpkgs` template `nix flake new --template git+https://github.com/drupol/my-own-nixpkgs#my-own-nixpkgs ./my-repo` as a starting point +2. Begin adding packages to the `pkgs/by-name` directory. Follow the + same approach as adding packages in `nixpkgs` (similar to [RFC140]). Packages + added in this directory will be automatically discovered. + - Create a new directory for each package. + - Inside each directory, create a `package.nix` file. +3. Optionally, you can add packages directly to the `pkgs/` directory and + manually update the bindings in the `imports/pkgs-all.nix` file. + +### Using Your Own Repository + +Use the `client` template `nix flake new --template git+https://github.com/drupol/my-own-nixpkgs#client ./my-nix-project` as a starting point or follow the manual steps hereunder. + +To use this repository as an overlay in another project, follow these steps: + +1. **Add the Repository as an Input**: + + Add the following to your `nix` file to include this repository as an input: + + ```nix + inputs = { + my-custom-nixpkgs.url = "repo-url"; # Replace "repo-url" with the actual URL to your repository + }; + ``` + +2. **Include the Overlay in `pkgs`**: + + When constructing `pkgs`, include the overlay as follows: + + ```nix + pkgs = import inputs.nixpkgs { + overlays = [ + inputs.my-custom-nixpkgs.overlays.default + ]; + }; + ``` + +3. **Use Your Packages**: + + Access the packages in your project like this: + + ```nix + buildInputs = [ pkgs.example1 pkgs.example2 ]; + ``` + +[RFC140]: https://github.com/NixOS/rfcs/pull/140 + +### Examples + +Refer to the dummy projects `example1` and `example2` for practical examples of +how packages can be structured. + +## Going further + +- Use the continuous integration service of your choice to build and test your + packages +- Add a binary cache to your repository to speed up builds and avoid + recompilation using [Cachix](https://cachix.org/) +- This project uses a flake framework, we recommend to use [flake-parts](https://flake.parts) + +## Contributing + +Feel free to contribute by sending pull requests. We are a usually very +responsive team and we will help you going through your pull request from the +beginning to the end. + +For some reasons, if you can't contribute to the code and willing to help, +sponsoring is a good, sound and safe way to show us some gratitude for the hours +we invested in this package. + +Sponsor me on [Github][github sponsors link] and/or any of [the +contributors][6]. + +[donate github]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square +[github sponsors link]: https://github.com/sponsors/drupol +[6]: https://github.com/drupol/my-own-nixpkgs/graphs/contributors +[`nixpkgs`]: https://github.com/NixOS/nixpkgs diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4a6473a --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "Nix templates for building your own nixpkgs repository and use it"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = + inputs@{ flake-parts, systems, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + + imports = [ + ./imports/formatter.nix + ./imports/templates.nix + ]; + }; +} diff --git a/imports/formatter.nix b/imports/formatter.nix new file mode 100644 index 0000000..3793bca --- /dev/null +++ b/imports/formatter.nix @@ -0,0 +1,17 @@ +{ inputs, ... }: + +{ + perSystem = + { + config, + self', + inputs', + pkgs, + system, + lib, + ... + }: + { + formatter = pkgs.nixfmt-rfc-style; + }; +} diff --git a/imports/templates.nix b/imports/templates.nix new file mode 100644 index 0000000..42f2530 --- /dev/null +++ b/imports/templates.nix @@ -0,0 +1,17 @@ +{ ... }: +{ + flake = { + templates = { + client = { + path = ../templates/client; + description = "A basic 'client' template for getting started using your own nixpkgs repository."; + welcomeText = builtins.readFile ../templates/client/README.md; + }; + my-own-nixpkgs = { + path = ../templates/my-own-nixpkgs; + description = "A basic custom nixpkgs repository for maintaining and promoting your own Nix expressions and packages."; + welcomeText = builtins.readFile ../templates/my-own-nixpkgs/README.md; + }; + }; + }; +} diff --git a/templates/client/README.md b/templates/client/README.md new file mode 100644 index 0000000..bc736ee --- /dev/null +++ b/templates/client/README.md @@ -0,0 +1,21 @@ +# My Custom Nixpkgs Overlay + +This project uses [flake-parts](https://flake.parts), a flake framework to +manage Nix expressions and to some extent, packages. + +## Contributing + +Feel free to contribute by sending pull requests. We are a usually very +responsive team and we will help you going through your pull request from the +beginning to the end. + +For some reasons, if you can't contribute to the code and willing to help, +sponsoring is a good, sound and safe way to show us some gratitude for the hours +we invested in this package. + +Sponsor me on [Github][github sponsors link] and/or any of [the +contributors][6]. + +[donate github]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square +[github sponsors link]: https://github.com/sponsors/drupol +[6]: https://github.com/drupol/my-own-nixpkgs/graphs/contributors diff --git a/templates/client/flake.nix b/templates/client/flake.nix new file mode 100644 index 0000000..92a17e0 --- /dev/null +++ b/templates/client/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + my-own-nixpkgs.url = "github:drupol/my-own-nixpkgs"; + }; + + outputs = + inputs@{ flake-parts, systems, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + + imports = [ ./imports/overlay.nix ]; + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + devShells.default = pkgs.mkShellNoCC { + name = "default"; + packages = [ + pkgs.example1 + pkgs.example2 + ]; + }; + }; + }; +} diff --git a/templates/client/imports/devShells.nix b/templates/client/imports/devShells.nix new file mode 100644 index 0000000..a1379c2 --- /dev/null +++ b/templates/client/imports/devShells.nix @@ -0,0 +1,22 @@ +{ ... }: +{ + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + devShells.default = pkgs.mkShell { + name = "default"; + packages = [ + pkgs.example1 + pkgs.example2 + ]; + }; + }; +} diff --git a/templates/client/imports/overlay.nix b/templates/client/imports/overlay.nix new file mode 100644 index 0000000..d915ee2 --- /dev/null +++ b/templates/client/imports/overlay.nix @@ -0,0 +1,20 @@ +{ inputs, ... }: + +{ + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ inputs.my-own-nixpkgs.overlays.default ]; + config = { }; + }; + }; +} diff --git a/templates/my-own-nixpkgs/README.md b/templates/my-own-nixpkgs/README.md new file mode 100644 index 0000000..434c9d7 --- /dev/null +++ b/templates/my-own-nixpkgs/README.md @@ -0,0 +1,87 @@ +[![Donate!][donate github]][github sponsors link] + +# My Custom Nixpkgs Overlay + +This repository serves as a template for creating your own collection of custom +Nix expressions, akin to what is done in `nixpkgs`. It includes a `default` +overlay that exposes all custom packages, facilitating their integration into +other projects. + +## Usage + +### Setting Up + +1. Fork this repository. +2. Begin adding packages to the `pkgs/by-name` directory. Follow the + same approach as adding packages in `nixpkgs`. Similar to [RFC140], packages + added in this directory will be automatically discovered. + - Create a new directory for each package. + - Inside each directory, create a `package.nix` file. +3. Optionally, you can add packages directly to the `pkgs/` directory and + manually update the bindings in the `imports/pkgs-all.nix` file. + +### Integrating Your Repository as an Overlay + +To use this repository as an overlay in another project, follow these steps: + +1. **Add the Repository as an Input**: + + Add the following to your `nix` file to include this repository as an input: + + ```nix + inputs = { + my-custom-nixpkgs.url = "repo-url"; # Replace "repo-url" with the actual URL to your repository + }; + ``` + +2. **Include the Overlay in `pkgs`**: + + When constructing `pkgs`, include the overlay as follows: + + ```nix + pkgs = import inputs.nixpkgs { + overlays = [ + inputs.my-custom-nixpkgs.overlays.default + ]; + }; + ``` + +3. **Use Your Packages**: + + Access the packages in your project like this: + + ```nix + buildInputs = [ pkgs.example1 pkgs.example2 ]; + ``` + +[RFC140]: https://github.com/NixOS/rfcs/pull/140 + +### Examples + +Refer to the dummy projects `example1` and `example2` for practical examples of +how packages can be structured. + +## Going further + +- Use the continuous integration service of your choice to build and test your + packages +- Add a binary cache to your repository to speed up builds and avoid + recompilation using [Cachix](https://cachix.org/) +- This project uses a flake framework, we recommend to use [flake-parts](https://flake.parts) + +## Contributing + +Feel free to contribute by sending pull requests. We are a usually very +responsive team and we will help you going through your pull request from the +beginning to the end. + +For some reasons, if you can't contribute to the code and willing to help, +sponsoring is a good, sound and safe way to show us some gratitude for the hours +we invested in this package. + +Sponsor me on [Github][github sponsors link] and/or any of [the +contributors][6]. + +[donate github]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square +[github sponsors link]: https://github.com/sponsors/drupol +[6]: https://github.com/drupol/my-own-nixpkgs/graphs/contributors diff --git a/templates/my-own-nixpkgs/flake.nix b/templates/my-own-nixpkgs/flake.nix new file mode 100644 index 0000000..1afddda --- /dev/null +++ b/templates/my-own-nixpkgs/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = + inputs@{ flake-parts, systems, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + + imports = [ + inputs.flake-parts.flakeModules.easyOverlay + ./imports/overlay.nix + ./imports/formatter.nix + ./imports/pkgs-by-name.nix + ./imports/pkgs-all.nix + ]; + }; +} diff --git a/templates/my-own-nixpkgs/imports/formatter.nix b/templates/my-own-nixpkgs/imports/formatter.nix new file mode 100644 index 0000000..3793bca --- /dev/null +++ b/templates/my-own-nixpkgs/imports/formatter.nix @@ -0,0 +1,17 @@ +{ inputs, ... }: + +{ + perSystem = + { + config, + self', + inputs', + pkgs, + system, + lib, + ... + }: + { + formatter = pkgs.nixfmt-rfc-style; + }; +} diff --git a/templates/my-own-nixpkgs/imports/overlay.nix b/templates/my-own-nixpkgs/imports/overlay.nix new file mode 100644 index 0000000..0eff119 --- /dev/null +++ b/templates/my-own-nixpkgs/imports/overlay.nix @@ -0,0 +1,22 @@ +{ inputs, ... }: + +{ + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ inputs.self.overlays.default ]; + config = { }; + }; + + overlayAttrs = config.packages; + }; +} diff --git a/templates/my-own-nixpkgs/imports/pkgs-all.nix b/templates/my-own-nixpkgs/imports/pkgs-all.nix new file mode 100644 index 0000000..138c64f --- /dev/null +++ b/templates/my-own-nixpkgs/imports/pkgs-all.nix @@ -0,0 +1,18 @@ +{ inputs, lib, ... }: +{ + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + packages = { + example2 = pkgs.callPackage ../pkgs/example2 { }; + }; + }; +} diff --git a/templates/my-own-nixpkgs/imports/pkgs-by-name.nix b/templates/my-own-nixpkgs/imports/pkgs-by-name.nix new file mode 100644 index 0000000..db99256 --- /dev/null +++ b/templates/my-own-nixpkgs/imports/pkgs-by-name.nix @@ -0,0 +1,25 @@ +{ inputs, lib, ... }: +{ + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + packages = + let + scope = lib.makeScope pkgs.newScope (self: { + inherit inputs; + }); + in + lib.filesystem.packagesFromDirectoryRecursive { + inherit (scope) callPackage; + directory = ../pkgs/by-name; + }; + }; +} diff --git a/templates/my-own-nixpkgs/pkgs/by-name/example1/package.nix b/templates/my-own-nixpkgs/pkgs/by-name/example1/package.nix new file mode 100644 index 0000000..63ff51f --- /dev/null +++ b/templates/my-own-nixpkgs/pkgs/by-name/example1/package.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +pkgs.writeShellApplication { + name = "example1-script"; + text = '' + echo "Hello, world!" + ''; +} diff --git a/templates/my-own-nixpkgs/pkgs/example2/default.nix b/templates/my-own-nixpkgs/pkgs/example2/default.nix new file mode 100644 index 0000000..b527da8 --- /dev/null +++ b/templates/my-own-nixpkgs/pkgs/example2/default.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +pkgs.writeShellApplication { + name = "example2-script"; + text = '' + echo "Hello, world!" + ''; +}