diff --git a/README.md b/README.md index 94ebdda4..d31d6c8d 100644 --- a/README.md +++ b/README.md @@ -85,39 +85,29 @@ A minimal example of using an existing configuration.nix: darwin.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, darwin, nixpkgs }: { + outputs = inputs@{ self, darwin, nixpkgs }: { darwinConfigurations."Johns-MacBook" = darwin.lib.darwinSystem { - system = "x86_64-darwin"; modules = [ ./configuration.nix ]; }; }; } ``` -Inputs from the flake can also be passed to `darwinSystem`. These inputs are then +Inputs from the flake can also be passed into `darwinSystem`. These inputs are then accessible as an argument `inputs`, similar to `pkgs` and `lib`, inside the configuration. ```nix +# in flake.nix darwin.lib.darwinSystem { - system = "x86_64-darwin"; modules = [ ./configuration.nix ]; - inputs = { inherit darwin dotfiles nixpkgs; }; + specialArgs = { inherit inputs; }; } -# in configuration.nix: -{ pkgs, lib, inputs }: -# inputs.darwin, inputs.dotfiles, and inputs.nixpkgs can be accessed here ``` -Alternatively, `specialArgs` could be used: - ```nix -darwin.lib.darwinSystem { - system = "x86_64-darwin"; - modules = [ ./configuration.nix ]; - specialArgs = { inherit darwin dotfiles nixpkgs; }; -} -# in configuration.nix: -{ pkgs, lib, darwin, dotfiles, nixpkgs }: +# in configuration.nix +{ pkgs, lib, inputs }: +# inputs.self, inputs.darwin, and inputs.nixpkgs can be accessed here ``` Since the installer doesn't work with flakes out of the box yet, nix-darwin will need to diff --git a/default.nix b/default.nix index 11c686bb..7c7e06b2 100644 --- a/default.nix +++ b/default.nix @@ -6,19 +6,16 @@ }: let - evalConfig = import ./eval-config.nix { inherit lib; }; - - eval = evalConfig { - inherit system; - modules = [ configuration nixpkgsRevisionModule ]; - inputs = { inherit nixpkgs; }; + eval = import ./eval-config.nix { + inherit lib; + modules = [ + configuration + { nixpkgs.source = lib.mkDefault nixpkgs; } + ] ++ lib.optional (system != null) { + nixpkgs.system = lib.mkDefault system; + }; }; - nixpkgsRevisionModule = - if nixpkgs?rev && lib.isString nixpkgs.rev - then { system.nixpkgsRevision = nixpkgs.rev; } - else { }; - # The source code of this repo needed by the [un]installers. nix-darwin = lib.cleanSource ( lib.cleanSourceWith { diff --git a/eval-config.nix b/eval-config.nix index 2beb1212..9663849a 100644 --- a/eval-config.nix +++ b/eval-config.nix @@ -1,13 +1,5 @@ -{ lib }: -let - nixpkgs-lib = lib; -in - -{ system ? builtins.currentSystem or "x86_64-darwin" -, pkgs ? null -, lib ? nixpkgs-lib +{ lib , modules -, inputs , baseModules ? import ./modules/module-list.nix , specialArgs ? { } , check ? true @@ -18,26 +10,13 @@ let _file = ./eval-config.nix; config = { _module.args = { - inherit baseModules inputs modules; + inherit baseModules modules; }; }; }; - pkgsModule = { config, inputs, ... }: { - _file = ./eval-config.nix; - config = { - _module.args.pkgs = lib.mkIf (pkgs != null) (lib.mkForce pkgs); - - nixpkgs.source = lib.mkDefault inputs.nixpkgs; - - # This permits the configuration to override the passed-in - # system. - nixpkgs.system = lib.mkDefault system; - }; - }; - - eval = lib.evalModules (builtins.removeAttrs args [ "lib" "inputs" "pkgs" "system" ] // { - modules = modules ++ [ argsModule pkgsModule ] ++ baseModules; + eval = lib.evalModules (builtins.removeAttrs args [ "lib" ] // { + modules = modules ++ [ argsModule ] ++ baseModules; specialArgs = { modulesPath = builtins.toString ./modules; } // specialArgs; }); in diff --git a/flake.nix b/flake.nix index 38056aea..e0c9c7ef 100644 --- a/flake.nix +++ b/flake.nix @@ -4,22 +4,36 @@ outputs = { self, nixpkgs }: { lib = { - # TODO handle multiple architectures. - evalConfig = import ./eval-config.nix { inherit (nixpkgs) lib; }; + evalConfig = import ./eval-config.nix; - darwinSystem = - { modules, inputs ? { } - , system ? throw "darwin.lib.darwinSystem now requires 'system' to be passed explicitly" - , ... - }@args: - self.lib.evalConfig (args // { - inherit system; - inputs = { inherit nixpkgs; darwin = self; } // inputs; - modules = modules ++ [ self.darwinModules.flakeOverrides ]; - }); + darwinSystem = args@{ modules, ... }: self.lib.evalConfig ( + { inherit (nixpkgs) lib; } + // nixpkgs.lib.optionalAttrs (args ? pkgs) { inherit (args.pkgs) lib; } + // builtins.removeAttrs args [ "system" "pkgs" "inputs" ] + // { + modules = modules + ++ nixpkgs.lib.optional (args ? pkgs) ({ lib, ... }: { + _module.args.pkgs = lib.mkForce args.pkgs; + }) + # Backwards compatibility shim; TODO: warn? + ++ nixpkgs.lib.optional (args ? system) ({ lib, ... }: { + nixpkgs.system = lib.mkDefault args.system; + }) + # Backwards compatibility shim; TODO: warn? + ++ nixpkgs.lib.optional (args ? inputs) { + _module.args.inputs = args.inputs; + } + ++ [ ({ lib, ... }: { + nixpkgs.source = lib.mkDefault nixpkgs; + + system.checks.verifyNixPath = lib.mkDefault false; + + system.darwinVersionSuffix = ".${self.shortRev or "dirty"}"; + system.darwinRevision = lib.mkIf (self ? rev) self.rev; + }) ]; + }); }; - darwinModules.flakeOverrides = ./modules/system/flake-overrides.nix; darwinModules.hydra = ./modules/examples/hydra.nix; darwinModules.lnl = ./modules/examples/lnl.nix; darwinModules.ofborg = ./modules/examples/ofborg.nix; @@ -32,8 +46,10 @@ checks = nixpkgs.lib.genAttrs ["aarch64-darwin" "x86_64-darwin"] (system: let simple = self.lib.darwinSystem { - inherit system; - modules = [ self.darwinModules.simple ]; + modules = [ + self.darwinModules.simple + { nixpkgs.hostPlatform = system; } + ]; }; in { simple = simple.system; diff --git a/modules/examples/flake/flake.nix b/modules/examples/flake/flake.nix index 0ada8524..bacdcf55 100644 --- a/modules/examples/flake/flake.nix +++ b/modules/examples/flake/flake.nix @@ -1,9 +1,9 @@ { - description = "Example darwin system flake"; + description = "Example Darwin system flake"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs"; - darwin.url = "github:lnl7/nix-darwin"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs"; }; @@ -30,6 +30,9 @@ # Used for backwards compatibility, please read the changelog before changing. # $ darwin-rebuild changelog system.stateVersion = 4; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "x86_64-darwin"; }; in { @@ -37,7 +40,6 @@ # $ darwin-rebuild build --flake .#simple darwinConfigurations."simple" = darwin.lib.darwinSystem { modules = [ configuration ]; - system = "x86_64-darwin"; }; # Expose the package set, including overlays, for convenience. diff --git a/modules/system/flake-overrides.nix b/modules/system/flake-overrides.nix deleted file mode 100644 index df3eb168..00000000 --- a/modules/system/flake-overrides.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib, inputs, ... }: - -with lib; - -let - inherit (inputs) darwin nixpkgs; -in - -{ - config = { - system.checks.verifyNixPath = mkDefault false; - system.checks.verifyNixChannels = mkDefault false; - - system.darwinVersionSuffix = ".${darwin.shortRev or "dirty"}"; - system.darwinRevision = mkIf (darwin ? rev) darwin.rev; - - system.nixpkgsVersionSuffix = ".${substring 0 8 (nixpkgs.lastModifiedDate or nixpkgs.lastModified or "19700101")}.${nixpkgs.shortRev or "dirty"}"; - system.nixpkgsRevision = mkIf (nixpkgs ? rev) nixpkgs.rev; - }; -}