Skip to content

Instantly share code, notes, and snippets.

@ckiee
Created January 4, 2022 08:42
Show Gist options
  • Save ckiee/f86ed075bb8aa839a55fff00d9307205 to your computer and use it in GitHub Desktop.
Save ckiee/f86ed075bb8aa839a55fff00d9307205 to your computer and use it in GitHub Desktop.
Get the default value of a NixOS option
# $ nix-instantiate --eval option.nix --argstr path services.journald.enableHttpGateway
# false
{ path }:
let
pkgs = import <nixpkgs> { };
evalConfig = import "${<nixpkgs>}/nixos/lib/eval-config.nix";
inherit (pkgs) lib;
in (evalConfig {
modules = [
({ config, ... }: {
options.cookie = lib.mkOption { default = null; };
config.cookie = lib.getAttrFromPath (lib.splitString "." path) config;
config._module.check = false;
config.fileSystems."/".device = "/fake";
config.boot.loader.grub.devices = [ "/fake" ];
})
];
}).config.cookie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment