Created
November 15, 2025 20:08
-
-
Save tennox/abda0b746f6dceb7fed6192defc9524a to your computer and use it in GitHub Desktop.
Conditional Dev Mode Symlinks for Nix Config
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
| { config, lib, inputs, ... }: | |
| { | |
| options.dev = { | |
| nixConfigPathForDevLinks = lib.mkOption { | |
| type = lib.types.nullOr lib.types.str; | |
| default = null; | |
| description = '' | |
| When set, enables development mode and symlinks files directly from the nix-config repo. | |
| Set to the path of your nix-config repository (e.g., "/home/manu/dev/nix-config"). | |
| When null, files are deployed normally. | |
| ''; | |
| }; | |
| }; | |
| config = | |
| let | |
| devMode = config.dev.nixConfigPathForDevLinks != null; | |
| flakeRoot = toString inputs.self; | |
| in | |
| { | |
| lib.file.mkSymlinkInDevMode = pathArg: | |
| if devMode | |
| then | |
| let | |
| abs = toString pathArg; | |
| relativePath = lib.strings.removePrefix "${flakeRoot}/" abs; | |
| in | |
| config.lib.file.mkOutOfStoreSymlink "${config.dev.nixConfigPathForDevLinks}/${relativePath}" | |
| else pathArg; | |
| # Helper that returns { source = ...; executable = ...; } for executable files | |
| lib.file.mkExecSymlinkInDevMode = pathArg: | |
| if devMode | |
| then | |
| let | |
| abs = toString pathArg; | |
| relativePath = lib.strings.removePrefix "${flakeRoot}/" abs; | |
| in | |
| { | |
| source = config.lib.file.mkOutOfStoreSymlink "${config.dev.nixConfigPathForDevLinks}/${relativePath}"; | |
| } | |
| else { | |
| source = pathArg; | |
| executable = true; | |
| }; | |
| # Export devMode for use in configs | |
| lib.file.isDevMode = devMode; | |
| }; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment