Skip to content
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

Add variants #3

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/flakehub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Publish every Git push to master to FlakeHub"
on:
push:
branches:
- "main"
jobs:
flakehub-publish:
runs-on: "ubuntu-latest"
permissions:
id-token: "write"
contents: "read"
steps:
- uses: "actions/checkout@v3"
- uses: "DeterminateSystems/nix-installer-action@main"
- uses: "DeterminateSystems/flakehub-push@main"
with:
name: "tsandrini/practical-flakes-template"
rolling: true
visibility: "public"
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ And you're good to go! 👍
3. [treefmt](https://github.com/numtide/treefmt) is the one and only formatter
to rule them all 🙏
4. Already preconfigured [github actions](https://docs.github.com/en/actions)
and [gitlab CI](ttps://docs.gitlab.com/ee/ci/) 💪
and [gitlab CI](https://docs.gitlab.com/ee/ci/) 💪
5. Prepared for custom `lib` overrides 🤓
- depending on what you're currently aiming to write, you might need some
custom helpers or library functions, this template
Expand All @@ -43,12 +43,49 @@ After a proper installation process you can enter the development environment
1. either using [direnv](https://github.com/direnv/direnv) `direnv allow`
2. or directly `nix develop .#dev --impure`

While not many, the code has some required references to the `practicalFlake`
While not many, the code has some required references to the `practicalFlakes`
identifier. This can be renamed in the whole project using the script
`rename-project` (which is available in the dev environment)

```bash
rename-project . myAwesomeApp
```

## Resources
You're also encouraged to update your flakes with

```bash
nix flake update
```

## Variants

There are also a few other different variants of the base template that may
be better suited for your needs

- **main**: The main, default template.
- **home**: Conceptually and structurally the same as the default template, but
also includes prepared and preconfigured
[home-manager](https://github.com/nix-community/home-manager) as well as
examples of how to use it
- **minimal**: Structurally the same as the default template, but stripped of all
of the included examples and additional prepared files
- **isolated**: Centralizes all of the nix related stuff into a `nix/` folder.
This can be useful when you'd like to not pollute your root with stuff not
directly tied to the code.
- **isolated-minimal**: Isolated combined with minimal, that is, structurally the
same as minimal, however, stripped out of all the examples and unnecessary code

You can install your desired template variant using

```bash
nix flake init -t github:tsandrini/practical-flakes-template#myVariant
```

For example,
`nix flake init -t github:tsandrini/practical-flakes-template#isolated-minimal`.

## Notes

- `pkgs` are by default enabled to allow **unfree** licenses, if you'd prefer not
to have this enabled, simply remove the line in the `lib/modules.nix:mkNixpkgs`
helper function
52 changes: 41 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
description = "PracticalFlakesTemplate - Highly opinionated nix flakes starter template that focuses on modularity.";

inputs = {
# Base dependencies
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";

# dev and formatting
# Development
treefmt-nix.url = "github:numtide/treefmt-nix";
devenv.url = "github:cachix/devenv";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
Expand All @@ -22,20 +23,49 @@
systems = import inputs.systems;

flake = {
templates = {
templates = let
welcomeText = ''
Hi! You've just created a fresh new flakes project using the
practical-flakes-template. You can start by looking around or
running the development environment either via direnv (`direnv allow`)
or `nix develop .#dev --impure`.

Furthermore don't forget to rename your project using
`rename-project . myAwesomeNewProject`

For more info refer to
https://github.com/tsandrini/practical-flakes-template/
'';
in {
default = inputs.self.templates.main;
main = {
inherit welcomeText;
path = ./templates/main;
description = "Highly opinionated nix flakes starter template that focuses on modularity.";
welcomeText = ''
Hi! You've just created a fresh new flakes project using the
practical-flakes-template. You can start by looking around or
running the development environment either via direnv (`direnv allow`)
or `nix develop .#dev --impure`.

For more info refer to
https://github.com/tsandrini/practical-flakes-template/
'';
};

minimal = {
inherit welcomeText;
path = ./templates/minimal;
description = "Minimal version of the highly opiniated nix flakes starter template.";
};

isolated = {
inherit welcomeText;
path = ./templates/isolated;
description = "Isolated (./nix) version of the highly opiniated nix flakes starter template.";
};

isolated-minimal = {
inherit welcomeText;
path = ./templates/isolated-minimal;
description = "Isolated (./nix) and minimal version of the highly opiniated nix flakes starter template.";
};

home = {
inherit welcomeText;
path = ./templates/home;
description = "Full version of the highly opiniated nix flakes starter template that includes prewired home-manager";
};
};
};
Expand Down
8 changes: 8 additions & 0 deletions templates/home/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

if ! use flake .#dev --impure
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
20 changes: 20 additions & 0 deletions templates/home/.github/workflows/check-on-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Run various checks on merge (pull) request"

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4

- name: Complete nix setup
uses: DeterminateSystems/nix-installer-action@main

- name: pre-commit checks
run: nix develop .#dev --impure --command bash -c "pre-commit run --all-files"

- name: Check the flake
run: nix develop .#dev --impure --command bash -c "nix flake check --impure --show-trace"
28 changes: 28 additions & 0 deletions templates/home/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# OS generated files #
######################
.DS_Store
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db

# IDEA Ignores #
################
*.iml
*.ipr
*.iws
.idea/
out/
local.properties

# Project related #
################
result/
build/

result
.direnv/
.devenv/

.devcontainer.json
.pre-commit-config.yaml
14 changes: 14 additions & 0 deletions templates/home/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: nixos/nix:latest

variables:
NIX_CONF_DIR: "/etc/nix"

before_script:
- echo 'experimental-features = nix-command flakes' > $NIX_CONF_DIR/nix.conf

check:
script:
- nix develop .#dev --impure --command bash -c "pre-commit run --all-files"
- nix develop .#dev --impure --command bash -c "nix flake check --impure --show-trace"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
1 change: 1 addition & 0 deletions templates/home/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
16 changes: 16 additions & 0 deletions templates/home/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# practicalFlakes

## Description

This flake has been generated from the
[tsandrini/practical-flakes-template](https://github.com/tsandrini/practical-flakes-template/)
project. The next steps for your development are

1. **development environment**
- either use [direnv](https://github.com/direnv/direnv) and `direnv allow`
- or explicitly enter the shell via `nix develop .#dev --impure`
2. **rename the project**
- while not many, there are some places in the code that have a `practicalFlakes`
identifier, you can use the `rename-project` (available in the dev environment)
script to change these
- `rename-project . myCoolNewProject`
Loading