Skip to content
Open
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions dev/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand Down
30 changes: 16 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 templates;
};
in
allOutputs;
}
12 changes: 12 additions & 0 deletions templates/default/default.nix
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions templates/default/shell.nix
Original file line number Diff line number Diff line change
@@ -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