diff --git a/.envrc b/.envrc deleted file mode 100644 index a93dec4..0000000 --- a/.envrc +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" -fi -use flake diff --git a/.envrc b/.envrc new file mode 120000 index 0000000..0b67630 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +template/.envrc \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa28ad5..fc9a130 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ concurrency: cancel-in-progress: true jobs: DeterminateCI: - uses: DeterminateSystems/ci/.github/workflows/workflow.yml@main + uses: dataheld/ci/.github/workflows/workflow.yml@pass-thru-failearly permissions: id-token: "write" contents: "read" diff --git a/README.md b/README.md index 79728a0..a17368d 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,28 @@ extra-[DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) 🤌 ## Installing > \[!NOTE\] +> This is not another flake or development framework. +> It is much less; just the set of composable nix flakes and modules that I use for my projects. + +> \[!TIP\] > This is the software you need to have on your _system_. > All project-specific software is handled automatically. 1. Install Nix (the package manager). The [Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer) is recommended. + 1. Install [direnv](https://direnv.net). + 1. (optional) Install [nix-direnv](https://github.com/nix-community/nix-direnv) for better performance during development. -1. (if not already done) Clone the repo + +1. Add the necessary boilerplate files. + + ```sh + nix flake init --template "https://flakehub.com/f/dataheld/nullkomma/0.1.*#default" + ``` + 1. (one-time only) Inside the repo, run `direnv allow` > \[!TIP\] diff --git a/flake.lock b/flake.lock index b815689..7dac35d 100644 --- a/flake.lock +++ b/flake.lock @@ -158,7 +158,9 @@ }, "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1741352980, @@ -241,35 +243,66 @@ "url": "https://flakehub.com/f/nix-community/naersk/0.1.%2A" } }, - "nixpkgs": { + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nix-unit", + "nixpkgs" + ] + }, "locked": { - "lastModified": 1739758141, - "narHash": "sha256-uq6A2L7o1/tR6VfmYhZWoVAwb3gTy7j4Jx30MIrH0rE=", - "rev": "c618e28f70257593de75a7044438efc1c1fc0791", - "revCount": 714614, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2411.714614%2Brev-c618e28f70257593de75a7044438efc1c1fc0791/0195155d-20df-7b25-ad70-45871483b8d2/source.tar.gz" + "lastModified": 1731952509, + "narHash": "sha256-p4gB3Rhw8R6Ak4eMl8pqjCPOLCZRqaehZxdZ/mbFClM=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "7b5f051df789b6b20d259924d349a9ba3319b226", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2411.%2A.tar.gz" + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" } }, - "nixpkgs-lib": { + "nix-unit": { + "inputs": { + "flake-parts": [ + "flake-parts" + ], + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, "locked": { - "lastModified": 1740877520, - "narHash": "sha256-oiwv/ZK/2FhGxrCkQkB83i7GnWXPPLzoqFHpDD3uYpk=", + "lastModified": 1741624954, + "narHash": "sha256-VjLS010BEfwuK343Dst08NnQNS8SRtVCDkz1zTsHuvI=", "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "147dee35aab2193b174e4c0868bd80ead5ce755c", + "repo": "nix-unit", + "rev": "e9d81f6cffe67681e7c04a967d29f18c2c540af5", "type": "github" }, "original": { "owner": "nix-community", - "repo": "nixpkgs.lib", + "repo": "nix-unit", "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1739758141, + "narHash": "sha256-uq6A2L7o1/tR6VfmYhZWoVAwb3gTy7j4Jx30MIrH0rE=", + "rev": "c618e28f70257593de75a7044438efc1c1fc0791", + "revCount": 714614, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2411.714614%2Brev-c618e28f70257593de75a7044438efc1c1fc0791/0195155d-20df-7b25-ad70-45871483b8d2/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2411.%2A.tar.gz" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1736200483, @@ -300,12 +333,12 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1741332913, - "narHash": "sha256-ri1e8ZliWS3Jnp9yqpKApHaOo7KBN33W8ECAKA4teAQ=", - "rev": "20755fa05115c84be00b04690630cb38f0a203ad", - "revCount": 715401, + "lastModified": 1742268799, + "narHash": "sha256-IhnK4LhkBlf14/F8THvUy3xi/TxSQkp9hikfDZRD4Ic=", + "rev": "da044451c6a70518db5b730fe277b70f494188f1", + "revCount": 715814, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2411.715401%2Brev-20755fa05115c84be00b04690630cb38f0a203ad/0195727e-13d5-7381-935b-fec5e4805a71/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2411.715814%2Brev-da044451c6a70518db5b730fe277b70f494188f1/0195a953-6802-701a-a1d1-1b8453be1416/source.tar.gz" }, "original": { "type": "tarball", @@ -335,8 +368,9 @@ "flake-iter": "flake-iter", "flake-parts": "flake-parts", "flake-schemas": "flake-schemas_2", + "nix-unit": "nix-unit", "nixpkgs": "nixpkgs_4", - "treefmt-nix": "treefmt-nix" + "treefmt-nix": "treefmt-nix_2" } }, "rust-analyzer-src": { @@ -391,6 +425,27 @@ } }, "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nix-unit", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733662930, + "narHash": "sha256-9qOp6jNdezzLMxwwXaXZWPXosHbNqno+f7Ii/xftqZ8=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "357cda84af1d74626afb7fb3bc12d6957167cda9", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { "inputs": { "nixpkgs": "nixpkgs_5" }, diff --git a/flake.nix b/flake.nix index a7a31d0..a7fb171 100644 --- a/flake.nix +++ b/flake.nix @@ -7,69 +7,122 @@ fh.url = "https://flakehub.com/f/DeterminateSystems/fh/0.1.*"; flake-checker.url = "https://flakehub.com/f/DeterminateSystems/flake-checker/0.2.*"; flake-iter.url = "https://flakehub.com/f/DeterminateSystems/flake-iter/0.1.*"; - flake-parts.url = "https://flakehub.com/f/hercules-ci/flake-parts/0.1.*"; + # keep-sorted end + flake-parts = { + inputs.nixpkgs-lib.follows = "nixpkgs"; + url = "https://flakehub.com/f/hercules-ci/flake-parts/0.1.*"; + }; flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/0.1.*"; + nix-unit = { + url = "github:nix-community/nix-unit/?tag=v2.24.1"; + inputs = { + flake-parts.follows = "flake-parts"; + nixpkgs.follows = "nixpkgs"; + }; + }; treefmt-nix.url = "github:numtide/treefmt-nix/3d0579f5cc93436052d94b73925b48973a104204"; - # keep-sorted end }; - outputs = {flake-parts, ...} @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} { + outputs = + { flake-parts, self, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { imports = [ + # keep-sorted start + inputs.nix-unit.modules.flake.default inputs.treefmt-nix.flakeModule + # keep-sorted end ]; systems = [ - "x86_64-linux" - "aarch64-linux" + # keep-sorted start "aarch64-darwin" + "aarch64-linux" "x86_64-darwin" + "x86_64-linux" + # keep-sorted end ]; - perSystem = { - inputs', - pkgs, - self', - ... - }: { - devShells.default = pkgs.mkShell { - packages = [ - # keep-sorted start - inputs'.fh.packages.default - inputs'.flake-checker.packages.default - inputs'.flake-iter.packages.default - pkgs.git - pkgs.gnumake - pkgs.nixd - self'.formatter - # keep-sorted end - ]; - }; - treefmt = { - programs = { - # keep-sorted start - actionlint.enable = true; - alejandra.enable = true; - beautysh.enable = true; - black.enable = true; - cmake-format.enable = true; - deadnix.enable = true; - hclfmt.enable = true; - isort.enable = true; - jsonfmt.enable = true; - keep-sorted.enable = true; - mdformat.enable = true; - prettier.enable = true; - shellcheck.enable = true; - shfmt.enable = true; - sqlfluff.enable = true; - toml-sort.enable = true; - yamlfmt.enable = true; - # keep-sorted end + perSystem = + { + inputs', + pkgs, + self', + ... + }: + { + devShells.default = pkgs.mkShell { + packages = [ + # keep-sorted start + inputs'.fh.packages.default + inputs'.flake-checker.packages.default + inputs'.flake-iter.packages.default + pkgs.git + pkgs.gnumake + pkgs.nixd + self'.formatter + # keep-sorted end + ]; + }; + treefmt = { + programs = { + # keep-sorted start + actionlint.enable = true; + beautysh.enable = true; + black.enable = true; + cmake-format.enable = true; + deadnix.enable = true; + hclfmt.enable = true; + isort.enable = true; + jsonfmt.enable = true; + keep-sorted.enable = true; + mdformat.enable = true; + nixfmt.enable = true; + prettier.enable = true; + shellcheck.enable = true; + shfmt.enable = true; + sqlfluff.enable = true; + toml-sort.enable = true; + yamlfmt.enable = true; + # keep-sorted end + }; + }; + nix-unit = { + inputs = { + inherit (inputs) + nixpkgs + flake-parts + nix-unit + treefmt-nix + ; + }; + tests = { + "test example system-specific" = { + expr = "1"; + expected = "1"; + }; + }; }; }; - packages.default = pkgs.hello; - }; flake = { schemas = inputs.flake-schemas.schemas; + templates = rec { + base = { + description = "nullkomma template"; + path = ./templates/base; + welcomeText = '' + Welcome to the nullkomma template + ''; + }; + default = base; + }; + tests = { + "test example system-agnostic" = { + expr = "2"; + expected = "2"; + }; + "test template welcome text" = { + expr = self.templates.default.description; + expected = "nullkomma template"; + }; + }; }; }; } diff --git a/templates/base/.envrc b/templates/base/.envrc new file mode 100644 index 0000000..a93dec4 --- /dev/null +++ b/templates/base/.envrc @@ -0,0 +1,6 @@ +#!/bin/bash + +if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi +use flake diff --git a/templates/base/.github/workflows/ci.yml b/templates/base/.github/workflows/ci.yml new file mode 100644 index 0000000..aa28ad5 --- /dev/null +++ b/templates/base/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI +on: + pull_request: + workflow_dispatch: + push: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + DeterminateCI: + uses: DeterminateSystems/ci/.github/workflows/workflow.yml@main + permissions: + id-token: "write" + contents: "read" + with: + visibility: public + flake-checker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check Nix flake Nixpkgs inputs + uses: DeterminateSystems/flake-checker-action@v9 diff --git a/templates/base/.github/workflows/nix_maintenance.yml b/templates/base/.github/workflows/nix_maintenance.yml new file mode 100644 index 0000000..41a2484 --- /dev/null +++ b/templates/base/.github/workflows/nix_maintenance.yml @@ -0,0 +1,24 @@ +name: Maintenance +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * 0" # runs weekly on Sunday at 01:00 +jobs: + nix-maintenance: + name: Nix Maintenance + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - uses: DeterminateSystems/flakehub-cache-action@main + - uses: DeterminateSystems/update-flake-lock@main + with: + pr-title: "Update flake.lock" + pr-labels: | + dependencies + automated + - uses: DeterminateSystems/flake-checker-action@main + with: + fail-mode: true diff --git a/templates/base/flake.nix b/templates/base/flake.nix new file mode 100644 index 0000000..79c2130 --- /dev/null +++ b/templates/base/flake.nix @@ -0,0 +1,12 @@ +{ + description = "nullkomma"; + + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2411.*"; + }; + + outputs = + { ... }: + { + }; +}