-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an example of dogfooding (fix #121) #197
Open
Atry
wants to merge
20
commits into
hercules-ci:main
Choose a base branch
from
Atry:example-dogfooding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−0
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
aafcaf1
Add dogfood template
Atry a13fbf2
Create a more sophisticated lazy self
Atry d30b7b2
Simplify dogfood.nix
Atry 1456b31
Merge commit '1e8a89e5f81bca67c5f649318179fc11727262d0' into example-…
Atry 7ca7b6f
Use moduleLocation instead of changing self
Atry 8ad164c
Use flake.nix as the location
Atry 9ee625d
Merge commit 'f76e870d64779109e41370848074ac4eaa1606ec' into HEAD
Atry 89c069d
Add bootstrap step
Atry 863f8b6
Add a dev flake
Atry 7b75530
Avoid double mkFlake
Atry 08d2ea1
Merge commit '8c9fa2545007b49a5db5f650ae91f227672c3877' into example-…
Atry 478396a
Update dev.nix
Atry de10e51
Update to nixpkgs 23.05
Atry 539814f
Remove .gitignore
Atry b75dd7c
Avoid moduleLocation comparison
Atry ebe79a3
Merge commit 'bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a' into example-…
Atry 0bbf4aa
Dogfooding via partitions
Atry 5ce8768
Add `options.enableUserStdenv`
Atry 1796154
Move `enableUserStdenv` to `customHello.enableUserStdenv`
Atry 56f98c5
23.05 -> 24.05
Atry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
description = "Description for the project"; | ||
|
||
inputs = { | ||
nixpkgs_24_05.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||
}; | ||
|
||
outputs = { flake-parts, self, nixpkgs, ... }@inputs: | ||
flake-parts.lib.mkFlake | ||
{ | ||
inherit inputs; | ||
} | ||
(topLevel: { | ||
imports = [ | ||
flake-parts.flakeModules.partitions | ||
./modules/dev.nix | ||
]; | ||
|
||
systems = [ "x86_64-linux" "aarch64-darwin" ]; | ||
|
||
partitionedAttrs.devShells = "dogfood"; | ||
partitionedAttrs.packages = "dogfood"; | ||
partitions.dogfood = { | ||
module = topLevel.config.flake.flakeModules.dev; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ inputs, flake-parts-lib, lib, ... }: | ||
{ | ||
imports = [ | ||
inputs.flake-parts.flakeModules.flakeModules | ||
]; | ||
|
||
flake.flakeModules.customHello = flakeModule: | ||
let | ||
cfg = flakeModule.config.customHello; | ||
in | ||
{ | ||
options.customHello.enableUserStdenv = lib.mkEnableOption "stdenv from `flakeModules.customHello` user's nixpkgs"; | ||
options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { | ||
packages.hello = | ||
(inputs.nixpkgs_24_05.legacyPackages.${system}.hello.override { | ||
stdenv = | ||
if cfg.enableUserStdenv then | ||
pkgs.stdenv | ||
else | ||
inputs.nixpkgs_24_05.legacyPackages.${system}.stdenv; | ||
}).overrideAttrs (oldAttrs: { | ||
meta = oldAttrs.meta // { | ||
description = "A hello package from the `flakeModules.customHello` author's nixpkgs 24.05, built with stdenv from ${ | ||
if cfg.enableUserStdenv then | ||
"the `flakeModules.customHello` user's nixpkgs" | ||
else | ||
"the `flakeModules.customHello` author's nixpkgs 24.05" | ||
}"; | ||
}; | ||
}); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ flake-parts-lib, inputs, ... }@topLevel: | ||
{ | ||
imports = [ | ||
inputs.flake-parts.flakeModules.flakeModules | ||
|
||
# For `topLevel.config.flake.flakeModules.customHello` | ||
./custom-hello.nix | ||
]; | ||
|
||
flake.flakeModules.dev = { | ||
imports = [ | ||
# For `perSystem.config.packages.hello | ||
topLevel.config.flake.flakeModules.customHello | ||
]; | ||
|
||
config.customHello.enableUserStdenv = true; | ||
|
||
options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, ... }@perSystem: { | ||
devShells.default = pkgs.mkShell { | ||
buildInputs = [ perSystem.config.packages.hello ]; | ||
shellHook = '' | ||
hello | ||
''; | ||
}; | ||
}); | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to list these is not great UX.
I think I'd prefer to add a parameter to
mkFlake
.I think we could have a
modules
specialArg to make that nice:It's a bit more custom, but it avoids the complexity of having partitions, probably improving error messages as well, and slightly less boilerplate.
It does put the module in a different scope, but I think this can be worked around, with techniques similar to
withSystem
, and it'd look like:However, actually needing access to the local flake seems quite rare for flake-parts modules, so we might not even need it for now.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a flake module that defines a flake module is a good abstract, because it distinguishes the module author's inputs from the module user's inputs. I like the idea to make
publicModules
a partition of preparatory step by default before the "main" partition. This design has precedent in other languages, e.g. sbt.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why we cannot put bootstrap modules to
flakeModules
is thatflakeModules
is a submodule of themkFlake
's top level module, and themkFlake
's top level module cannot depend on its own submodule.Can we make
mkFlake
a submodule instead of a function, then we can create a "meta-module" as the new top-level module to set up special args for themkFlake
submodule. Eventually the user could simply use nixpkgs'sevalModules
to evaluate the meta-module to build the flake: