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 15 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
21 changes: 21 additions & 0 deletions template/dogfood/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
description = "Description for the project";

inputs = {
nixpkgs_23_05.url = "github:NixOS/nixpkgs/nixos-23.05";
};

outputs = { flake-parts, self, nixpkgs, ... }@inputs:
flake-parts.lib.mkFlake
{
inherit inputs;
moduleLocation = ./flake.nix;
}
{
imports = [
./modules/anotherFlakeModule.nix
./modules/hello.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
};
}
32 changes: 32 additions & 0 deletions template/dogfood/modules/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{flake-parts-lib, lib, inputs, ...}@topLevel:
rec {
imports = [
inputs.flake-parts.flakeModules.flakeModules

# Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion
./hello.nix

{
flake.flakeModules.dev.imports = [
# Use attributes to reference the flake module from other flakes
topLevel.config.flake.flakeModules.hello
];
}

# Reference `flake.flakeModules.dev` via `rec` instead of `config` to avoid infinite recursion
flake.flakeModules.dev
];

flake.flakeModules.dev = {
config.systems = [ "x86_64-linux" "aarch64-darwin" ];

options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: {
devShells.default = pkgs.mkShell {
buildInputs = [ perSystem.config.packages.hello_22_11 ];
shellHook = ''
hello
'';
};
});
};
}
16 changes: 16 additions & 0 deletions template/dogfood/modules/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{inputs, flake-parts-lib, ...}:
rec {
imports = [
inputs.flake-parts.flakeModules.flakeModules

# Reference `flake.flakeModules.hello` via `rec` instead of `config` to avoid infinite recursion
flake.flakeModules.hello
];

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