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
2 changes: 1 addition & 1 deletion flake/dev/devshell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, inputs, ... }:
{
imports = [
inputs.devshell.flakeModule
(inputs.devshell + "/flake-module.nix")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small price to pay?

];

perSystem =
Expand Down
56 changes: 6 additions & 50 deletions flake/dev/flake.lock

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

18 changes: 11 additions & 7 deletions flake/dev/flake.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
{
description = "Private inputs for development purposes. These are used by the top level flake in the `dev` partition, but do not appear in consumers' lock files.";

# Avoid `flake = true` when we do not need to evaluate flake outputs or fetch flake inputs.
# e.g. when we only import loose files.
Comment thread
MattSturgeon marked this conversation as resolved.
inputs = {
# NOTE: Use a different name to the root flake's inputs.nixpkgs to avoid shadowing it.
# NOTE: The only reason we specify a nixpkgs input at all here, is so the other inputs can follow it.
# TODO: Once nix 2.26 is more prevalent, follow the root flake's inputs using a "path:../.." input.
dev-nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

# flake-compat is used by the root `default.nix` to allow non-flake users to import nixvim
flake-compat.url = "github:NixOS/flake-compat";
flake-compat = {
url = "github:NixOS/flake-compat";
flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @MattSturgeon pointed, flake-compat instructs declaring it with flake=false in its readme.

};

# keep-sorted start block=yes newline_separated=yes
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "dev-nixpkgs";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followses be gone!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sold on flake = false being worth it just for eliminating transitive follows.

Imagine the scenario where an input changes its inputs without us noticing; if we pull it as a flake, then we get their new inputs transitively. If we don't, then things potentially break.


If the reason we can set flake = false is that we are explicitly only using a part of the project that is designed to be used without flake inputs, then that's fine and should probably be documented in a comment.

# Don't pull flake inputs or evaluate outputs.
# We exclusively use the flake-module file.
flake = false;

Or perhaps a top-level comment along the lines of:

# Avoid `flake = true` when we do not need to evaluate flake outputs or fetch flake inputs.
# e.g. when we only import loose files.

TL;DR a) consider whether we're setting flake = false for the right reasons b) consider whether flake = false is fragile and may miss future transitive dependencies c) document why we enable or disable flake in general or for specific inputs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that single comment above the inputs attribute.

I've pointed out in this PR for each flake=false why it is okay.

I think that projects that expose truly loose files such as /flake-module.nix and /lib/default.nix are aware that users will use them and are not likely to turn them into functions that first take local context such as flake inputs. I prefer this risk over lockfile drift.

flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposes a vanilla /flake-module.nix, so we're good.

};

git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "dev-nixpkgs";
inputs.flake-compat.follows = "flake-compat";
flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposes a vanilla /flake-module.nix, so we're good.

};

home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "dev-nixpkgs";
flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides a /lib/default.nix that takes { inherit lib; } so we're golden.

};

nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "dev-nixpkgs";
flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides a vanilla /eval-config.nix so we're golden.

};

nuschtosSearch = {
Expand All @@ -40,7 +44,7 @@

treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "dev-nixpkgs";
flake = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides a vanilla /flake-module.nix so we're golden.

};

# keep-sorted end
Expand Down
2 changes: 1 addition & 1 deletion flake/dev/fmt.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ inputs, ... }:
{
imports = [
inputs.treefmt-nix.flakeModule
(inputs.treefmt-nix + "/flake-module.nix")
];

perSystem =
Expand Down
2 changes: 1 addition & 1 deletion flake/dev/git-hooks.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ inputs, ... }:
{
imports = [
inputs.git-hooks.flakeModule
(inputs.git-hooks + "/flake-module.nix")
];

perSystem =
Expand Down
28 changes: 20 additions & 8 deletions tests/platforms/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
{
self,
system,
lib,
}:
self.inputs.nix-darwin.lib.darwinSystem {
let
darwinSystem = import (self.inputs.nix-darwin + "/eval-config.nix");
in
darwinSystem {
inherit lib;

modules = [
{
nixpkgs.hostPlatform = system;
(
{ config, ... }:
{
nixpkgs = {
source = self.inputs.nixpkgs;
hostPlatform = system;
};

programs.nixvim = {
enable = true;
};
programs.nixvim = {
enable = true;
};

system.stateVersion = 5;
}
system.stateVersion = config.system.maxStateVersion;
Comment thread
MattSturgeon marked this conversation as resolved.
}
)
self.nixDarwinModules.nixvim
];
}
6 changes: 3 additions & 3 deletions tests/platforms/hm-extra-files-byte-compiling.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
self,
pkgs,
lib,
}:
let
inherit (self.inputs.home-manager.lib)
homeManagerConfiguration
;
hmLib = import (self.inputs.home-manager + "/lib") { inherit lib; };
inherit (hmLib) homeManagerConfiguration;

config = {
home = {
Expand Down
6 changes: 3 additions & 3 deletions tests/platforms/hm-submodule-merge.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
self,
pkgs,
lib,
}:
# This test covers a user-reported regression where nixvim's submodule-option (programs.nixvim)
# cannot correctly merge options declared from the parent scope.
Expand All @@ -9,9 +10,8 @@
#
# To be clear, this is an upstream module system bug, this test validates our workaround.
let
inherit (self.inputs.home-manager.lib)
homeManagerConfiguration
;
hmLib = import (self.inputs.home-manager + "/lib") { inherit lib; };
inherit (hmLib) homeManagerConfiguration;

# This test module declares a nixvim option from a Home Manager module
# The module system will attempt an option-type merge on the `programs.nixvim` option,
Expand Down
6 changes: 5 additions & 1 deletion tests/platforms/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
self,
pkgs,
lib,
}:
self.inputs.home-manager.lib.homeManagerConfiguration {
let
hmLib = import (self.inputs.home-manager + "/lib") { inherit lib; };
in
hmLib.homeManagerConfiguration {
inherit pkgs;

modules = [
Expand Down
Loading