diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 98246cf38..1f15885f3 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -9,7 +9,11 @@ on: jobs: check: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v3 diff --git a/default.nix b/default.nix index 83c6b89e4..664f25f7b 100644 --- a/default.nix +++ b/default.nix @@ -7,12 +7,11 @@ let sha256 = lock.nodes.flake-compat.locked.narHash; } ) - { src = ./.; } - ) defaultNix; + { src = ./.; }) defaultNix; in - # Pass this flake as inputs.digga - defaultNix // { - inputs = defaultNix.inputs // { digga = defaultNix; }; - shell = import ./devShell.nix { }; - } +# Pass this flake as inputs.digga +defaultNix // { + inputs = defaultNix.inputs // { digga = defaultNix; }; + shell = import ./devShell.nix { }; +} diff --git a/deprecated.nix b/deprecated.nix index 66ef2e010..8b3e0702f 100644 --- a/deprecated.nix +++ b/deprecated.nix @@ -1,4 +1,4 @@ -{ lib, flake-utils-plus, internal-modules, importers, nixosModules }: +{ lib, importers }: lib.warn '' You are accessing a deprecated item of the digga lib. Please update timely, it will be remove soon. diff --git a/devShell.nix b/devShell.nix index a656db7ad..84ad08fba 100644 --- a/devShell.nix +++ b/devShell.nix @@ -2,9 +2,10 @@ , inputs ? (import ./.).inputs }: let - pkgs = inputs.nixpkgs.legacyPackages.${system}; - devshell = import inputs.devshell { inherit pkgs system; }; + unstablePkgs = inputs.nixpkgs-unstable.legacyPackages.${system}; + devshell = import inputs.devshell { inherit system; }; + nixBin = "${unstablePkgs.nix}/bin/nix"; withCategory = category: attrset: attrset // { inherit category; }; utils = withCategory "utils"; @@ -79,9 +80,9 @@ let digga_fixture test -f flake.lock && lockfile_present=$? || true - ${pkgs.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?; - ${pkgs.nixUnstable}/bin/nix flake show "$@" - ${pkgs.nixUnstable}/bin/nix flake check "$@" + ${nixBin} flake lock --update-input digga "$@"; lockfile_updated=$?; + ${nixBin} flake show "$@" + ${nixBin} flake check "$@" cleanup ''; @@ -93,7 +94,8 @@ devshell.mkShell { packages = with pkgs; [ fd nixpkgs-fmt - nixUnstable + # Use the latest stable version of nix + unstablePkgs.nix ]; env = [ diff --git a/doc/api-reference-channels.md b/doc/api-reference-channels.md index 9fbc3e7f8..533e6e917 100755 --- a/doc/api-reference-channels.md +++ b/doc/api-reference-channels.md @@ -57,7 +57,7 @@ nix flake ## channels.\.overlays overlays to apply to this channel these will get exported under the 'overlays' flake output -as \/\ and any overlay pulled from ${inputs} +as \/\ and any overlay pulled from \ will be filtered out @@ -73,3 +73,19 @@ list of valid Nixpkgs overlay or path convertible to its or anything convertible +## channels.\.patches +patches to apply to this channel + + +*_Type_*: +list of paths + + +*_Default_* +``` +[] +``` + + + + diff --git a/doc/api-reference-home.md b/doc/api-reference-home.md index 8d3b05535..0ab62f360 100755 --- a/doc/api-reference-home.md +++ b/doc/api-reference-home.md @@ -101,54 +101,6 @@ list of valid modules or anything convertible to it or path convertible to it -## home.profiles -WARNING: The 'suites' and `profiles` options have been deprecated, you can now create -both with the importables option. `rakeLeaves` can be used to create profiles and -by passing a module or `rec` set to `importables`, suites can access profiles. -Example: -``` -importables = rec { - profiles = digga.lib.rakeLeaves ./profiles; - suites = with profiles; { }; -} -``` -See https://github.com/divnix/digga/pull/30 for more details - - -*_Type_*: -list of paths or path convertible to it - - -*_Default_* -``` -[] -``` - - - - -## home.suites -WARNING: The 'suites' and `profiles` options have been deprecated, you can now create -both with the importables option. `rakeLeaves` can be used to create profiles and -by passing a module or `rec` set to `importables`, suites can access profiles. -Example: -``` -importables = rec { - profiles = digga.lib.rakeLeaves ./profiles; - suites = with profiles; { }; -} -``` -See https://github.com/divnix/digga/pull/30 for more details - - -*_Type_*: -function that evaluates to a(n) attrs or path convertible to it - - - - - - ## home.users HM users that can be deployed portably without a host. diff --git a/doc/api-reference-nixos.md b/doc/api-reference-nixos.md index 6d2a8d673..7428b161a 100755 --- a/doc/api-reference-nixos.md +++ b/doc/api-reference-nixos.md @@ -232,51 +232,3 @@ null -## nixos.profiles -WARNING: The 'suites' and `profiles` options have been deprecated, you can now create -both with the importables option. `rakeLeaves` can be used to create profiles and -by passing a module or `rec` set to `importables`, suites can access profiles. -Example: -``` -importables = rec { - profiles = digga.lib.rakeLeaves ./profiles; - suites = with profiles; { }; -} -``` -See https://github.com/divnix/digga/pull/30 for more details - - -*_Type_*: -list of paths or path convertible to it - - -*_Default_* -``` -[] -``` - - - - -## nixos.suites -WARNING: The 'suites' and `profiles` options have been deprecated, you can now create -both with the importables option. `rakeLeaves` can be used to create profiles and -by passing a module or `rec` set to `importables`, suites can access profiles. -Example: -``` -importables = rec { - profiles = digga.lib.rakeLeaves ./profiles; - suites = with profiles; { }; -} -``` -See https://github.com/divnix/digga/pull/30 for more details - - -*_Type_*: -function that evaluates to a(n) attrs or path convertible to it - - - - - - diff --git a/doc/api-reference.md b/doc/api-reference.md index 41694c24c..47eb12848 100755 --- a/doc/api-reference.md +++ b/doc/api-reference.md @@ -5,6 +5,7 @@ - [Home](./api-reference-home.md) - [Devshell](./api-reference-devshell.md) - [NixOS](./api-reference-nixos.md) +- [Darwin](./api-reference-darwin.md) ## channelsConfig nixpkgs config for all channels @@ -39,7 +40,7 @@ The builder gets passed an attrset of all channels *_Type_*: -function that evaluates to a(n) attrs or path convertible to it +function that evaluates to a(n) attribute set or path convertible to it *_Default_* diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 82de770b6..4c89496f3 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -10,6 +10,13 @@ # Track channels with commits tested and built by hydra nixos.url = "github:nixos/nixpkgs/nixos-21.11"; latest.url = "github:nixos/nixpkgs/nixos-unstable"; + # For darwin hosts: it can be helpful to track this darwin-specific stable + # channel equivalent to the `nixos-*` channels for NixOS. For one, these + # channels are more likely to provide cached binaries for darwin systems. + # But, perhaps even more usefully, it provides a place for adding + # darwin-specific overlays and packages which could otherwise cause build + # failures on Linux systems. + nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; digga.url = "github:divnix/digga"; digga.inputs.nixpkgs.follows = "nixos"; @@ -25,7 +32,7 @@ home.inputs.nixpkgs.follows = "nixos"; darwin.url = "github:LnL7/nix-darwin"; - darwin.inputs.nixpkgs.follows = "nixos"; + darwin.inputs.nixpkgs.follows = "nixpkgs-darwin-stable"; deploy.url = "github:serokell/deploy-rs"; deploy.inputs.nixpkgs.follows = "nixos"; @@ -55,6 +62,7 @@ , agenix , nvfetcher , deploy + , nixpkgs , ... } @ inputs: digga.lib.mkFlake @@ -66,12 +74,11 @@ channels = { nixos = { imports = [ (digga.lib.importOverlays ./overlays) ]; - overlays = [ - nur.overlay - agenix.overlay - nvfetcher.overlay - ./pkgs/default.nix - ]; + overlays = [ ]; + }; + nixpkgs-darwin-stable = { + imports = [ (digga.lib.importOverlays ./overlays) ]; + overlays = [ ]; }; latest = { }; }; @@ -85,6 +92,12 @@ our = self.lib; }); }) + + nur.overlay + agenix.overlay + nvfetcher.overlay + + (import ./pkgs) ]; nixos = { @@ -102,9 +115,9 @@ ]; }; - imports = [ (digga.lib.importHosts ./hosts) ]; + imports = [ (digga.lib.importHosts ./hosts/nixos) ]; hosts = { - /* set host specific properties here */ + /* set host-specific properties here */ NixOS = { }; }; importables = rec { @@ -112,7 +125,35 @@ users = digga.lib.rakeLeaves ./users; }; suites = with profiles; rec { - base = [ core users.nixos users.root ]; + base = [ core.nixos users.nixos users.root ]; + }; + }; + }; + + darwin = { + hostDefaults = { + system = "x86_64-darwin"; + channelName = "nixpkgs-darwin-stable"; + imports = [ (digga.lib.importExportableModules ./modules) ]; + modules = [ + { lib.our = self.lib; } + digga.darwinModules.nixConfig + home.darwinModules.home-manager + agenix.nixosModules.age + ]; + }; + + imports = [ (digga.lib.importHosts ./hosts/darwin) ]; + hosts = { + /* set host-specific properties here */ + Mac = { }; + }; + importables = rec { + profiles = digga.lib.rakeLeaves ./profiles // { + users = digga.lib.rakeLeaves ./users; + }; + suites = with profiles; rec { + base = [ core.darwin users.darwin ]; }; }; }; @@ -127,13 +168,34 @@ }; }; users = { + # TODO: does this naming convention still make sense with darwin support? + # + # - it doesn't make sense to make a 'nixos' user available on + # darwin, and vice versa + # + # - the 'nixos' user might have special significance as the default + # user for fresh systems + # + # - perhaps a system-agnostic home-manager user is more appropriate? + # something like 'primaryuser'? + # + # all that said, these only exist within the `hmUsers` attrset, so + # it could just be left to the developer to determine what's + # appropriate. after all, configuring these hm users is one of the + # first steps in customizing the template. nixos = { suites, ... }: { imports = suites.base; }; + darwin = { suites, ... }: { imports = suites.base; }; }; # digga.lib.importers.rakeLeaves ./users/hm; }; devshell = ./shell; - homeConfigurations = digga.lib.mkHomeConfigurations self.nixosConfigurations; + # TODO: similar to the above note: does it make sense to make all of + # these users available on all systems? + homeConfigurations = digga.lib.mergeAny + (digga.lib.mkHomeConfigurations self.darwinConfigurations) + (digga.lib.mkHomeConfigurations self.nixosConfigurations) + ; deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { }; diff --git a/examples/devos/hosts/darwin/Mac.nix b/examples/devos/hosts/darwin/Mac.nix new file mode 100644 index 000000000..a44314ecc --- /dev/null +++ b/examples/devos/hosts/darwin/Mac.nix @@ -0,0 +1,6 @@ +{ config, pkgs, suites, ... }: + +{ + imports = with suites; + base; +} diff --git a/examples/devos/hosts/NixOS.nix b/examples/devos/hosts/nixos/NixOS.nix similarity index 100% rename from examples/devos/hosts/NixOS.nix rename to examples/devos/hosts/nixos/NixOS.nix diff --git a/examples/devos/hosts/bootstrap.nix b/examples/devos/hosts/nixos/bootstrap.nix similarity index 95% rename from examples/devos/hosts/bootstrap.nix rename to examples/devos/hosts/nixos/bootstrap.nix index d491855d6..575d95143 100644 --- a/examples/devos/hosts/bootstrap.nix +++ b/examples/devos/hosts/nixos/bootstrap.nix @@ -6,7 +6,7 @@ # interface that has the local link to the target machine imports = [ # profiles.networking - profiles.core + profiles.core.nixos profiles.users.root # make sure to configure ssh keys profiles.users.nixos ]; diff --git a/examples/devos/modules/hm-system-defaults.nix b/examples/devos/modules/hm-system-defaults.nix index 7b442a619..09afddc19 100644 --- a/examples/devos/modules/hm-system-defaults.nix +++ b/examples/devos/modules/hm-system-defaults.nix @@ -1,8 +1,11 @@ -{ config, ... }: { +{ config, pkgs, ... }: { home-manager.sharedModules = [ { home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; + # environment.sessionVariables is not currently available in nix-darwin + NIX_PATH = config.environment.sessionVariables.NIX_PATH + or config.environment.variables.NIX_PATH + ; }; xdg.configFile."nix/registry.json".text = config.environment.etc."nix/registry.json".text; diff --git a/examples/devos/overlays/overrides.nix b/examples/devos/overlays/overrides.nix index e35ad7e48..df8687df4 100644 --- a/examples/devos/overlays/overrides.nix +++ b/examples/devos/overlays/overrides.nix @@ -8,6 +8,7 @@ channels: final: prev: { discord element-desktop rage + nix-index nixpkgs-fmt qutebrowser signal-desktop diff --git a/examples/devos/profiles/core/default.nix b/examples/devos/profiles/core/common.nix similarity index 56% rename from examples/devos/profiles/core/default.nix rename to examples/devos/profiles/core/common.nix index c1aed3fac..beed6bc01 100644 --- a/examples/devos/profiles/core/default.nix +++ b/examples/devos/profiles/core/common.nix @@ -1,34 +1,28 @@ { self, config, lib, pkgs, ... }: -let inherit (lib) fileContents; + +let + inherit (lib) fileContents; + inherit (pkgs.stdenv.hostPlatform) isDarwin; in + { # Sets nrdxp.cachix.org binary cache which just speeds up some builds imports = [ ../cachix ]; - # For rage encryption, all hosts need a ssh key pair - services.openssh = { - enable = true; - openFirewall = lib.mkDefault false; - }; - - # This is just a representation of the nix default - nix.systemFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; - environment = { # Selection of sysadmin tools that can come in handy systemPackages = with pkgs; [ + # TODO: must come from unstable channel + # alejandra binutils coreutils curl direnv dnsutils - dosfstools fd git bottom - gptfdisk - iputils jq manix moreutils @@ -37,8 +31,6 @@ in ripgrep skim tealdeer - usbutils - utillinux whois ]; @@ -52,7 +44,10 @@ in ''; shellAliases = - let ifSudo = lib.mkIf config.security.sudo.enable; + let + # The `security.sudo.enable` option does not exist on darwin because + # sudo is always available. + ifSudo = lib.mkIf (isDarwin || config.security.sudo.enable); in { # quick cd @@ -69,6 +64,7 @@ in gi = "grep -i"; # internet ip + # TODO: explain this hard-coded IP address myip = "dig +short myip.opendns.com @208.67.222.222 2>&1"; # nix @@ -81,58 +77,30 @@ in nepl = "n repl ''"; srch = "ns nixos"; orch = "ns override"; - nrb = ifSudo "sudo nixos-rebuild"; mn = '' manix "" | grep '^# ' | sed 's/^# \(.*\) (.*/\1/;s/ (.*//;s/^# //' | sk --preview="manix '{}'" | xargs manix ''; - - # fix nixos-option - nixos-option = "nixos-option -I nixpkgs=${self}/lib/compat"; + top = "btm"; # sudo s = ifSudo "sudo -E "; si = ifSudo "sudo -i"; se = ifSudo "sudoedit"; - # top - top = "btm"; - - # systemd - ctl = "systemctl"; - stl = ifSudo "s systemctl"; - utl = "systemctl --user"; - ut = "systemctl --user start"; - un = "systemctl --user stop"; - up = ifSudo "s systemctl start"; - dn = ifSudo "s systemctl stop"; - jtl = "journalctl"; - }; }; - fonts = { - fonts = with pkgs; [ powerline-fonts dejavu_fonts ]; - - fontconfig.defaultFonts = { - - monospace = [ "DejaVu Sans Mono for Powerline" ]; - - sansSerif = [ "DejaVu Sans" ]; - - }; - }; + fonts.fonts = with pkgs; [ powerline-fonts dejavu_fonts ]; nix = { # Improve nix store disk usage - autoOptimiseStore = true; gc.automatic = true; - optimise.automatic = true; # Prevents impurities in builds useSandbox = true; - # give root and @wheel special privileges with nix + # Give root user and wheel group special Nix privileges. trustedUsers = [ "root" "@wheel" ]; # Generally useful nix option defaults @@ -145,18 +113,4 @@ in }; - programs.bash = { - # Enable starship - promptInit = '' - eval "$(${pkgs.starship}/bin/starship init bash)" - ''; - # Enable direnv, a tool for managing shell environments - interactiveShellInit = '' - eval "$(${pkgs.direnv}/bin/direnv hook bash)" - ''; - }; - - # Service that makes Out of Memory Killer more effective - services.earlyoom.enable = true; - } diff --git a/examples/devos/profiles/core/darwin.nix b/examples/devos/profiles/core/darwin.nix new file mode 100644 index 000000000..88123ebf4 --- /dev/null +++ b/examples/devos/profiles/core/darwin.nix @@ -0,0 +1,61 @@ +{ self, config, lib, pkgs, ... }: + +{ + imports = [ + ./common.nix + ]; + + # Recreate /run/current-system symlink after boot + services.activate-system.enable = true; + + services.nix-daemon.enable = true; + users.nix.configureBuildUsers = true; + + environment = { + + systemPackages = with pkgs; [ + m-cli + terminal-notifier + ]; + + darwinConfig = "${self}/lib/compat"; + + shellAliases = { + nrb = "sudo darwin-rebuild switch --flake"; + }; + + }; + + nix = { + + nixPath = [ + # TODO: This entry should be added automatically via FUP's + # `nix.linkInputs` and `nix.generateNixPathFromInputs` options, but + # currently that doesn't work because nix-darwin doesn't export packages, + # which FUP expects. + # + # This entry should be removed once the upstream issues are fixed. + # + # https://github.com/LnL7/nix-darwin/issues/277 + # https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/107 + "darwin=/etc/nix/inputs/darwin" + ]; + + # Administrative users on Darwin are part of this group. + trustedUsers = [ "@admin" ]; + + }; + + programs.bash = { + # nix-darwin's shell options are very different from those on nixos. there + # is no `promptInit` option, for example. so instead, we throw the prompt + # init line into `interactiveShellInit`. + # + # https://github.com/LnL7/nix-darwin/blob/master/modules/programs/bash/default.nix + interactiveShellInit = '' + eval "$(${pkgs.starship}/bin/starship init bash)" + eval "$(${pkgs.direnv}/bin/direnv hook bash)" + ''; + }; + +} diff --git a/examples/devos/profiles/core/nixos.nix b/examples/devos/profiles/core/nixos.nix new file mode 100644 index 000000000..8fac9f9ab --- /dev/null +++ b/examples/devos/profiles/core/nixos.nix @@ -0,0 +1,75 @@ +{ config, lib, pkgs, self, ... }: + +{ + imports = [ + ./common.nix + ]; + + # This is just a representation of the nix default + nix.systemFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; + + environment = { + + # Selection of sysadmin tools that can come in handy + systemPackages = with pkgs; [ + dosfstools + gptfdisk + iputils + usbutils + utillinux + ]; + + shellAliases = + let ifSudo = lib.mkIf config.security.sudo.enable; in + { + # nix + nrb = ifSudo "sudo nixos-rebuild"; + + # fix nixos-option for flake compat + nixos-option = "nixos-option -I nixpkgs=${self}/lib/compat"; + + # systemd + ctl = "systemctl"; + stl = ifSudo "s systemctl"; + utl = "systemctl --user"; + ut = "systemctl --user start"; + un = "systemctl --user stop"; + up = ifSudo "s systemctl start"; + dn = ifSudo "s systemctl stop"; + jtl = "journalctl"; + }; + }; + + fonts.fontconfig.defaultFonts = { + monospace = [ "DejaVu Sans Mono for Powerline" ]; + sansSerif = [ "DejaVu Sans" ]; + }; + + nix = { + # Improve nix store disk usage + autoOptimiseStore = true; + optimise.automatic = true; + allowedUsers = [ "@wheel" ]; + }; + + programs.bash = { + # Enable starship + promptInit = '' + eval "$(${pkgs.starship}/bin/starship init bash)" + ''; + # Enable direnv, a tool for managing shell environments + interactiveShellInit = '' + eval "$(${pkgs.direnv}/bin/direnv hook bash)" + ''; + }; + + # For rage encryption, all hosts need a ssh key pair + services.openssh = { + enable = true; + openFirewall = lib.mkDefault false; + }; + + # Service that makes Out of Memory Killer more effective + services.earlyoom.enable = true; + +} diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index 581aee9a7..684db2bf6 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -1,12 +1,22 @@ -{ pkgs, extraModulesPath, inputs, ... }: +{ pkgs, extraModulesPath, inputs, lib, ... }: let + inherit (pkgs) + agenix + cachix + editorconfig-checker + mdbook + nixUnstable + nixpkgs-fmt + nvfetcher-bin + ; + hooks = import ./hooks; pkgWithCategory = category: package: { inherit package category; }; + devos = pkgWithCategory "devos"; linter = pkgWithCategory "linter"; docs = pkgWithCategory "docs"; - devos = pkgWithCategory "devos"; in { @@ -30,26 +40,26 @@ in unset _PATH ''); - commands = with pkgs; [ + commands = [ (devos nixUnstable) (devos agenix) + (devos inputs.deploy.packages.${pkgs.system}.deploy-rs) + { category = "devos"; - name = pkgs.nvfetcher-bin.pname; - help = pkgs.nvfetcher-bin.meta.description; - command = "cd $PRJ_ROOT/pkgs; ${pkgs.nvfetcher-bin}/bin/nvfetcher -c ./sources.toml $@"; + name = nvfetcher-bin.pname; + help = nvfetcher-bin.meta.description; + command = "cd $PRJ_ROOT/pkgs; ${nvfetcher-bin}/bin/nvfetcher -c ./sources.toml $@"; } + (linter nixpkgs-fmt) (linter editorconfig-checker) - # (docs python3Packages.grip) too many deps + (docs mdbook) - (devos inputs.deploy.packages.${pkgs.system}.deploy-rs) ] - ++ lib.optional - (system != "i686-linux") + ++ lib.optional (!pkgs.stdenv.buildPlatform.isi686) (devos cachix) - ++ lib.optional - (system != "aarch64-darwin") + ++ lib.optional (pkgs.stdenv.hostPlatform.isLinux && !pkgs.stdenv.buildPlatform.isDarwin) (devos inputs.nixos-generators.defaultPackage.${pkgs.system}) ; } diff --git a/examples/devos/users/darwin/default.nix b/examples/devos/users/darwin/default.nix new file mode 100644 index 000000000..a268b8a87 --- /dev/null +++ b/examples/devos/users/darwin/default.nix @@ -0,0 +1,8 @@ +{ hmUsers, ... }: +{ + home-manager.users = { inherit (hmUsers) darwin; }; + + users.users.darwin = { + description = "default"; + }; +} diff --git a/examples/groupByConfig/darwin/Darwinia.nix b/examples/groupByConfig/darwin/Darwinia.nix new file mode 100644 index 000000000..a1d9a82ec --- /dev/null +++ b/examples/groupByConfig/darwin/Darwinia.nix @@ -0,0 +1,12 @@ +{ lib, pkgs, config, suites, ... }: { + # TODO: remove manually-imported suites and profiles once custom test support + # is added for darwin + imports = with suites; + base; + + # On Darwin, admins are added to the `admin` group. + nix.trustedUsers = [ "@admin" "sosumi" ]; + + # https://daiderd.com/nix-darwin/manual/index.html#opt-system.stateVersion + system.stateVersion = 4; +} diff --git a/examples/groupByConfig/darwin/default.nix b/examples/groupByConfig/darwin/default.nix new file mode 100644 index 000000000..d748ac0e2 --- /dev/null +++ b/examples/groupByConfig/darwin/default.nix @@ -0,0 +1,27 @@ +{ self, inputs, ... }: + +let + inherit (inputs.digga.lib) allProfilesTest; +in + +{ + hostDefaults = { + channelName = "nixpkgs-darwin-stable"; + }; + + hosts = { + Darwinia = { + modules = [ ./Darwinia.nix ]; + + # TODO: add custom test support for darwin hosts + # tests = [ allProfilesTest ]; + tests = [ ]; + }; + }; + + importables = rec { + suites = rec { + base = [ ]; + }; + }; +} diff --git a/examples/groupByConfig/flake.nix b/examples/groupByConfig/flake.nix index 350009b48..db966de38 100644 --- a/examples/groupByConfig/flake.nix +++ b/examples/groupByConfig/flake.nix @@ -1,27 +1,49 @@ { description = "A DevOS example. And also a digga test bed."; - inputs = - { - # Track channels with commits tested and built by hydra - nixos.url = "github:nixos/nixpkgs/nixos-21.11"; - - digga = { - url = "github:divnix/digga"; - inputs.nixpkgs.follows = "nixos"; - }; - home.url = "github:nix-community/home-manager"; - home.inputs.nixpkgs.follows = "nixos"; - }; + inputs = { + # Track channels with commits tested and built by hydra + nixos.url = "github:nixos/nixpkgs/nixos-21.11"; + + # For darwin hosts: it can be helpful to track this darwin-specific stable + # channel equivalent to the `nixos-*` channels for NixOS. For one, these + # channels are more likely to provide cached binaries for darwin systems. + # But, perhaps even more usefully, it provides a place for adding + # darwin-specific overlays and packages which could otherwise cause build + # failures on Linux systems. + nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; + + digga.url = "github:divnix/digga"; + digga.inputs.nixpkgs.follows = "nixos"; - outputs = inputs @ { self, nixos, digga, home }: + darwin.url = "github:LnL7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs-darwin-stable"; + + home.url = "github:nix-community/home-manager/release-21.11"; + home.inputs.nixpkgs.follows = "nixos"; + }; + + outputs = + inputs @ { self + , nixos + , nixpkgs + , nixpkgs-darwin-stable + , darwin + , digga + , home + , ... + }: digga.lib.mkFlake { inherit self inputs; - channels.nixos = { }; + channels = { + nixos = { }; + nixpkgs-darwin-stable = { }; + }; nixos = ./nixos; + darwin = ./darwin; home = ./home; devshell = ./devshell; diff --git a/examples/groupByConfig/nixos/default.nix b/examples/groupByConfig/nixos/default.nix index 54b42a6e6..eed4a9e5e 100644 --- a/examples/groupByConfig/nixos/default.nix +++ b/examples/groupByConfig/nixos/default.nix @@ -1,13 +1,21 @@ { self, inputs, ... }: + let inherit (inputs.digga.lib) allProfilesTest; in + { - hostDefaults.channelName = "nixos"; + hostDefaults = { + channelName = "nixos"; + }; + hosts = { - Morty.modules = [ ./Morty.nix ]; - Morty.tests = [ allProfilesTest ]; + Morty = { + modules = [ ./Morty.nix ]; + tests = [ allProfilesTest ]; + }; }; + importables = rec { suites = rec { base = [ ]; diff --git a/examples/hmOnly/flake.nix b/examples/hmOnly/flake.nix index d7904f768..8002648e3 100644 --- a/examples/hmOnly/flake.nix +++ b/examples/hmOnly/flake.nix @@ -1,15 +1,14 @@ { description = "A DevOS example. And also a digga test bed."; - inputs = - { - nixos.url = "github:nixos/nixpkgs/nixos-21.11"; - digga.url = "github:divnix/digga"; - digga.inputs.nixpkgs.follows = "nixos"; - digga.inputs.home-manager.follows = "home"; - home.url = "github:nix-community/home-manager/release-21.11"; - home.inputs.nixpkgs.follows = "nixos"; - }; + inputs = { + nixos.url = "github:nixos/nixpkgs/nixos-21.11"; + digga.url = "github:divnix/digga"; + digga.inputs.nixpkgs.follows = "nixos"; + digga.inputs.home-manager.follows = "home"; + home.url = "github:nix-community/home-manager/release-21.11"; + home.inputs.nixpkgs.follows = "nixos"; + }; outputs = inputs @ { self, nixos, digga, home }: digga.lib.mkFlake { diff --git a/flake.lock b/flake.lock index 28fbdafce..693a5b0eb 100644 --- a/flake.lock +++ b/flake.lock @@ -15,20 +15,40 @@ "type": "github" } }, + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1650976225, + "narHash": "sha256-PGM65SQHS63Dd5MmLJo3GJsZP9lJVZmpWxluQoG1Dt8=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "bb3baef6e115ae47bc2ab4973bd3a486488485b0", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, "deploy": { "inputs": { "flake-compat": "flake-compat", "nixpkgs": [ - "latest" + "nixpkgs" ], "utils": "utils" }, "locked": { - "lastModified": 1632822684, - "narHash": "sha256-lt7eayYmgsD5OQwpb1XYfHpxttn43bWo7G7hIJs+zJw=", + "lastModified": 1648475189, + "narHash": "sha256-gAGAS6IagwoUr1B0ohE3iR6sZ8hP4LSqzYLC8Mq3WGU=", "owner": "serokell", "repo": "deploy-rs", - "rev": "9a02de4373e0ec272d08a417b269a28ac8b961b4", + "rev": "83e0c78291cd08cb827ba0d553ad9158ae5a95c3", "type": "github" }, "original": { @@ -38,12 +58,18 @@ } }, "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1637575296, - "narHash": "sha256-ZY8YR5u8aglZPe27+AJMnPTG6645WuavB+w0xmhTarw=", + "lastModified": 1650389807, + "narHash": "sha256-GFRBdHMJ/T/ifaE2GS58RWpxyufH0LqI3oGS6oWAnHk=", "owner": "numtide", "repo": "devshell", - "rev": "0e56ef21ba1a717169953122c7415fa6a8cd2618", + "rev": "5a53bbf3eb4c908d83884d725a86b3a3bde35979", "type": "github" }, "original": { @@ -55,11 +81,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1627913399, - "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", + "lastModified": 1648199409, + "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=", "owner": "edolstra", "repo": "flake-compat", - "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", + "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03", "type": "github" }, "original": { @@ -71,11 +97,11 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1641205782, - "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", "owner": "edolstra", "repo": "flake-compat", - "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", "type": "github" }, "original": { @@ -86,11 +112,11 @@ }, "flake-utils": { "locked": { - "lastModified": 1638122382, - "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", "owner": "numtide", "repo": "flake-utils", - "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", "type": "github" }, "original": { @@ -101,14 +127,14 @@ }, "flake-utils-plus": { "inputs": { - "flake-utils": "flake-utils" + "flake-utils": "flake-utils_2" }, "locked": { - "lastModified": 1639385028, - "narHash": "sha256-oqorKz3mwf7UuDJwlbCEYCB2LfcWLL0DkeCWhRIL820=", + "lastModified": 1647259887, + "narHash": "sha256-yEkMbEHVO9qydluQ3uHGWX1PkfZhgDKxnd1rhZYZ72w=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "be1be083af014720c14f3b574f57b6173b4915d0", + "rev": "06dba5f3b4fa2cc0bfc98ce9cd6f9a4d8db11d46", "type": "github" }, "original": { @@ -117,6 +143,21 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -124,11 +165,11 @@ ] }, "locked": { - "lastModified": 1637917557, - "narHash": "sha256-3u5bLyGn5NUG3RJA7/v1Bqa/QCFGqp/01Bh/4REf9m4=", + "lastModified": 1649887911, + "narHash": "sha256-Af0Ppb1RZ7HWuxUvF0/O7h3cy8tqU2eKFyVwyA1ZD+w=", "owner": "nix-community", "repo": "home-manager", - "rev": "4daff26495ca9ac67476cba8cf15c3e36d91ab18", + "rev": "7244c6715cb8f741f3b3e1220a9279e97b2ed8f5", "type": "github" }, "original": { @@ -140,11 +181,11 @@ }, "latest": { "locked": { - "lastModified": 1638198142, - "narHash": "sha256-plU9b8r4St6q4U7VHtG9V7oF8k9fIpfXl/KDaZLuY9k=", + "lastModified": 1650701402, + "narHash": "sha256-XKfstdtqDg+O+gNBx1yGVKWIhLgfEDg/e2lvJSsp9vU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8a308775674e178495767df90c419425474582a1", + "rev": "bc41b01dd7a9fdffd32d9b03806798797532a5fe", "type": "github" }, "original": { @@ -156,11 +197,11 @@ }, "nixlib": { "locked": { - "lastModified": 1641688481, - "narHash": "sha256-6L+EU12xLDHby7y8elgFtRKVBxix+7qV8DhVgXqrKZo=", + "lastModified": 1650761098, + "narHash": "sha256-pllwIuJiY3HDOg5JfO19NnnoHQZ8ZZtrAJMQ9/BX3Y0=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "f697717b3d3a074ffc16c8c8227504f0db292886", + "rev": "50b30201342fd191180fa95948ee4ba4c1e67183", "type": "github" }, "original": { @@ -171,11 +212,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1648648646, - "narHash": "sha256-pHAq/GvsP7zRHkUTCs+4d31C0IEtTIuC6/TFASIA+zg=", + "lastModified": 1650728030, + "narHash": "sha256-VfCYsC/0mZQlQqsXf5o5Cib1ncJQ5l7WHN7hEIMmZNw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "efea022d6fe0da84aa6613d4ddeafb80de713457", + "rev": "5fb3a179605141bfa4c9c423f9b1c33658b059c8", "type": "github" }, "original": { @@ -185,9 +226,26 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1650726686, + "narHash": "sha256-hE5PCqQlsdgWH3AUTwesvjZWs5ZUZ8SjMS5cnFB6W54=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3c0f57e36ed0cf9947281e3b31f1bebb7ce5d4a1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "blank": "blank", + "darwin": "darwin", "deploy": "deploy", "devshell": "devshell", "flake-compat": "flake-compat_2", @@ -195,16 +253,17 @@ "home-manager": "home-manager", "latest": "latest", "nixlib": "nixlib", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" } }, "utils": { "locked": { - "lastModified": 1638122382, - "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f3c32b947..1862d6abe 100644 --- a/flake.nix +++ b/flake.nix @@ -10,17 +10,24 @@ # Track channels with commits tested and built by hydra nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; latest.url = "github:nixos/nixpkgs/nixos-unstable"; - + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixlib.url = "github:nix-community/nixpkgs.lib"; + + # TODO: remove -- no references blank.url = "github:divnix/blank"; deploy.url = "github:serokell/deploy-rs"; - deploy.inputs.nixpkgs.follows = "latest"; + deploy.inputs.nixpkgs.follows = "nixpkgs"; home-manager.url = "github:nix-community/home-manager/release-21.11"; home-manager.inputs.nixpkgs.follows = "nixlib"; + darwin.url = "github:LnL7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; + devshell.url = "github:numtide/devshell"; + devshell.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; flake-compat = { @@ -37,6 +44,7 @@ , deploy , devshell , flake-utils-plus + , darwin , home-manager , ... }@inputs: @@ -52,6 +60,10 @@ inherit (nixlib) lib; }; + collectors = import ./src/collectors.nix { + inherit (nixlib) lib; + }; + generators = import ./src/generators.nix { inherit (nixlib) lib; inherit deploy; @@ -62,7 +74,16 @@ mkFlake' = import ./src/mkFlake { inherit (nixlib) lib; inherit (flake-utils-plus.inputs) flake-utils; - inherit deploy devshell home-manager flake-utils-plus internal-modules tests; + inherit + collectors + darwin + deploy + devshell + home-manager + flake-utils-plus + internal-modules + tests + ; }; in { @@ -86,13 +107,10 @@ # .. it's adopted by a growing number of projects. # Please consider adopting it if you want to help to improve flakes. - - # DEPRECATED - will be removed timely deprecated = import ./deprecated.nix { inherit (nixlib) lib; - inherit (self) nixosModules; - inherit flake-utils-plus internal-modules importers; + inherit importers; }; in @@ -101,11 +119,15 @@ # what you came for ... lib = { inherit (flake-utils-plus.inputs.flake-utils.lib) defaultSystems eachSystem eachDefaultSystem filterPackages; - inherit (flake-utils-plus.lib) exportModules exportOverlays exportPackages; + inherit (flake-utils-plus.lib) exportModules exportOverlays exportPackages mergeAny; inherit mkFlake; inherit (tests) mkTest allProfilesTest; inherit (importers) flattenTree rakeLeaves importOverlays importExportableModules importHosts; inherit (generators) mkDeployNodes mkHomeConfigurations; + inherit (collectors) + collectHosts + collectHostsOnSystem + ; # DEPRECATED - will be removed soon inherit (deprecated) @@ -116,7 +138,8 @@ # a little extra service ... overlays = import ./overlays { inherit inputs; }; - nixosModules = import ./modules; + nixosModules = import ./modules/nixos-modules.nix; + darwinModules = import ./modules/darwin-modules.nix; defaultTemplate = self.templates.devos; templates.devos.path = ./examples/devos; diff --git a/jobs/default.nix b/jobs/default.nix index 91a10c566..03662a77d 100644 --- a/jobs/default.nix +++ b/jobs/default.nix @@ -30,6 +30,7 @@ in - [Home](./api-reference-home.md) - [Devshell](./api-reference-devshell.md) - [NixOS](./api-reference-nixos.md) + - [Darwin](./api-reference-darwin.md) ${( pkgs.nixosOptionsDoc { options = { @@ -60,5 +61,8 @@ in mkApiReferenceNixos = mkDocPartMd "nixos" "NixOS API Container" '' Configure your nixos modules, profiles & suites. ''; + mkApiReferenceDarwin = mkDocPartMd "darwin" "Darwin API Container" '' + Configure your darwin/macOS modules, profiles & suites. + ''; } diff --git a/modules/bootstrap-iso.nix b/modules/bootstrap-iso.nix index d7a11ca38..72fcb6faa 100644 --- a/modules/bootstrap-iso.nix +++ b/modules/bootstrap-iso.nix @@ -3,7 +3,7 @@ let let net = config.networking; fqdn = - if net.domain != null + if (net ? domain) && (net.domain != null) then "${net.hostName}.${net.domain}" else net.hostName; in diff --git a/modules/darwin-modules.nix b/modules/darwin-modules.nix new file mode 100644 index 000000000..1c779276c --- /dev/null +++ b/modules/darwin-modules.nix @@ -0,0 +1,3 @@ +{ + nixConfig = import ./nix-config.nix; +} diff --git a/modules/default.nix b/modules/nixos-modules.nix similarity index 100% rename from modules/default.nix rename to modules/nixos-modules.nix diff --git a/overlays/default.nix b/overlays/default.nix index a03c1f272..7f0c7a0f4 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,3 +1 @@ -{ inputs }: { - -} +{ inputs }: { } diff --git a/src/collectors.nix b/src/collectors.nix new file mode 100644 index 000000000..37c428a50 --- /dev/null +++ b/src/collectors.nix @@ -0,0 +1,34 @@ +{ lib }: +let + collectHosts = nixosConfigurations: darwinConfigurations: + /** + Synopsis: collectHosts _nixosConfigurations_ _darwinConfigurations_ + + Collect all hosts across NixOS and Darwin configurations, validating for + unique hostnames to prevent collisions. + **/ + (nixosConfigurations // lib.mapAttrs + (name: value: + if builtins.hasAttr name nixosConfigurations + then + throw '' + Hostnames must be unique across all platforms! Found a duplicate host config for '${name}'. + '' + else value + ) + darwinConfigurations); +in +{ + inherit collectHosts; + + collectHostsOnSystem = hostConfigurations: system: + /** + Synopsis: collectHostsOnSystem _hostConfigurations_ _system_ + + Filter a set of host configurations to those matching a given system. + **/ + let + systemSieve = _: host: host.config.nixpkgs.system == system; + in + lib.filterAttrs systemSieve hostConfigurations; +} diff --git a/src/generators.nix b/src/generators.nix index e72c852b0..0011002a5 100644 --- a/src/generators.nix +++ b/src/generators.nix @@ -4,7 +4,7 @@ let let net = c.config.networking; fqdn = - if net.domain != null + if (net ? domain) && (net.domain != null) then "${net.hostName}.${net.domain}" else net.hostName; in @@ -12,12 +12,12 @@ let in { - mkHomeConfigurations = nixosConfigurations: + mkHomeConfigurations = systemConfigurations: /** - Synopsis: mkHomeConfigurations _nixosConfigurations_ + Synopsis: mkHomeConfigurations _systemConfigurations_ - Generate the `homeConfigurations` attribute expected by - `home-manager` cli from _nixosConfigurations_ in the form + Generate the `homeConfigurations` attribute expected by `home-manager` cli + from _nixosConfigurations_ or _darwinConfigurations_ in the form _user@hostname_. **/ let @@ -35,16 +35,24 @@ in ; mkHmConfigs = lib.foldl op { }; in - mkHmConfigs (builtins.attrValues nixosConfigurations); + mkHmConfigs (builtins.attrValues systemConfigurations); - mkDeployNodes = hosts: extraConfig: + mkDeployNodes = systemConfigurations: extraConfig: /** - Synopsis: mkNodes _nixosConfigurations_ + Synopsis: mkNodes _systemConfigurations_ _extraConfig_ Generate the `nodes` attribute expected by deploy-rs - where _nixosConfigurations_ are `nodes`. + where _systemConfigurations_ are `nodes`. + + _systemConfigurations_ should take the form of a flake's + _nixosConfigurations_. Note that deploy-rs does not currently support + deploying to darwin hosts. + + _extraConfig_, if specified, will be merged into each of the + nodes' configurations. + + Example _systemConfigurations_ input: - Example input: ``` { hostname-1 = { @@ -69,6 +77,6 @@ in }; } ) - hosts) + systemConfigurations) extraConfig; } diff --git a/src/mkFlake/default.nix b/src/mkFlake/default.nix index e5ee31d4f..8645b9448 100644 --- a/src/mkFlake/default.nix +++ b/src/mkFlake/default.nix @@ -1,4 +1,14 @@ -{ lib, deploy, devshell, home-manager, flake-utils-plus, flake-utils, internal-modules, tests } @ injectedDeps: +{ lib +, collectors +, darwin +, deploy +, devshell +, home-manager +, flake-utils-plus +, flake-utils +, internal-modules +, tests +} @ injectedDeps: { self, inputs, ... } @ args: let diff --git a/src/mkFlake/fup-adapter.nix b/src/mkFlake/fup-adapter.nix index 1908f831a..19f76eb8b 100644 --- a/src/mkFlake/fup-adapter.nix +++ b/src/mkFlake/fup-adapter.nix @@ -1,5 +1,5 @@ # constructor dependencies -{ lib, self, inputs, flake-utils-plus, internal-modules, ... }: +{ lib, self, inputs, darwin, flake-utils-plus, collectors, internal-modules, ... }: { # evaluated digga configuration @@ -50,20 +50,64 @@ let # evalArgs sets channelName and system to null by default # but for proper default handling in fup, null args have to be removed - stripHost = args: removeAttrs (lib.filterAttrs (_: arg: arg != null) args) [ + stripNull = args: (lib.filterAttrs (_: arg: arg != null) args); + + stripHost = args: removeAttrs (stripNull args) [ # arguments in our hosts/hostDefaults api that shouldn't be passed to fup "externalModules" # TODO: remove deprecated option "exportedModules" "tests" ]; + nixosHostDefaults = flake-utils-plus.lib.mergeAny + { + system = "x86_64-linux"; + output = "nixosConfigurations"; + + # add `self` & `inputs` as specialArgs so their libs can be used in imports + specialArgs = config.nixos.importables // { inherit (config) self inputs; }; + + modules = config.nixos.hostDefaults.exportedModules ++ defaultHostModules ++ [ + internal-modules.nixosDefaults + ]; + } + (stripNull config.nixos.hostDefaults); + nixosHosts = lib.mapAttrs + ( + _: hostConfig: + flake-utils-plus.lib.mergeAny + nixosHostDefaults + (stripNull hostConfig) + ) + config.nixos.hosts; + + darwinHostDefaults = flake-utils-plus.lib.mergeAny + { + system = "x86_64-darwin"; + output = "darwinConfigurations"; + builder = darwin.lib.darwinSystem; + + # add `self` & `inputs` as specialArgs so their libs can be used in imports + specialArgs = config.darwin.importables // { inherit (config) self inputs; }; + modules = config.darwin.hostDefaults.exportedModules ++ defaultHostModules; + } + (stripNull config.darwin.hostDefaults); + darwinHosts = lib.mapAttrs + ( + _: hostConfig: flake-utils-plus.lib.mergeAny + darwinHostDefaults + (stripNull hostConfig) + ) + config.darwin.hosts; + diggaFupArgs = { inherit (config) channelsConfig supportedSystems; inherit self inputs sharedOverlays; - hosts = builtins.mapAttrs (_: stripHost) config.nixos.hosts; + hosts = builtins.mapAttrs (_: stripHost) + (collectors.collectHosts nixosHosts darwinHosts); channels = builtins.mapAttrs (name: channel: @@ -74,14 +118,10 @@ let ) config.channels; - hostDefaults = flake-utils-plus.lib.mergeAny (stripHost config.nixos.hostDefaults) { - # add `self` & `inputs` as specialargs so their libs can be used in imports - specialArgs = config.nixos.importables // { inherit self inputs; }; - modules = config.nixos.hostDefaults.exportedModules ++ defaultHostModules; - }; - nixosModules = flake-utils-plus.lib.exportModules config.nixos.hostDefaults.exportedModules; + darwinModules = flake-utils-plus.lib.exportModules config.darwin.hostDefaults.exportedModules; + homeModules = flake-utils-plus.lib.exportModules config.home.exportedModules; devshellModules = flake-utils-plus.lib.exportModules config.devshell.exportedModules; @@ -95,14 +135,14 @@ let }; outputsBuilder = channels: - flake-utils-plus.lib.mergeAny (defaultOutputsBuilder channels) (config.outputsBuilder channels); - + flake-utils-plus.lib.mergeAny + (defaultOutputsBuilder channels) + (config.outputsBuilder channels); }; in -flake-utils-plus.lib.mkFlake - ( - flake-utils-plus.lib.mergeAny - diggaFupArgs - extraArgs # for overlays list order - ) +flake-utils-plus.lib.mkFlake ( + flake-utils-plus.lib.mergeAny + diggaFupArgs + extraArgs # for overlays list order +) diff --git a/src/mkFlake/options.nix b/src/mkFlake/options.nix index 326135d51..69e348263 100644 --- a/src/mkFlake/options.nix +++ b/src/mkFlake/options.nix @@ -270,7 +270,7 @@ let description = escape [ "<" ">" ] '' overlays to apply to this channel these will get exported under the 'overlays' flake output - as / and any overlay pulled from ''\${inputs} + as / and any overlay pulled from will be filtered out ''; }; @@ -355,6 +355,13 @@ let ]; }; + darwinType = with types; submoduleWith { + specialArgs = { inherit self inputs; }; + modules = [ + { options = (hostsOpt "darwin") // (hostDefaultsOpt "darwin") // importablesOpt; } + ]; + }; + homeType = with types; submoduleWith { specialArgs = { inherit self inputs; }; modules = [ @@ -433,6 +440,13 @@ in hosts, modules, suites, and profiles for NixOS ''; }; + darwin = mkOption { + type = pathToOr darwinType; + default = { }; + description = '' + hosts, modules, suites, and profiles for darwin + ''; + }; home = mkOption { type = pathToOr homeType; default = { }; diff --git a/src/mkFlake/outputs-builder.nix b/src/mkFlake/outputs-builder.nix index 0b7063128..ed7a9da06 100644 --- a/src/mkFlake/outputs-builder.nix +++ b/src/mkFlake/outputs-builder.nix @@ -1,5 +1,5 @@ # constructor dependencies -{ lib, self, inputs, deploy, devshell, home-manager, flake-utils-plus, tests, ... }: +{ lib, self, inputs, collectors, deploy, devshell, home-manager, flake-utils-plus, tests, ... }: config: channels: let @@ -26,7 +26,7 @@ let configuration = { imports = [ configuration ]; } // ( - if pkgs.stdenv.hostPlatform.isLinux + if (pkgs.stdenv.hostPlatform.isLinux && !pkgs.stdenv.buildPlatform.isDarwin) then { targets.genericLinux.enable = true; } else { } ); @@ -35,9 +35,9 @@ let homeConfigurationsPortable = builtins.mapAttrs (n: v: mkPortableHomeManagerConfiguration { + inherit pkgs system; username = n; configuration = v; - inherit pkgs system; }) config.home.users; @@ -84,15 +84,17 @@ in let collectActivationPackages = n: v: { name = "user-" + n; value = v.activationPackage; }; in + # N.B. portable home configurations for Linux/NixOS hosts cannot be built on Darwin! lib.mapAttrs' collectActivationPackages homeConfigurationsPortable else { } ) // ( - # for self.deploy if present & non-empty + # for self.deploy if ( (builtins.hasAttr "deploy" self) && - (self.deploy != { }) + (self.deploy != { }) && + (!pkgs.stdenv.buildPlatform.isDarwin) ) then let deployChecks = deploy.lib.${system}.deployChecks self.deploy; @@ -106,16 +108,16 @@ in # for self.nixosConfigurations if present & non-empty if ( (builtins.hasAttr "nixosConfigurations" self) && - (self.nixosConfigurations != { }) + (self.nixosConfigurations != { }) && + (!pkgs.stdenv.buildPlatform.isDarwin) ) then let - systemSieve = _: host: host.config.nixpkgs.system == system; - hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.nixosConfigurations; + hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.nixosConfigurations system; createCustomTestOp = n: host: test: lib.warnIf (!(test ? name)) '' '${n}' has a test without a name. To distinguish tests in the flake output - all nixos tests must have names. + all tests must have names. '' { name = "customTestFor-${n}-${test.name}"; diff --git a/src/modules.nix b/src/modules.nix index 0a7338a60..28c17b095 100644 --- a/src/modules.nix +++ b/src/modules.nix @@ -17,10 +17,6 @@ globalDefaults = { hmUsers }: { config, pkgs, self, ... }: { - users.mutableUsers = lib.mkDefault false; - - hardware.enableRedistributableFirmware = lib.mkDefault true; - # digga lib can be accessed in modules directly as config.lib.digga lib = { inherit (pkgs.lib) digga; @@ -33,7 +29,12 @@ `self.nixosConfigurations`, with the `self` module argument. ''; }; - - system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; + + nixosDefaults = { self, ... }: { + users.mutableUsers = lib.mkDefault false; + hardware.enableRedistributableFirmware = lib.mkDefault true; + system.configurationRevision = lib.mkIf (self ? rev) self.rev; + }; + }