Skip to content

Commit

Permalink
flake: partition dev dependencies
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MattSturgeon committed Feb 23, 2025
1 parent 0ab9947 commit 6d10fc0
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 285 deletions.
39 changes: 32 additions & 7 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ on:
# Allow manual triggering
workflow_dispatch:
inputs:
lock:
root_lock:
type: boolean
default: true
description: Update flake.lock
description: Update root flake.lock
dev_lock:
type: boolean
default: true
description: Update dev flake.lock
generate:
type: boolean
default: true
Expand Down Expand Up @@ -100,9 +104,9 @@ jobs:
git fetch origin "$pr_branch"
git branch --set-upstream-to "origin/$pr_branch"
- name: Update flake.lock
id: flake_lock
if: inputs.lock || github.event_name == 'schedule'
- name: Update root flake.lock
id: root_flake_lock
if: inputs.root_lock || github.event_name == 'schedule'
run: |
old=$(git show --no-patch --format=%h)
nix flake update --commit-lock-file
Expand All @@ -113,6 +117,22 @@ jobs:
echo "EOF" >> "$GITHUB_OUTPUT"
fi
- name: Update dev flake.lock
id: dev_flake_lock
if: inputs.dev_lock || github.event_name == 'schedule'
run: |
root_nixpkgs=$(nix eval -f . 'inputs.nixpkgs.rev')
old=$(git show --no-patch --format=%h)
nix flake update --commit-lock-file \
--override-input nixpkgs "github:NixOS/nixpkgs/$root_nixpkgs" \
--flake './flake/dev'
new=$(git show --no-patch --format=%h)
if [ "$old" != "$new" ]; then
echo "body<<EOF" >> "$GITHUB_OUTPUT"
git show --no-patch --format=%b >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
fi
- name: Update generated files
id: generate
if: inputs.generate || github.event_name == 'schedule'
Expand Down Expand Up @@ -185,9 +205,14 @@ jobs:
title: |
[${{ github.ref_name }}] Update flake.lock & generated files
body: |
## Flake lockfile
## Root lockfile
```
${{ steps.root_flake_lock.outputs.body || 'No changes' }}
```
## Dev lockfile
```
${{ steps.flake_lock.outputs.body || 'No changes' }}
${{ steps.dev_flake_lock.outputs.body || 'No changes' }}
```
## Generate
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
lock = builtins.fromJSON (builtins.readFile ./flake/dev/flake.lock);
in
fetchTarball {
url =
Expand Down
147 changes: 1 addition & 146 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 0 additions & 50 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,10 @@
inputs.nixpkgs-lib.follows = "nixpkgs";
};

/*
# NOTE: The inputs below this comment are optional
# You can remove them with `inputs.<input>.follows = ""`
For example:
```
nixvim = {
url = "github:nix-community/nixvim";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-parts.follows = "flake-parts";
devshell.follows = "";
flake-compat.follows = "";
git-hooks.follows = "";
home-manager.follows = "";
nix-darwin.follows = "";
treefmt-nix.follows = "";
};
};
```
*/

nuschtosSearch = {
url = "github:NuschtOS/search";
inputs.nixpkgs.follows = "nixpkgs";
};

home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};

devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};

flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
};
};

nixConfig = {
Expand Down
46 changes: 44 additions & 2 deletions flake/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
{
lib,
inputs,
config,
partitionStack,
...
}:
{
imports = [
./dev
./flake-modules
./lib.nix
./legacy-packages.nix
./nixvim-configurations.nix
./overlays.nix
./packages.nix
./templates.nix
./tests.nix
./wrappers.nix
inputs.flake-parts.flakeModules.partitions
];

# Define flake partitions
# Each has a `module`, assigned to the partition's submodule,
# and an `extraInputsFlake`, used for its inputs.
# See https://flake.parts/options/flake-parts-partitions.html
partitions = {
dev = {
module = ./dev;
extraInputsFlake = ./dev;
};
};

# Specify which outputs are defined by which partitions
partitionedAttrs = {
checks = "dev";
devShells = "dev";
formatter = "dev";
};

# For any output attrs normally defined by the root flake configuration,
# any exceptions must be manually propagated from the `dev` partition.
#
# NOTE: Attrs should be explicitly propagated at the deepest level.
# Otherwise the partition won't be lazy, making it pointless.
# E.g. propagate `packages.${system}.foo` instead of `packages.${system}`
# See: https://github.com/hercules-ci/flake-parts/issues/258
perSystem =
{ system, ... }:
{
packages = lib.optionalAttrs (partitionStack == [ ]) {
# Propagate `packages` from the `dev` partition:
inherit (config.partitions.dev.module.flake.packages.${system})
list-plugins
;
};
};
}
Loading

0 comments on commit 6d10fc0

Please sign in to comment.