Skip to content
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
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
A minimal flake using flake-parts importing nixpkgs with the unfree option.
'';
};
dogfood = {
path = ./template/dogfood;
description = ''
A minimal flake using flake-parts creating flake modules to build its own outputs.
'';
};
};
flakeModules = {
easyOverlay = ./extras/easyOverlay.nix;
Expand Down
1 change: 1 addition & 0 deletions template/dogfood/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.direnv/
20 changes: 20 additions & 0 deletions template/dogfood/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
description = "Description for the project";

inputs = {
nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11";
Atry marked this conversation as resolved.
Show resolved Hide resolved
};

outputs = { flake-parts, self, nixpkgs, ... }@inputs:
flake-parts.lib.mkFlake
{
inherit inputs;
moduleLocation = ./flake.nix;
}
{
imports = [
./modules/anotherFlakeModule.nix
./modules/dev.nix
];
};
}
8 changes: 8 additions & 0 deletions template/dogfood/modules/anotherFlakeModule.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{inputs, ...}: {
imports = [
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.anotherFlakeModule = {
# Define another flake module here
};
}
25 changes: 25 additions & 0 deletions template/dogfood/modules/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{flake-parts-lib, lib, inputs, ...}@topLevel:
rec {
imports = [
inputs.flake-parts.flakeModules.flakeModules
flake.flakeModules.dev
];
flake.flakeModules.dev = dev: {
config.systems = [ "x86_64-linux" "aarch64-darwin" ];
imports = [
(
if topLevel.moduleLocation == dev.moduleLocation
then ./hello.nix # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion
else topLevel.config.flake.flakeModules.hello # Use attributes to reference the flake module from other flakes
)
];
options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: {
devShells.default = pkgs.mkShell {
buildInputs = [ perSystem.config.packages.hello_22_11 ];
shellHook = ''
hello
'';
};
});
};
}
14 changes: 14 additions & 0 deletions template/dogfood/modules/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{inputs, flake-parts-lib, ...}:
rec {
imports = [
inputs.flake-parts.flakeModules.flakeModules
flake.flakeModules.hello
];

flake.flakeModules.hello = {
options.perSystem = flake-parts-lib.mkPerSystemOption ({ system, ... }: {
packages.hello_22_11 =
inputs.nixpkgs_22_11.legacyPackages.${system}.hello;
});
};
}