### Initial non-flake default.nix Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate-no-flakes.mdx Example of a traditional Nix default.nix file before migration. ```nix # default.nix let sources = import ./npins; in { nixosConfigurations.my-laptop = ...; # use sources } ``` -------------------------------- ### Start Local Development Server Source: https://github.com/denful/flake-file/blob/main/docs/README.md This command starts a local development server, typically accessible at `localhost:4321`, for previewing your site during development. ```bash pnpm dev ``` -------------------------------- ### Using the Dendritic flakeModule Source: https://context7.com/denful/flake-file/llms.txt This example demonstrates using the `flakeModules.dendritic` module for a batteries-included setup. It automatically includes flake-parts and import-tree defaults. ```nix # modules/default.nix { inputs, lib, }: { imports = [ inputs.flake-file.flakeModules.dendritic ]; flake-file = { description = "My Dendritic Project"; inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs-lib.follows = "nixpkgs"; # flake-parts and import-tree are added automatically by the dendritic module }; } # Generates outputs: inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules) ``` -------------------------------- ### Using unflake and nixlock flakeModules Source: https://context7.com/denful/flake-file/llms.txt This example shows how to use `flakeModules.unflake` and `flakeModules.nixlock` to generate `unflake.nix` or `nixlock.lock.nix` from `flake-file.inputs` declarations. ```nix # modules/default.nix — unflake { inputs, ... }: { imports = [ inputs.flake-file.flakeModules.unflake ]; flake-file.inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/denful/flake-file/blob/main/docs/README.md Run this command in the root of your project to install all necessary dependencies defined in `package.json`. ```bash pnpm install ``` -------------------------------- ### Create Astro Project with Starlight Template Source: https://github.com/denful/flake-file/blob/main/docs/README.md Use this command to initialize a new Astro project with the Starlight template. Ensure you have pnpm installed. ```bash pnpm create astro@latest -- --template starlight ``` -------------------------------- ### Initialize Project from Template Source: https://context7.com/denful/flake-file/llms.txt Commands to initialize a new project using flake-file's built-in templates. After initialization, generate flake.nix and verify the setup. ```shell # Minimal explicit setup (default) nix flake init -t github:vic/flake-file#default # Dendritic — batteries-included with flake-parts and import-tree nix flake init -t github:vic/flake-file#dendritic # flake-parts-builder integration nix flake init -t github:vic/flake-file#parts # Non-flake / stable Nix with npins nix flake init -t github:vic/flake-file#npins # Non-flake / stable Nix with unflake nix flake init -t github:vic/flake-file#unflake # Non-flake / stable Nix with nixlock nix flake init -t github:vic/flake-file#nixlock # After initialising any template, generate flake.nix and verify nix run ".#write-flake" nix flake check ``` -------------------------------- ### flake-file Configuration After Migration Source: https://context7.com/denful/flake-file/llms.txt This is an example of a `flake-file.nix` after migrating from a traditional `flake.nix`. It shows a full Nix configuration without restrictions and includes an optional output schema validation. ```nix # flake-file.nix (after migration) — full real Nix, no restrictions { lib, ... }: { flake-file.inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; outputs = inputs: { hello = "mundo"; }; # Optionally validate outputs with a typed schema flake-file.outputs-schema = { lib, ... }: { options.hello = lib.mkOption { type = lib.types.enum [ "mundo" "monde" ]; }; }; } ``` -------------------------------- ### Configure flake-file Inputs Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/reference/options.mdx Example demonstrating how to configure flake inputs, including direct URL references, following other inputs, and disabling flake detection for specific tools. ```nix flake-file = { description = "my awesome flake"; nixConfig = {}; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs-lib.follows = "nixpkgs"; inputs.my-tool.flake = false; inputs.my-tool.url = "github:owner/my-tool"; inputs.dep.inputs.nixpkgs.follows = "nixpkgs"; }; ``` -------------------------------- ### Create new default.nix for modular setup Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate-no-flakes.mdx A new default.nix file that leverages Nix Modules and resolves inputs using the npins generated from the flake-file.nix. ```nix # default.nix let sources = import ./npins; nixpkgs = import sources.nixpkgs { }; outputs = (nixpkgs.lib.evalModules { modules = ./modules; specialArgs = { inputs = sources; # (A) NOTE: Not flake-like inputs. }; }).config; in outputs ``` -------------------------------- ### Generate unflake.nix with Options Source: https://github.com/denful/flake-file/blob/main/templates/unflake/README.md Pass any unflake option to the `write-unflake` command. This example shows how to specify the verbose flag and the nix backend. ```shell nix-shell . -A flake-file.sh --run 'write-unflake --verbose --backend nix' ``` -------------------------------- ### Bootstrap flake-file Source: https://github.com/denful/flake-file/blob/main/README.md Use this command to bootstrap flake-file. It renames your existing flake.nix and installs flake-file. ```shell mv flake.nix flake-file.nix nix-shell https://github.com/vic/flake-file/archive/main.zip -A flake-file.sh --run bootstrap ``` -------------------------------- ### Move project files to modules directory Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate-no-flakes.mdx Organize your existing default.nix and flake-file.nix into a new 'modules' directory for a modular setup. ```shell mkdir modules mv flake-file.nix modules/inputs.nix mv default.nix modules/default.nix ``` -------------------------------- ### Create temporary directory for bootstrapping Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/bootstrap.mdx Create a temporary directory and navigate into it to safely experiment with the bootstrap command without affecting your existing flake setup. ```shell mkdir bootstrap cd bootstrap ``` -------------------------------- ### Get Help with Astro CLI Source: https://github.com/denful/flake-file/blob/main/docs/README.md Displays help information for the Astro CLI, useful for understanding available commands and options. ```bash pnpm astro -- --help ``` -------------------------------- ### Import flake-parts-builder Module Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/flake-parts-builder.mdx Import the flake-parts-builder module to enable dynamic loading of flake-parts. This setup bootstraps the builder, auto-loads Nix modules, and reads flake-file configurations from each part's _meta/ directory. ```nix { inputs, ... }: { imports = [ (inputs.flake-file.lib.flakeModules.flake-parts-builder ./flake-parts) ]; } ``` -------------------------------- ### Overriding flake-file.outputs for a One-liner Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/outputs.mdx An example of overriding `flake-file.outputs` for a simple, legitimate one-liner, such as setting up `dendritic`. ```nix inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules) ``` -------------------------------- ### Default flake.nix Configuration Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/templates.mdx A minimal and explicit Nix flake configuration using flake-parts. This serves as a basic setup without additional framework dependencies. ```nix # flake-parts module — see templates/default { inputs, ... }: { imports = [ inputs.flake-file.flakeModules.default ]; flake-file.inputs = { flake-file.url = "github:vic/flake-file"; flake-parts.url = "github:hercules-ci/flake-parts"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; systems = inputs.nixpkgs.lib.systems.flakeExposed; } ``` -------------------------------- ### Import flakeModules.dendritic Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/flake-modules.mdx Use the dendritic module for a batteries-included setup for Dendritic projects. It includes the default module, import-tree, flake-parts, and sets up default outputs. ```nix { inputs, lib, ... }: { imports = [ inputs.flake-file.flakeModules.dendritic ]; flake-file = { description = "My Awesome Flake"; inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; } ``` -------------------------------- ### Declare flake-file Inputs with Nix Modules Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/explanation/how-it-works.mdx Example of how to declare flake-file inputs within a Nix module, using lib.mkDefault for initial values and follows for referencing existing inputs. ```nix { inputs, lib, ... }: { flake-file.inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-file.inputs.nixpkgs-lib.follows = "nixpkgs"; } ``` -------------------------------- ### Add write-hook to update flake Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/hooks.mdx Use write-hooks to trigger follow-up actions whenever `flake.nix` is regenerated. This example runs `nix flake update` after `flake.nix` is written. ```nix { pkgs, ... }: { flake-file.write-hooks = [ { index = 10; exec = "${pkgs.nix}/bin/nix flake update"; } ]; } ``` -------------------------------- ### Declare Flake Inputs with flake-file Source: https://context7.com/denful/flake-file/llms.txt Example of declaring flake inputs as typed module options within a Nix module. Demonstrates standard GitHub inputs, following other inputs, non-flake sources, typed references, pinning to specific commits, flattening dependencies, and conditional inputs. ```nix # modules/inputs.nix { lib, ... }: { flake-file.inputs = { # Standard GitHub input nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; # Follow another input so transitive deps are shared nixpkgs-lib.follows = "nixpkgs"; # Non-flake source archive my-tool.flake = false; my-tool.url = "github:owner/my-tool"; # Typed reference (no url string needed) my-lib = { type = "github"; owner = "some-owner"; repo = "some-repo"; ref = "main"; }; # Pin to a specific commit pinned-dep.url = "github:owner/repo"; pinned-dep.rev = "abc1234def5678"; # Flatten a transitive dependency dep.inputs.nixpkgs.follows = "nixpkgs"; # Conditional input (only when some condition applies) optional-tool.url = lib.mkIf true "github:owner/optional-tool"; }; } ``` -------------------------------- ### Distribute input declarations to modules Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate.mdx To make modules self-contained, move input declarations from modules/inputs.nix to the specific modules that use them. This example shows how to declare an input for 'my-tool' within its own module. ```nix # modules/my-tool.nix { inputs, lib, ... }: { flake-file.inputs.my-tool.url = lib.mkDefault "github:owner/my-tool"; imports = lib.optionals (inputs ? my-tool) [ inputs.my-tool.flakeModule ]; } ``` -------------------------------- ### Initialize New Project with flake-file Template Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/quick-start.mdx Use this command to initialize a new project using a `flake-file` template. This is suitable for brand new projects, with or without existing flakes. ```shell nix flake init -t github:vic/flake-file#default ``` -------------------------------- ### Generate unflake.nix Source: https://github.com/denful/flake-file/blob/main/templates/unflake/README.md Use this command to generate the `unflake.nix` file. It first creates a temporary `inputs.nix` from your configuration and then runs unflake. ```shell nix-shell . -A flake-file.sh --run write-unflake ``` -------------------------------- ### Add check-hook for validation Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/hooks.mdx Use check-hooks to add extra validation during `nix flake check`. This example runs a linter to check the current directory. ```nix { pkgs, ... }: { flake-file.check-hooks = [ { index = 10; exec = "${pkgs.my-linter}/bin/my-linter --check ."; } ]; } ``` -------------------------------- ### Bootstrap flake.nix using a modules directory Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/bootstrap.mdx Bootstrap a `flake.nix` by providing a directory of `.nix` files as modules. These files will be auto-imported, which is useful when you have existing module files and need an initial `flake.nix`. ```shell nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \ -A flake-file.sh --run write-flake --arg modules ./modules ``` -------------------------------- ### flake-file Workflow Diagram Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/explanation/how-it-works.mdx Illustrates the process of declaring flake-file options in modules, running the write-flake command, and updating the flake.nix file. ```text edit modules/*.nix # declare flake-file options ↓ nix run .#write-flake # extracts inputs and serializes ↓ flake.nix # updated and locked ``` -------------------------------- ### Dendritic Project Initialization and Checks Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/templates.mdx Commands to initialize a Dendritic project using the `dendritic` template, generate the `flake.nix`, and perform a flake check. ```shell nix flake init -t github:vic/flake-file#dendritic nix run ".#write-flake" nix flake check ``` -------------------------------- ### Preview Production Build Source: https://github.com/denful/flake-file/blob/main/docs/README.md Allows you to preview the production build locally before deploying it. ```bash pnpm preview ``` -------------------------------- ### Build Production Site Source: https://github.com/denful/flake-file/blob/main/docs/README.md Generates a production-ready build of your website in the `./dist/` directory. ```bash pnpm build ``` -------------------------------- ### Verify and clean up after migration Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate.mdx Inspect the generated flake.nix to ensure correctness. Run `nix flake check` to verify the flake's integrity. Remove the backup file if satisfied. ```shell cat flake.nix # inspect the generated file nix flake check # verify everything is in sync rm flake.nix.bak # clean up if happy ``` -------------------------------- ### Initialize unflake Template Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/templates.mdx Use this command to initialize a project for a non-flake (stable Nix) environment using the `unflake` template, which leverages goldstein/unflake for input pinning. ```shell nix flake init -t github:vic/flake-file#unflake ``` -------------------------------- ### Import flakeModules.default Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/flake-modules.mdx Import the base module to access all flake-file options, the write-flake app, and flake checks. ```nix { inputs, ... }: { imports = [ inputs.flake-file.flakeModules.default ]; } ``` -------------------------------- ### Original flake.nix with flake-parts Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate-flake-parts.mdx This is the initial structure of a flake.nix file using flake-parts, defining inputs and the flake-parts entry-point module. ```nix # flake.nix { inputs = { # (A) So much inputs nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; foo.url = "github:coolguy/foo"; bar.url = "github:coolguy/bar"; }; outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } # (B) flake-parts entry-point module. { systems = [ "aarch64-darwin" ]; ... }; } ``` -------------------------------- ### Define flake-file.nix inputs Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/tutorials/migrate-no-flakes.mdx Create a flake-file.nix to define your project's inputs, similar to a flake's inputs. ```nix # flake-file.nix { flake-file.inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; } ``` -------------------------------- ### Run flake-file.sh via nix-shell Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/reference/bootstrap.mdx This command fetches the `flake-file.sh` app from a specific GitHub release and executes it within a `nix-shell`. Use this as the entry point for generating flake files. ```shell nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \ -A flake-file.sh --run [--arg ]... ``` -------------------------------- ### Adding flake-parts-builder Parts and Regenerating Source: https://context7.com/denful/flake-file/llms.txt Commands to add parts using `flake-parts-builder` and then regenerate the `flake.nix` to include new inputs. It also includes a check for flake integrity. ```shell # Add parts (use write-meta branch until PR#60 is merged) nix run github:vic/flake-parts-builder/write-meta -- \ add --write-meta --parts systems,treefmt $PWD # Regenerate flake.nix to pick up new inputs declared by added parts nix run ".#write-flake" nix flake check ``` -------------------------------- ### Bootstrap flake-file Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/index.mdx Use this command to bootstrap flake-file into your project. It involves renaming your existing flake.nix and then running the bootstrap script. ```shell mv flake.nix flake-file.nix nix-shell https://github.com/vic/flake-file/archive/main.tar.gz -A flake-file.sh --run bootstrap ``` -------------------------------- ### Initialize flake-file Template Source: https://github.com/denful/flake-file/blob/main/docs/src/content/docs/guides/templates.mdx Use this command to initialize a new project with a specific flake-file template. Replace `