LnL7 / nix-darwin

nix modules for darwin
MIT License
3.12k stars 451 forks source link

Is there a way to "evaluate" my configuration? #824

Open jjant opened 11 months ago

jjant commented 11 months ago

I was looking for a way to "evaluate" my configuration, to basically get a nix record out of my flake with all the configuration I've set:

# Example configuration
{
  description = "Example Darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs }:
    let
      configuration = { pkgs, ... }: {
        environment.systemPackages = [
          pkgs.vim
          pkgs.neovim
        ];

        # Auto upgrade nix package and the daemon service.
        services.nix-daemon.enable = true;
        # nix.package = pkgs.nix;

        # Necessary for using flakes on this system.
        nix.settings.experimental-features = "nix-command flakes";

        # Create /etc/zshrc that loads the nix-darwin environment.
        programs.zsh.enable = true; # default shell on catalina
        programs.fish.enable = true;

        # Set Git commit hash for darwin-version.
        system.configurationRevision = self.rev or self.dirtyRev or null;

        system.defaults.dock.autohide = true;
        system.defaults.dock.showhidden = true;

        system.stateVersion = 4;

        # The platform the configuration will be used on.
        nixpkgs.hostPlatform = "x86_64-darwin";
      };
    in
    {
      darwinConfigurations."simple" = nix-darwin.lib.darwinSystem {
        modules = [ configuration ];
      };
    };
}

nix do the thing .#darwinConfigurations

{
  simple = {
      system = {
        configuration = ...
      };
    };
}

Is this possible?

kubukoz commented 11 months ago

nix build ~/.nixpkgs#darwinConfigurations."${HOSTNAME}".system

at least that's what I do: https://github.com/kubukoz/nix-config/blob/65496c3f3ff50076eed9b523462606dc2cbee34d/compare.sh

jjant commented 11 months ago

I want the nix object/record, not the built artifacts (directory tree).

Enzime commented 11 months ago

If you want to explore it, you can do nix repl .#darwinConfigurations.simple.config

I don't think a nix-darwin/NixOS configuration object is fully serializable, see: https://discourse.nixos.org/t/print-flake-system-configuration-as-json/14199/4