From 03f5198e9ed3dd66a0b146f8953c8fca98e66543 Mon Sep 17 00:00:00 2001 From: "den.aspects.pol" Date: Sun, 12 Apr 2026 21:40:52 +0200 Subject: [PATCH 1/2] chore: reorganise attributes logically --- flake.nix | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/flake.nix b/flake.nix index 4c43c3d..ee7eb36 100644 --- a/flake.nix +++ b/flake.nix @@ -4,29 +4,31 @@ outputs = { self, ... }: let - allOutputs = publicOutputs // { - # Use explicit inherit, to ensure allOutputs is evaluated without - # evaluating devOutputs. - inherit (devOutputs) devShells checks formatter; - }; - # Currently none (`import flake-compat`) # TODO: add `lib`. publicOutputs = { }; - devOutputs = devInputs.flake-parts.lib.mkFlake { - inputs = devInputs; - } ./dev/config.nix; - devInputs = devDeps // { - self = self // { - inputs = devInputs; - }; - }; # TODO: use clean library entrypoint when that's factored out. devDeps = (import ./default.nix { src = ./dev/deps; }).defaultNix.inputs; + + devInputs = devDeps // { + self = self // { + inputs = devInputs; + }; + }; + + devOutputs = devInputs.flake-parts.lib.mkFlake { + inputs = devInputs; + } ./dev/config.nix; + + allOutputs = publicOutputs // { + # Use explicit inherit, to ensure allOutputs is evaluated without + # evaluating devOutputs. + inherit (devOutputs) devShells checks formatter; + }; in allOutputs; } From 0fb71c7192d367c03e90abed764aa3436128c04a Mon Sep 17 00:00:00 2001 From: "den.aspects.pol" Date: Sun, 12 Apr 2026 22:02:58 +0200 Subject: [PATCH 2/2] feat: add `default` flake template --- README.md | 12 ++++++++++++ dev/config.nix | 7 +++++++ flake.nix | 2 +- templates/default/default.nix | 12 ++++++++++++ templates/default/shell.nix | 12 ++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 templates/default/default.nix create mode 100644 templates/default/shell.nix diff --git a/README.md b/README.md index 467597e..35e9e8a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,18 @@ This project was originally at `edolstra/flake-compat` and is now maintained at ## Usage +### Automatic setup (template) + +To generate both `default.nix` and `shell.nix` automatically, use the default template: + +```console +nix flake init -t github:NixOS/flake-compat +``` + +This creates a `default.nix` and `shell.nix` equivalent to the manual setup below. + +### Manual setup + To use, add the following to your `flake.nix`: ```nix diff --git a/dev/config.nix b/dev/config.nix index 46f92d2..40355a0 100644 --- a/dev/config.nix +++ b/dev/config.nix @@ -13,6 +13,13 @@ inputs.treefmt-nix.flakeModule ]; + flake = { + templates.default = { + path = ../templates/default; + description = "Default files for flake-compat configuration."; + }; + }; + # https://flake.parts/options/flake-parts.html#opt-perSystem perSystem = { diff --git a/flake.nix b/flake.nix index ee7eb36..35391d2 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ allOutputs = publicOutputs // { # Use explicit inherit, to ensure allOutputs is evaluated without # evaluating devOutputs. - inherit (devOutputs) devShells checks formatter; + inherit (devOutputs) devShells checks formatter templates; }; in allOutputs; diff --git a/templates/default/default.nix b/templates/default/default.nix new file mode 100644 index 0000000..c03ddc4 --- /dev/null +++ b/templates/default/default.nix @@ -0,0 +1,12 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + nodeName = lock.nodes.root.inputs.flake-compat; + in + fetchTarball { + url = + lock.nodes.${nodeName}.locked.url + or "https://github.com/NixOS/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; + sha256 = lock.nodes.${nodeName}.locked.narHash; + } +) { src = ./.; }).defaultNix diff --git a/templates/default/shell.nix b/templates/default/shell.nix new file mode 100644 index 0000000..692cd4d --- /dev/null +++ b/templates/default/shell.nix @@ -0,0 +1,12 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + nodeName = lock.nodes.root.inputs.flake-compat; + in + fetchTarball { + url = + lock.nodes.${nodeName}.locked.url + or "https://github.com/NixOS/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; + sha256 = lock.nodes.${nodeName}.locked.narHash; + } +) { src = ./.; }).shellNix