Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs

add templates/minimal (#83)

authored by oeiuwq.com and committed by

GitHub ad57f63a bfe0475f

+78 -8
+16 -8
.github/workflows/flake-check.yaml
··· 16 16 templates=$(find templates -mindepth 2 -maxdepth 2 -name flake.nix -print0 | xargs -0 dirname | xargs -n 1 basename | jq -R | jq -sc) 17 17 echo "$templates" 18 18 echo "templates=$templates" >> $GITHUB_OUTPUT 19 - bootstrap-command: 20 - name: Bootstrap command 19 + bootstrap-minimal: 20 + name: Bootstrap templates/minimal 21 21 runs-on: ubuntu-latest 22 22 env: 23 23 NIX_PATH: "nixpkgs=https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz" ··· 26 26 - uses: cachix/install-nix-action@v31 27 27 - uses: DeterminateSystems/magic-nix-cache-action@main 28 28 - uses: actions/checkout@v4 29 - - run: echo '{ }' > flake.nix 30 - - run: nix-shell "https://github.com/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.zip" -A flake-file.sh --run bootstrap 31 - - run: cat flake.nix flake-file.nix 32 - - run: grep inputs.flake-file.flakeModules.flake flake.nix 33 - - run: grep github:vic/flake-file flake.nix 29 + - run: | 30 + cd templates/minimal 31 + rm flake.nix 32 + mv flake-file.nix flake.nix 33 + nix-shell "https://github.com/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.zip" -A flake-file.sh --run bootstrap 34 + cat flake-file.nix flake.nix 35 + nix flake check 36 + sed -i 's#hello = "mundo"#hello = "world"#' flake-file.nix 37 + if nix flake check; then exit 1; fi 38 + sed -i 's#hello = "world"#hello = "monde"#' flake-file.nix 39 + nix flake check 34 40 bootstrap-tests: 35 41 name: Bootstrap apps 36 42 runs-on: ubuntu-latest ··· 49 55 strategy: 50 56 matrix: 51 57 template: ${{ fromJSON(needs.find-templates.outputs.templates) }} 58 + exclude: 59 + - template: minimal 52 60 steps: 53 61 - uses: wimpysworld/nothing-but-nix@main 54 62 - uses: cachix/install-nix-action@v31 ··· 121 129 sed -i 's/# flake-file = import/flake-file = import/' default.nix 122 130 nix-shell . -A flake-file.sh --run write-nixlock 123 131 dev: 124 - needs: [bootstrap-command, bootstrap-tests, nix-fmt] 132 + needs: [bootstrap-minimal, bootstrap-tests, nix-fmt] 125 133 name: Check flake dev 126 134 runs-on: ubuntu-latest 127 135 steps:
+4
docs/src/content/docs/tutorials/migrate-traditional-flake.mdx
··· 5 5 6 6 import { Aside } from '@astrojs/starlight/components'; 7 7 8 + <Aside title="Working Example" icon="nix"> 9 + You can use [`templates/minimal`](https://github.com/vic/flake-file/tree/main/templates/minimal) as a working example and safe sandbox to experiment. 10 + </Aside> 11 + 8 12 ## The bootstrap magic step. 9 13 10 14 ```shell
+5
modules/default.nix
··· 67 67 ]; 68 68 }; 69 69 70 + templates.minimal = { 71 + description = "minimal template"; 72 + path = ./../templates/minimal; 73 + }; 74 + 70 75 templates.default = { 71 76 description = "default template"; 72 77 path = ./../templates/default;
+11
templates/minimal/README.md
··· 1 + This template is an example of how to use flake-file without introducing new dependencies 2 + to your existing flake. 3 + 4 + This flake is the result of doing this bootstrap step (taken form the guide): 5 + 6 + ```shell 7 + mv flake.nix flake-file.nix 8 + nix-shell https://github.com/vic/flake-file/archive/main.tar.gz \ 9 + -A flake-file.sh --run write-flake \ 10 + --arg modules ./flake-file.nix --argstr outputs flake-file 11 + ```
+18
templates/minimal/flake-file.nix
··· 1 + { 2 + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 3 + 4 + outputs = _inputs: { 5 + hello = "mundo"; 6 + }; 7 + 8 + flake-file.outputs-schema = 9 + { lib, ... }: 10 + { 11 + options.hello = lib.mkOption { 12 + type = lib.types.enum [ 13 + "mundo" 14 + "monde" 15 + ]; 16 + }; 17 + }; 18 + }
+24
templates/minimal/flake.nix
··· 1 + # DO-NOT-EDIT. Generated by github:vic/flake-file from flake-file.nix. Regen with: 2 + # nix-shell https://github.com/vic/flake-file/archive/main.zip -A flake-file.sh --run bootstrap 3 + { 4 + 5 + outputs = 6 + inputs: 7 + (inputs.nixpkgs.lib.evalModules { 8 + specialArgs = { 9 + inherit inputs; 10 + inherit (inputs) self; 11 + }; 12 + modules = [ 13 + inputs.flake-file.flakeModules.flake 14 + ./flake-file.nix 15 + ]; 16 + }).config.outputs 17 + inputs; 18 + 19 + inputs = { 20 + flake-file.url = "github:vic/flake-file"; 21 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 22 + }; 23 + 24 + }