-
-
Notifications
You must be signed in to change notification settings - Fork 20.1k
(Draft) NixOS vars #547171
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
Draft
prescientmoon
wants to merge
129
commits into
NixOS:master
Choose a base branch
from
starlitcanopy:master
base: master
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.
Draft
(Draft) NixOS vars #547171
Changes from 75 commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
3e6ad5e
nixos-vars: Init
prescientmoon ef34047
nixos-vars: Set up nix evaluation
prescientmoon b9930da
nixos-vars: Attempt to implement the proper logic for evaluating conf…
prescientmoon 1c45c6a
nixos-vars: Add a comment explaining the stub target-host-nixpkgs import
prescientmoon 1cfbb45
nixos-vars: Delete some older code
prescientmoon 8bdaf56
nixos-vars: Add a flake example
prescientmoon 0e0a9dc
nixos-vars: Improve NixOS module
prescientmoon ac586ed
nixos-vars: Explicitly set Python styling parameters
prescientmoon a08030b
nixos-vars: Implement config evaluation, including flake support
prescientmoon a1e3320
nixos-vars: Add support for direct JSON input
prescientmoon 9c96029
nixos-vars: Remove --nixpkgs arg
prescientmoon b8b8b74
nixos-vars: Fix up example
prescientmoon f8e386b
nixos-vars: Compute the evaluation order
prescientmoon ab7a25c
nixos-vars: Make variable casing consistent
prescientmoon 58542cf
nixos-vars: Implement rebuild order computation & checking whether fi…
prescientmoon 9c0e8f3
nixos-vars: Implement generation logic for secrets
prescientmoon f1c5df5
nixos-vars: Add rudimentary error handling to generation logic
prescientmoon c78a7e6
nixos-vars: Make generation logic respec --dry-run
prescientmoon e74c2a7
nixos-vars: Package the CLI using Nix
prescientmoon cab535f
nixos-vars: Proper error messages for script failure + pick a unique …
prescientmoon 9b2e0e6
nixos-vars: Support non root store paths for deferred packages
prescientmoon f3355e5
nixos-vars: Implement garbage collection
prescientmoon cec175c
nixos-vars: Add a basic NixOS test
prescientmoon e20fef3
nixos-vars: Implement the "regenerate" command
prescientmoon 0296e18
nixos-vars: Fix test
prescientmoon 60e5211
nixos-vars: Remove scuffed postInstall in favour of setuptools.packag…
prescientmoon 5abaf45
nixos-vars: Merge generate and regenerate into a single command
prescientmoon c1af279
nixos-vars: Add bubblewrap support
prescientmoon 9288cc7
nixos-vars: Run fixup scripts
prescientmoon 6770c62
nixos-vars: Improve the docs slightly
prescientmoon ea60b93
nixos-vars: Implement prompts
prescientmoon e1c5339
nixos-vars: Bump python version
prescientmoon 044449d
nixos-vars: Add rudimentary deploy script support
prescientmoon d87924b
nixos-vars: Update test for the meeting
prescientmoon 2e35a17
nixos-vars: Oops, the test should pass now! (with no sandbox though :…
prescientmoon f12c0f4
nixos-vars: Attempt to use closureInfo
prescientmoon 77143dd
nixos-vars: Attempt to make the test pass within the Nix sandbox
prescientmoon 96dd3a5
nixos-vars: Bind mount more paths in the bubblewrap sandbox
prescientmoon 4a0edf7
nixos-vars: Make the test pass
prescientmoon 5029e65
nixos-vars: Abstract away the closure computation used by the tests
prescientmoon f236713
nixos-vars: Support local deployments
prescientmoon e864e4c
nixos-vars: Add test for local deployment
prescientmoon b4d88f2
nixos-vars: import history
prescientmoon 67156d7
nixos-vars: Implement a simple age backend
prescientmoon 547c640
nixos-vars: move module to the NixOS module tree
prescientmoon 8a74436
nixos-vars: implement age backend local deployments & pass file list …
prescientmoon 67a204b
nixos-vars: make logs slightly more consistent
prescientmoon 091cc58
nixos-vars: remove generatorModule in favour of the built-in way of m…
prescientmoon 9024982
nivos-vars: write a scuffed demo deploy script for the age backend
prescientmoon b8318aa
nixos-vars: remove the unused --yes option
prescientmoon 4c41e5d
nixos-vars: start writing some docs
prescientmoon 89f2738
nixos-vars: write a bit more of the docs
prescientmoon d47e58e
nixos-vars: clean up examples slightly
prescientmoon afafead
nixos-vars: clean up example directory a bit further
prescientmoon 012cc13
nixos-vars: add docs about the vars schema
prescientmoon d2eac07
nixos-vars: make a few more things optional, and start working on the…
prescientmoon ed0c328
nixos-vars: improve docs (slightly)
prescientmoon 610cf25
nixos-vars: Remove {shell,default}.nix
prescientmoon e433f35
nixos-vars: remove example entrypoints that reference the current nix…
prescientmoon 2ddbb25
nixos-vars: fix the thingies treefmt was complaining about
prescientmoon 807ec47
nixos-vars: move test to the proper spot + fix some dangling paths
prescientmoon cab67aa
nixos-vars: fix arg parsing for `--set`
prescientmoon 4350292
nixos-vars: remove lib.fileset usage
prescientmoon c3a8d16
nixos-vars: make age backend file extraction atomic
prescientmoon 60c84df
meta: add myself to the maintainer list
prescientmoon 778326c
nixos-vars: add meta attribute
prescientmoon 1fcba3c
nixos-vars: improve docs & incorporate more PR feedback
prescientmoon 3b5c4f3
nixos-vars: improve phrasing a bit
prescientmoon e4b0148
nixos-vars: enlarge the code snippet explaining how to write a genera…
prescientmoon 35682d5
nixos-vars: remove editorconfig file
prescientmoon 3a37e55
nixos-vars: remove gitignore
prescientmoon ee17f8f
nixos-vars: remove ruff config (?)
prescientmoon 1fd6229
nixos-vars: reformat everything to match the root .editorconfig
prescientmoon a777107
nixos-vars: remove TODO related to merging from the age backend
prescientmoon 80802c8
nixos-vars: add example `identity.target` to age backend
prescientmoon a0a09c9
nixos-vars: pass both labels and descriptions to prompt scripts
prescientmoon 4aa05d4
nixos-vars: make `fixup` a batch operation
prescientmoon fa2cf5a
nixos-vars: remove age from devshell
prescientmoon 34fd2f0
nixos-vars: remove unused arg
prescientmoon d96e647
nixos-vars: use the old CLI when --flake is not used
prescientmoon fa1db85
nixos-vars: change test to not enable the new CLI
prescientmoon a32d547
nixos-vars: do not use --impure
prescientmoon e699983
nixos-vars: replace `nix-vars` with `nixos-vars` everywhere
prescientmoon aba1dfa
nixos-vars: also replace `nix_vars` -> `nixos_vars`
prescientmoon 8c6dfd7
nixos-vars: rename `deploy` -> `local` and remove the unused `secret`…
prescientmoon ae61f34
nixos-vars: `deploy` -> `deploy.remote`, `deployLocal` -> `deploy.local`
prescientmoon db80469
nixos-vars: fix naming inconsistencies with `delayedPackage` and `def…
prescientmoon ab38bf2
nixos-vars: fix invalid usage of `writeShellScript` in examples
prescientmoon a1782f8
nixos-vars: fix failing test
prescientmoon 5061bf1
nixos-vars: tiny var name changes (as discussed in the meeting)
prescientmoon 791ac25
nixos-vars: don't directly import <nixpkgs> as a fallback, thus getti…
prescientmoon 8b236a9
nixos-vars: allow mutating names in the NixOS module (instead of alwa…
prescientmoon c5f0167
nixos-vars: do not fail on the first fixup script error
prescientmoon f622a0b
nixos-vars: enable __structuredAttrs in order to make nixpkgs-vet happy
prescientmoon f6c894d
nixos-vars: better `safeName` error messages & check the names on the…
prescientmoon 4d2ffa5
nixos-vars: try to add more comments to `jsonify.nix`, explaining som…
prescientmoon 6971c2e
nixos-secrets: rename from `nixos-vars`
prescientmoon 245c7e2
nixos-secrets: extract common example backends into their own directory
prescientmoon 1643cea
nixos-secrets: add an example of how one can tack structured IDs on t…
prescientmoon 1edf118
nixos-secrets: use "with lib.types" in the module
prescientmoon fdd076b
nixos-secrets: rename the `!local` flag back to `deploy`
prescientmoon b985c1f
nixos-secrets: add safety comments to examples
prescientmoon 8f2ad76
nixos-secrets: write jsonschema for secrets configurations
prescientmoon 5f93e3f
nixos-secrets: rework naming structure
prescientmoon 3848fc8
nixos-secrets: make prompt names `safeName`s
prescientmoon d558dc7
nixos-secrets: fix bad arg description
prescientmoon 2508fb1
nixos-secrets: remove reference to never-captured stderr when running…
prescientmoon 51cef8d
nixos-secrets: fix failure to retrieve files being attributed to the …
prescientmoon 16174d5
nixos-vars: error out on secret with no files
prescientmoon b5e70fe
nixos-secrets: implement --set and checking whether files have actual…
prescientmoon 4088ff8
nixos-secrets: quote file name in error message
prescientmoon ee65459
nixos-secrets: generator script timeouts
prescientmoon 9c89013
nixos-secrets: pass info required for git-root detection via env vars
prescientmoon bb1ff15
nixos-secrets: pass `--die-with-parent` to bwrap
prescientmoon 7b77f48
nixos-secrets: probe for bwrap before using it
prescientmoon f0c051f
nixos-secrets: testing prompt backend
prescientmoon 9f3963d
nixos-secrets: reset terminal state after running user commands
prescientmoon d525841
nixos-secrets: improve docs related to the prompt backend changes
prescientmoon 303c627
nixos-secrets: pass empty stdin to generator scripts
prescientmoon bd8f05b
nixos-secrets: crash if bwrap is avaiable and --no-sandbox is not given
prescientmoon 26752fc
nixos-secrets: proper consistency checks
prescientmoon 3254df8
nixos-secrets: move examples to modulesPath and make test use said ex…
prescientmoon d2d6bf7
nixos-secrets: make the test pass
prescientmoon e6af758
nixos-secrets: rewrite the plain-text backend from Bash to Python
prescientmoon 58c856c
nixos-secrets: rework docs
prescientmoon 6336988
nixos-secrets: fix tests
prescientmoon e0171a0
nixos-secrets: fix docs
prescientmoon b226dac
nixos-secrets: remove the `exists` script in favour of `list`
prescientmoon cd8bd49
nixos-secrets: explain when bad things might happen
prescientmoon 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 hidden or 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 hidden or 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,341 @@ | ||
| { lib, config, ... }: | ||
| let | ||
| safeName = lib.types.strMatching "[a-zA-Z0-9:_\\.-]*"; | ||
| cfg = config.vars; | ||
|
|
||
| delayedPackage = | ||
| description: | ||
| lib.mkOption { | ||
| inherit description; | ||
| type = lib.types.functionTo lib.types.pathInStore; | ||
| example = pkgs: pkgs.writeShellScript "echo 'Hi!'"; | ||
| }; | ||
|
|
||
| nullableDelayedPackage = | ||
| description: | ||
| lib.mkOption { | ||
| inherit description; | ||
| type = lib.types.nullOr (lib.types.functionTo lib.types.pathInStore); | ||
| example = pkgs: pkgs.writeShellScript "echo 'Hi!'"; | ||
| default = null; | ||
| }; | ||
|
|
||
| generatorBackendModule = lib.types.submodule ( | ||
| { name, ... }: | ||
| { | ||
| options = { | ||
| name = lib.mkOption { | ||
| description = "The name of the backend."; | ||
| type = lib.types.str; | ||
| readOnly = true; | ||
| default = name; | ||
| }; | ||
|
|
||
| get = nullableDelayedPackage '' | ||
| Given $1=gen_name and $2=file_name, the script retrieves the | ||
| respective secret to $out. | ||
| ''; | ||
|
|
||
| set = delayedPackage '' | ||
| Given $1=gen_name and $2=file_name, the script retrieves the | ||
| respective secret from $in and stores it in the appropriate location. | ||
| ''; | ||
|
|
||
| exists = delayedPackage '' | ||
| Given $1=gen_name and $2=file_name, the script exists with status | ||
| code 0 if the secret exists, and with status code 42 otherwise. | ||
|
|
||
| This script must not perform side effects. | ||
| ''; | ||
|
|
||
| delete = nullableDelayedPackage '' | ||
| Given $1=gen_name and $2=file_name, the script deletes the respective | ||
| secret if it does exist. | ||
| ''; | ||
|
|
||
| list = nullableDelayedPackage '' | ||
| A script that lists all files managed by this backend. Should output | ||
| space-separated or newline-separated pairs of: generator_name | ||
| file_name. | ||
|
|
||
| If the backend supports multiple hosts, then this command should only | ||
| list the secrets owned by the current host. In particular, files | ||
| included in this command's output will be deleted by the | ||
| collect-garbage command, unless they appear in the user's generator | ||
| configuration. | ||
|
|
||
| This script must not perform side effects. | ||
| ''; | ||
|
|
||
| fixup = nullableDelayedPackage '' | ||
| This script will be run on every invocation of the CLI's generator | ||
| command. Given $1=gen_name and $2=file_name, the script performs any | ||
| necessary updates to the secrets' files (e.g. rekeying encrypted | ||
| secrets). This script can perform side effects, but must be | ||
| idempotent. | ||
| ''; | ||
|
|
||
| deploy = nullableDelayedPackage '' | ||
| Deploys every available file to the given machine. Any additional | ||
| information required by the deploy script can be provided by the user | ||
| through environment variables. | ||
| ''; | ||
|
|
||
| deployLocal = nullableDelayedPackage '' | ||
| Deploys every available file to the machine with system root mounted | ||
| at $1=system_root. This is useful for fresh installs from | ||
| environments live live CDs, where the target system is not yet up and | ||
| running (even if nixos-install has successfully completed). | ||
| ''; | ||
|
|
||
| fileModule = lib.mkOption { | ||
| type = lib.types.deferredModule; | ||
| internal = true; | ||
| default = { }; | ||
| description = '' | ||
| A module to be imported in every | ||
| vars.generators.<name>.files.<name> submodule. Used by backends to | ||
| define the `path` attribute. The module will have the following | ||
| additional arguments passed to it: | ||
| - `generator`, containing the generator the file belongs to | ||
| - `backend`, containing the backend associated with said generator | ||
| ''; | ||
| }; | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| fileModule = | ||
| { name, backend, ... }: | ||
| { | ||
| imports = [ backend.fileModule ]; | ||
| options = { | ||
| name = lib.mkOption { | ||
| description = "name of the generated file"; | ||
| type = safeName; | ||
| readOnly = true; | ||
| default = name; | ||
| defaultText = "Name of the file"; | ||
| }; | ||
|
|
||
| path = lib.mkOption { | ||
| description = "Path to the generated file; usually set by the backend"; | ||
| type = lib.types.path; | ||
| }; | ||
|
|
||
| deploy = lib.mkOption { | ||
| description = '' | ||
| Whether the file should be deployed to the target machine. Disable | ||
| this if the generated file is only used as an input to other | ||
| generators. | ||
|
|
||
| This option is not currently used by the CLI. | ||
| ''; | ||
| type = lib.types.bool; | ||
| default = true; | ||
| }; | ||
|
|
||
| secret = lib.mkOption { | ||
|
prescientmoon marked this conversation as resolved.
Outdated
|
||
| description = '' | ||
| Whether the file should be treated as a secret. Backends might | ||
| treat such files differently (e.g. they might choose not to encrypt | ||
| them). | ||
|
|
||
| This option is not currently used by the CLI. | ||
| ''; | ||
| type = lib.types.bool; | ||
| default = true; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| generatorModule = lib.types.submodule ( | ||
| { name, config, ... }: | ||
| let | ||
| backend = cfg.generatorBackends.${config.backend}; | ||
| in | ||
| { | ||
| options = { | ||
| name = lib.mkOption { | ||
| description = '' | ||
| The name of the generator. | ||
| This name will be used to refer to the generator in other generators. | ||
| ''; | ||
| type = safeName; | ||
| readOnly = true; | ||
| default = name; | ||
| defaultText = "Name of the generator"; | ||
| }; | ||
|
|
||
| prompts = lib.mkOption { | ||
| description = '' | ||
| A list of prompts this generator will have at its disposal. | ||
| ''; | ||
| type = lib.types.listOf safeName; | ||
| default = [ ]; | ||
| }; | ||
|
|
||
| dependencies = lib.mkOption { | ||
| description = '' | ||
| A list of other generators this generator should be able to read the | ||
| output(s) of. | ||
| ''; | ||
| type = lib.types.listOf safeName; | ||
| default = [ ]; | ||
| }; | ||
|
|
||
| files = lib.mkOption { | ||
| description = '' | ||
| A set of files to generate. The generator 'script' is expected to | ||
| produce exactly these files under $out. | ||
| ''; | ||
| default = { }; | ||
| type = lib.types.attrsOf ( | ||
| lib.types.submoduleWith { | ||
| modules = [ fileModule ]; | ||
| specialArgs = { | ||
| inherit backend; | ||
| generator = config; | ||
| }; | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| script = delayedPackage '' | ||
| The script to run to generate the files. The script will be run with | ||
| the following environment variables: | ||
| - $in: The directory containing the output values of all declared | ||
| dependencies | ||
| - $out: The output directory to put the generated files | ||
| - $prompts: The directory containing the prompted values as files | ||
| The script should produce the files specified in the 'files' attribute | ||
| under $out. | ||
| ''; | ||
|
|
||
| backend = lib.mkOption { | ||
| type = safeName; | ||
| description = "The backend responsible for handling this secret."; | ||
| default = cfg.defaultGeneratorBackend; | ||
| }; | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| promptBackendModule = lib.types.submodule ( | ||
| { name, ... }: | ||
| { | ||
| options = { | ||
| name = lib.mkOption { | ||
| description = "The name of the backend."; | ||
| type = lib.types.str; | ||
| readOnly = true; | ||
| default = name; | ||
| }; | ||
|
|
||
| script = delayedPackage '' | ||
| Given $1=prompt_type and $2=prompt_text, the script runs the prompt | ||
| by the user, then saves respective value to $out. | ||
| ''; | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| promptModule = lib.types.submodule ( | ||
| { name, ... }: | ||
| { | ||
| options = { | ||
| name = lib.mkOption { | ||
| description = "The name of the backend."; | ||
| type = lib.types.str; | ||
| readOnly = true; | ||
| default = name; | ||
| }; | ||
|
|
||
| description = lib.mkOption { | ||
| description = '' | ||
| The description of the prompted value | ||
| ''; | ||
| type = lib.types.str; | ||
| default = name; | ||
|
prescientmoon marked this conversation as resolved.
Outdated
|
||
| defaultText = "Name of the prompt"; | ||
| example = "SSH private key"; | ||
| }; | ||
|
|
||
| type = lib.mkOption { | ||
| description = '' | ||
| The input type of the prompt. | ||
| The following types are available: | ||
| - hidden: A hidden text (e.g. password) | ||
| - line: A single line of text | ||
| - multiline: A multiline text | ||
| ''; | ||
| type = lib.types.enum [ | ||
| "hidden" | ||
| "line" | ||
| "multiline" | ||
| ]; | ||
| default = "line"; | ||
| }; | ||
|
|
||
| backend = lib.mkOption { | ||
| type = safeName; | ||
| description = "The backend responsible for handling this prompt."; | ||
| default = cfg.defaultPromptBackend; | ||
| }; | ||
| }; | ||
| } | ||
| ); | ||
| in | ||
| { | ||
| options.vars = { | ||
| generatorBackends = lib.mkOption { | ||
| description = '' | ||
| A set of backends that handle storing and retrieving generated files. | ||
| ''; | ||
| default = { }; | ||
| type = lib.types.attrsOf generatorBackendModule; | ||
| }; | ||
|
|
||
| generators = lib.mkOption { | ||
| description = '' | ||
| A set of generators that are each expected to produce a set of files | ||
| under a directory. Generators can produce files using a script, | ||
| possibly referencing values produced by other generators and user | ||
| input. | ||
| ''; | ||
| default = { }; | ||
| type = lib.types.attrsOf generatorModule; | ||
| }; | ||
|
|
||
| defaultGeneratorBackend = lib.mkOption { | ||
| description = '' | ||
| The default backend to use for generators that do not specify one. | ||
| ''; | ||
| type = safeName; | ||
| }; | ||
|
|
||
| promptBackends = lib.mkOption { | ||
| description = '' | ||
| A set of backends that handle retrieving user inputs. | ||
| ''; | ||
| default = { }; | ||
| type = lib.types.attrsOf promptBackendModule; | ||
| }; | ||
|
|
||
| prompts = lib.mkOption { | ||
| description = '' | ||
| A set of prompts the user can use to provide manual input to the | ||
| generator backends. | ||
| ''; | ||
| default = { }; | ||
| type = lib.types.attrsOf promptModule; | ||
| }; | ||
|
|
||
| defaultPromptBackend = lib.mkOption { | ||
| description = '' | ||
| The default backend to use for prompts that do not specify one. | ||
| ''; | ||
| type = safeName; | ||
| }; | ||
| }; | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.