Skip to content

Commit 6d10fc0

Browse files
committed
flake: partition dev dependencies
This removes the need for end-users to manually set `nixvim.inputs.devshell.follows = ""` (etc) We offload evaluation of some of our flake modules into a `dev` partition submodule. - When its not needed, this submodule is not evaluated. - When it is needed, it fetches extra inputs from `flake/dev/flake.nix` as part of evaluating the submodule. See https://flake.parts/options/flake-parts-partitions.html
1 parent 0ab9947 commit 6d10fc0

File tree

16 files changed

+366
-285
lines changed

16 files changed

+366
-285
lines changed

.github/workflows/update.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ on:
66
# Allow manual triggering
77
workflow_dispatch:
88
inputs:
9-
lock:
9+
root_lock:
1010
type: boolean
1111
default: true
12-
description: Update flake.lock
12+
description: Update root flake.lock
13+
dev_lock:
14+
type: boolean
15+
default: true
16+
description: Update dev flake.lock
1317
generate:
1418
type: boolean
1519
default: true
@@ -100,9 +104,9 @@ jobs:
100104
git fetch origin "$pr_branch"
101105
git branch --set-upstream-to "origin/$pr_branch"
102106
103-
- name: Update flake.lock
104-
id: flake_lock
105-
if: inputs.lock || github.event_name == 'schedule'
107+
- name: Update root flake.lock
108+
id: root_flake_lock
109+
if: inputs.root_lock || github.event_name == 'schedule'
106110
run: |
107111
old=$(git show --no-patch --format=%h)
108112
nix flake update --commit-lock-file
@@ -113,6 +117,22 @@ jobs:
113117
echo "EOF" >> "$GITHUB_OUTPUT"
114118
fi
115119
120+
- name: Update dev flake.lock
121+
id: dev_flake_lock
122+
if: inputs.dev_lock || github.event_name == 'schedule'
123+
run: |
124+
root_nixpkgs=$(nix eval -f . 'inputs.nixpkgs.rev')
125+
old=$(git show --no-patch --format=%h)
126+
nix flake update --commit-lock-file \
127+
--override-input nixpkgs "github:NixOS/nixpkgs/$root_nixpkgs" \
128+
--flake './flake/dev'
129+
new=$(git show --no-patch --format=%h)
130+
if [ "$old" != "$new" ]; then
131+
echo "body<<EOF" >> "$GITHUB_OUTPUT"
132+
git show --no-patch --format=%b >> "$GITHUB_OUTPUT"
133+
echo "EOF" >> "$GITHUB_OUTPUT"
134+
fi
135+
116136
- name: Update generated files
117137
id: generate
118138
if: inputs.generate || github.event_name == 'schedule'
@@ -185,9 +205,14 @@ jobs:
185205
title: |
186206
[${{ github.ref_name }}] Update flake.lock & generated files
187207
body: |
188-
## Flake lockfile
208+
## Root lockfile
209+
```
210+
${{ steps.root_flake_lock.outputs.body || 'No changes' }}
211+
```
212+
213+
## Dev lockfile
189214
```
190-
${{ steps.flake_lock.outputs.body || 'No changes' }}
215+
${{ steps.dev_flake_lock.outputs.body || 'No changes' }}
191216
```
192217
193218
## Generate

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(import (
22
let
3-
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
3+
lock = builtins.fromJSON (builtins.readFile ./flake/dev/flake.lock);
44
in
55
fetchTarball {
66
url =

flake.lock

Lines changed: 1 addition & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,10 @@
99
inputs.nixpkgs-lib.follows = "nixpkgs";
1010
};
1111

12-
/*
13-
# NOTE: The inputs below this comment are optional
14-
# You can remove them with `inputs.<input>.follows = ""`
15-
16-
For example:
17-
18-
```
19-
nixvim = {
20-
url = "github:nix-community/nixvim";
21-
inputs = {
22-
nixpkgs.follows = "nixpkgs";
23-
flake-parts.follows = "flake-parts";
24-
25-
devshell.follows = "";
26-
flake-compat.follows = "";
27-
git-hooks.follows = "";
28-
home-manager.follows = "";
29-
nix-darwin.follows = "";
30-
treefmt-nix.follows = "";
31-
};
32-
};
33-
```
34-
*/
35-
3612
nuschtosSearch = {
3713
url = "github:NuschtOS/search";
3814
inputs.nixpkgs.follows = "nixpkgs";
3915
};
40-
41-
home-manager = {
42-
url = "github:nix-community/home-manager";
43-
inputs.nixpkgs.follows = "nixpkgs";
44-
};
45-
nix-darwin = {
46-
url = "github:lnl7/nix-darwin";
47-
inputs.nixpkgs.follows = "nixpkgs";
48-
};
49-
50-
devshell = {
51-
url = "github:numtide/devshell";
52-
inputs.nixpkgs.follows = "nixpkgs";
53-
};
54-
treefmt-nix = {
55-
url = "github:numtide/treefmt-nix";
56-
inputs.nixpkgs.follows = "nixpkgs";
57-
};
58-
59-
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
60-
61-
git-hooks = {
62-
url = "github:cachix/git-hooks.nix";
63-
inputs.nixpkgs.follows = "nixpkgs";
64-
inputs.flake-compat.follows = "flake-compat";
65-
};
6616
};
6717

6818
nixConfig = {

flake/default.nix

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
1+
{
2+
lib,
3+
inputs,
4+
config,
5+
partitionStack,
6+
...
7+
}:
18
{
29
imports = [
3-
./dev
410
./flake-modules
511
./lib.nix
612
./legacy-packages.nix
713
./nixvim-configurations.nix
814
./overlays.nix
915
./packages.nix
1016
./templates.nix
11-
./tests.nix
1217
./wrappers.nix
18+
inputs.flake-parts.flakeModules.partitions
1319
];
20+
21+
# Define flake partitions
22+
# Each has a `module`, assigned to the partition's submodule,
23+
# and an `extraInputsFlake`, used for its inputs.
24+
# See https://flake.parts/options/flake-parts-partitions.html
25+
partitions = {
26+
dev = {
27+
module = ./dev;
28+
extraInputsFlake = ./dev;
29+
};
30+
};
31+
32+
# Specify which outputs are defined by which partitions
33+
partitionedAttrs = {
34+
checks = "dev";
35+
devShells = "dev";
36+
formatter = "dev";
37+
};
38+
39+
# For any output attrs normally defined by the root flake configuration,
40+
# any exceptions must be manually propagated from the `dev` partition.
41+
#
42+
# NOTE: Attrs should be explicitly propagated at the deepest level.
43+
# Otherwise the partition won't be lazy, making it pointless.
44+
# E.g. propagate `packages.${system}.foo` instead of `packages.${system}`
45+
# See: https://github.com/hercules-ci/flake-parts/issues/258
46+
perSystem =
47+
{ system, ... }:
48+
{
49+
packages = lib.optionalAttrs (partitionStack == [ ]) {
50+
# Propagate `packages` from the `dev` partition:
51+
inherit (config.partitions.dev.module.flake.packages.${system})
52+
list-plugins
53+
;
54+
};
55+
};
1456
}

0 commit comments

Comments
 (0)