From 71874ad2ee60ec5549f7b445966abfc65d444687 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 17:43:06 -0500 Subject: [PATCH 01/34] ci: run on `macos-latest` --- .github/workflows/check.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From 4b865dd1957906bf56c58cfd13b97ed58a20b470 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 17:47:08 -0500 Subject: [PATCH 02/34] inputs: add nix-darwin --- flake.lock | 132 ++++++++++++++++++++++++++---------- flake.nix | 7 +- src/mkFlake/default.nix | 11 ++- src/mkFlake/fup-adapter.nix | 2 +- 4 files changed, 113 insertions(+), 39 deletions(-) diff --git a/flake.lock b/flake.lock index 28fbdafce..e0bf0403e 100644 --- a/flake.lock +++ b/flake.lock @@ -15,20 +15,41 @@ "type": "github" } }, + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1646015191, + "narHash": "sha256-+gemBNsqBiSwR5OJA2F/0eZc3xWOsxLDbFNu7/nMcxw=", + "owner": "montchr", + "repo": "nix-darwin", + "rev": "3bb62d40a2ef5c7c1b5634c58c47dd4a239d7618", + "type": "github" + }, + "original": { + "owner": "montchr", + "ref": "add-toplevel-option-lib", + "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 +59,18 @@ } }, "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1637575296, - "narHash": "sha256-ZY8YR5u8aglZPe27+AJMnPTG6645WuavB+w0xmhTarw=", + "lastModified": 1647857022, + "narHash": "sha256-Aw70NWLOIwKhT60MHDGjgWis3DP3faCzr6ap9CSayek=", "owner": "numtide", "repo": "devshell", - "rev": "0e56ef21ba1a717169953122c7415fa6a8cd2618", + "rev": "0a5ff74dacb9ea22614f64e61aeb3ca0bf0e7311", "type": "github" }, "original": { @@ -55,11 +82,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 +98,11 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1641205782, - "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "lastModified": 1648199409, + "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=", "owner": "edolstra", "repo": "flake-compat", - "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03", "type": "github" }, "original": { @@ -86,11 +113,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 +128,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 +144,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 +166,11 @@ ] }, "locked": { - "lastModified": 1637917557, - "narHash": "sha256-3u5bLyGn5NUG3RJA7/v1Bqa/QCFGqp/01Bh/4REf9m4=", + "lastModified": 1648834319, + "narHash": "sha256-i5Aj4Aw64D/A0X6XW5LxSS4XBnYj7gMz+kN4dpsbdk8=", "owner": "nix-community", "repo": "home-manager", - "rev": "4daff26495ca9ac67476cba8cf15c3e36d91ab18", + "rev": "0bdbdea2e26c984b096f4f7d10e3c88536a980b0", "type": "github" }, "original": { @@ -140,11 +182,11 @@ }, "latest": { "locked": { - "lastModified": 1638198142, - "narHash": "sha256-plU9b8r4St6q4U7VHtG9V7oF8k9fIpfXl/KDaZLuY9k=", + "lastModified": 1649012074, + "narHash": "sha256-vQUROcJ3FfT3GTB/nJrXwVvjuq8WfK0ImN+RUgDVN1c=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8a308775674e178495767df90c419425474582a1", + "rev": "bc4b9eef3ce3d5a90d8693e8367c9cbfc9fc1e13", "type": "github" }, "original": { @@ -156,11 +198,11 @@ }, "nixlib": { "locked": { - "lastModified": 1641688481, - "narHash": "sha256-6L+EU12xLDHby7y8elgFtRKVBxix+7qV8DhVgXqrKZo=", + "lastModified": 1648946675, + "narHash": "sha256-ibAfLJJ0WvKjObaFG+QzZHnm42MQtjl2zciPZiLeVjs=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "f697717b3d3a074ffc16c8c8227504f0db292886", + "rev": "58c55a3dbff82bdd04d50e3e58120503bc6d7d14", "type": "github" }, "original": { @@ -171,11 +213,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1648648646, - "narHash": "sha256-pHAq/GvsP7zRHkUTCs+4d31C0IEtTIuC6/TFASIA+zg=", + "lastModified": 1649537291, + "narHash": "sha256-V6VYIwTeI5BCfYK9f5EsMbjsjsis1rUDHMsaDbTvt+A=", "owner": "nixos", "repo": "nixpkgs", - "rev": "efea022d6fe0da84aa6613d4ddeafb80de713457", + "rev": "715dc137b08213aabbbe0965b78ab938e5d8d3b7", "type": "github" }, "original": { @@ -185,9 +227,26 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "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 +254,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..ebc3364ee 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,10 @@ home-manager.url = "github:nix-community/home-manager/release-21.11"; home-manager.inputs.nixpkgs.follows = "nixlib"; + # TODO: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged + darwin.url = "github:montchr/nix-darwin/add-toplevel-option-lib"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; + devshell.url = "github:numtide/devshell"; flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; @@ -37,6 +41,7 @@ , deploy , devshell , flake-utils-plus + , darwin , home-manager , ... }@inputs: @@ -62,7 +67,7 @@ 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 darwin deploy devshell home-manager flake-utils-plus internal-modules tests; }; in { diff --git a/src/mkFlake/default.nix b/src/mkFlake/default.nix index e5ee31d4f..dcf09e05b 100644 --- a/src/mkFlake/default.nix +++ b/src/mkFlake/default.nix @@ -1,4 +1,13 @@ -{ lib, deploy, devshell, home-manager, flake-utils-plus, flake-utils, internal-modules, tests } @ injectedDeps: +{ lib +, 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..c8c31f74d 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, internal-modules, ... }: { # evaluated digga configuration From 7b0cff82bd4c6b7d8256da44c6b1bd3b3f114f04 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 31 Mar 2022 09:39:54 -0400 Subject: [PATCH 03/34] inputs: add nixpkgs-unstable --- flake.lock | 16 ++++++++++++++++ flake.nix | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index e0bf0403e..a91fe16db 100644 --- a/flake.lock +++ b/flake.lock @@ -243,6 +243,22 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "blank": "blank", diff --git a/flake.nix b/flake.nix index ebc3364ee..45ca9d04b 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ # 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"; blank.url = "github:divnix/blank"; From 7ad166f4145b013e5297d5610ec1f46c7985ef5b Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 4 Apr 2022 09:53:15 -0400 Subject: [PATCH 04/34] inputs: avoid pinning nixpkgs to `latest` unless absolutely necessary --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 45ca9d04b..7a3e353bf 100644 --- a/flake.nix +++ b/flake.nix @@ -12,10 +12,12 @@ latest.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixlib.url = "github:nix-community/nixpkgs.lib"; + + # TODO: is this necessary? no references in codebase 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"; From f980b600dd7b8a5eccadd151f6ebc605b1bcc134 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 4 Apr 2022 09:54:36 -0400 Subject: [PATCH 05/34] devshell: pin `devshell.inputs.nixpkgs` to ours --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 7a3e353bf..43a4f9493 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,8 @@ 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 = { From eceb5335ccf7d6b84ed2cc5ece98c10f80430468 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 17:48:27 -0500 Subject: [PATCH 06/34] docs: add commands to generate darwin api docs --- jobs/default.nix | 4 ++++ 1 file changed, 4 insertions(+) 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. + ''; } From 93df57f71f9391bda360e1ef4b02c3183f8b50a5 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 18:19:52 -0500 Subject: [PATCH 07/34] docs: reword overlays doc to work better with syntax highlighting the existing string: ``` ''\${inputs}` ``` causes issues with syntax highlighting in emacs nix-mode --- src/mkFlake/options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mkFlake/options.nix b/src/mkFlake/options.nix index 326135d51..9a122839d 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 ''; }; From 55f1ffa6eae0bf560ec0b4312009d27a83485858 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 17:54:28 -0500 Subject: [PATCH 08/34] darwin: agnostic arg name for `mkHomeConfigurations` --- src/generators.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/generators.nix b/src/generators.nix index e72c852b0..cbc9690f2 100644 --- a/src/generators.nix +++ b/src/generators.nix @@ -12,13 +12,13 @@ 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 - _user@hostname_. + `home-manager` cli from _nixosConfigurations_ or _darwinConfigurations_ + in the form _user@hostname_. **/ let op = attrs: c: @@ -35,7 +35,7 @@ in ; mkHmConfigs = lib.foldl op { }; in - mkHmConfigs (builtins.attrValues nixosConfigurations); + mkHmConfigs (builtins.attrValues systemConfigurations); mkDeployNodes = hosts: extraConfig: /** From 251395e7bdd6e8bde357cc59bd0f2b09a379fd5d Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 18:22:49 -0500 Subject: [PATCH 09/34] darwin: add top-level option for `darwin` host type --- src/mkFlake/options.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/mkFlake/options.nix b/src/mkFlake/options.nix index 9a122839d..69e348263 100644 --- a/src/mkFlake/options.nix +++ b/src/mkFlake/options.nix @@ -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 = { }; From 1c977a3cb555b3831ab26f275dde097dcf6b8bf3 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 23 Jan 2022 13:21:30 -0500 Subject: [PATCH 10/34] refactor: prepare host configs in fup adapter --- flake.nix | 1 + overlays/default.nix | 4 +- src/mkFlake/fup-adapter.nix | 74 +++++++++++++++++++++++++-------- src/mkFlake/outputs-builder.nix | 36 ++++++++++++++++ 4 files changed, 95 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 43a4f9493..4304dd0fe 100644 --- a/flake.nix +++ b/flake.nix @@ -126,6 +126,7 @@ # a little extra service ... overlays = import ./overlays { inherit inputs; }; nixosModules = import ./modules; + darwinModules = import ./modules; defaultTemplate = self.templates.devos; templates.devos.path = ./examples/devos; 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/mkFlake/fup-adapter.nix b/src/mkFlake/fup-adapter.nix index c8c31f74d..346655c25 100644 --- a/src/mkFlake/fup-adapter.nix +++ b/src/mkFlake/fup-adapter.nix @@ -47,23 +47,67 @@ let # arguments in our channels api that shouldn't be passed to fup "overlays" ]; - + # 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; + } + (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) ( + flake-utils-plus.lib.mergeAny + 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/outputs-builder.nix b/src/mkFlake/outputs-builder.nix index 0b7063128..75bcc7c4a 100644 --- a/src/mkFlake/outputs-builder.nix +++ b/src/mkFlake/outputs-builder.nix @@ -137,6 +137,42 @@ in customTests else { } ) + // + ( + # for self.darwinConfigurations if present & non-empty + if ( + (builtins.hasAttr "darwinConfigurations" self) && + (self.darwinConfigurations != { }) + ) then + let + systemSieve = _: host: host.config.nixpkgs.system == system; + hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.darwinConfigurations; + + createCustomTestOp = n: host: test: + lib.warnIf (!(test ? name)) '' + '${n}' has a test without a name. To distinguish tests in the flake output + all darwin tests must have names. + '' + { + name = "customTestFor-${n}-${test.name}"; + value = tests.mkTest host test; + }; + + createCustomTestsOp = n: host: + let + op = createCustomTestOp n host; + in + builtins.listToAttrs (map op config.darwin.hosts.${n}.tests); + + customTests = + if (hostConfigsOnThisSystem != [ ]) + then lib.foldl (a: b: a // b) { } (lib.attrValues (lib.mapAttrs createCustomTestsOp hostConfigsOnThisSystem)) + else { }; + + in + customTests + else { } + ) ; } From 223920bf00ab8ce13baadcf619b1a2b882881d71 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 24 Jan 2022 00:42:44 -0500 Subject: [PATCH 11/34] darwin: relocate nixos-only defs out of `globalDefaults` module most of the `globalDefaults` module's definitions are not present in nix-darwin, so they need to move into nixos-specific modules. at this time, darwin does not yet have its own host-type-specific defaults module, but there are probably some defs worth adding to such a module. --- src/mkFlake/fup-adapter.nix | 13 ++++++++----- src/modules.nix | 13 +++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/mkFlake/fup-adapter.nix b/src/mkFlake/fup-adapter.nix index 346655c25..e54d85c78 100644 --- a/src/mkFlake/fup-adapter.nix +++ b/src/mkFlake/fup-adapter.nix @@ -47,11 +47,11 @@ let # arguments in our channels api that shouldn't be passed to fup "overlays" ]; - + # evalArgs sets channelName and system to null by default # but for proper default handling in fup, null args have to be removed 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 @@ -64,9 +64,12 @@ let system = "x86_64-linux"; output = "nixosConfigurations"; - # add `self` & `inputs` as specialargs so their libs can be used in imports + # 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; + + modules = config.nixos.hostDefaults.exportedModules ++ defaultHostModules ++ [ + internal-modules.nixosDefaults + ]; } (stripNull config.nixos.hostDefaults); nixosHosts = lib.mapAttrs @@ -84,7 +87,7 @@ let output = "darwinConfigurations"; builder = darwin.lib.darwinSystem; - # add `self` & `inputs` as specialargs so their libs can be used in imports + # 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; } 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; + }; + } From 2de29e5deec635d1695180d0b9cd96724721e4b0 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 31 Jan 2022 22:55:57 -0500 Subject: [PATCH 12/34] fix: check for `domain` attr before use `networking.domain` is not declared in nix-darwin. --- modules/bootstrap-iso.nix | 2 +- src/generators.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/src/generators.nix b/src/generators.nix index cbc9690f2..2524d8d6d 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 From dec17c20e181b52ce993a9d85822127fbf967310 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 31 Mar 2022 23:22:22 -0400 Subject: [PATCH 13/34] refactor: isolate exported modules to host-type-specific files darwin should not export a `bootstrapIso` module, for example, because this requires building unsupported packages. --- flake.nix | 4 ++-- modules/darwin-modules.nix | 3 +++ modules/{default.nix => nixos-modules.nix} | 0 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 modules/darwin-modules.nix rename modules/{default.nix => nixos-modules.nix} (100%) diff --git a/flake.nix b/flake.nix index 4304dd0fe..42d59a7e5 100644 --- a/flake.nix +++ b/flake.nix @@ -125,8 +125,8 @@ # a little extra service ... overlays = import ./overlays { inherit inputs; }; - nixosModules = import ./modules; - darwinModules = 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/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 From d506813d6a93680483879301d2f8a44006f7a43b Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 10 Apr 2022 19:21:24 -0400 Subject: [PATCH 14/34] mkFlake: require unique hostnames across nixos and darwin hosts while this could be considered a change in digga's api, flake-utils-plus wouldn't allow duplicate hostnames either, because its `hosts` option does not separate nixos or darwin hosts -- both live at `hosts.`. --- flake.nix | 20 ++++++++++++++++++-- src/collectors.nix | 19 +++++++++++++++++++ src/mkFlake/default.nix | 1 + src/mkFlake/fup-adapter.nix | 9 +++------ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/collectors.nix diff --git a/flake.nix b/flake.nix index 42d59a7e5..b4621a8a9 100644 --- a/flake.nix +++ b/flake.nix @@ -61,6 +61,10 @@ inherit (nixlib) lib; }; + collectors = import ./src/collectors.nix { + inherit (nixlib) lib; + }; + generators = import ./src/generators.nix { inherit (nixlib) lib; inherit deploy; @@ -71,7 +75,16 @@ mkFlake' = import ./src/mkFlake { inherit (nixlib) lib; inherit (flake-utils-plus.inputs) flake-utils; - inherit darwin deploy devshell home-manager flake-utils-plus internal-modules tests; + inherit + collectors + darwin + deploy + devshell + home-manager + flake-utils-plus + internal-modules + tests + ; }; in { @@ -114,7 +127,10 @@ inherit mkFlake; inherit (tests) mkTest allProfilesTest; inherit (importers) flattenTree rakeLeaves importOverlays importExportableModules importHosts; - inherit (generators) mkDeployNodes mkHomeConfigurations; + inherit (generators) mkDeployNodes mkHomeConfigurations ; + inherit (collectors) + collectHosts + ; # DEPRECATED - will be removed soon inherit (deprecated) diff --git a/src/collectors.nix b/src/collectors.nix new file mode 100644 index 000000000..4a1f5c794 --- /dev/null +++ b/src/collectors.nix @@ -0,0 +1,19 @@ +{ lib }: +let + collectHosts = nixosHosts: darwinHosts: + /** + Synopsis: hostsOnSystem _hostOutputs_ _system_ + + **/ + (nixosHosts // lib.mapAttrs (name: value: + if builtins.hasAttr name nixosHosts + then throw '' + Hostnames must be unique across all platforms! Found a duplicate host config for '${name}'. + '' + else value + ) + darwinHosts); +in +{ + inherit collectHosts; +} diff --git a/src/mkFlake/default.nix b/src/mkFlake/default.nix index dcf09e05b..8645b9448 100644 --- a/src/mkFlake/default.nix +++ b/src/mkFlake/default.nix @@ -1,4 +1,5 @@ { lib +, collectors , darwin , deploy , devshell diff --git a/src/mkFlake/fup-adapter.nix b/src/mkFlake/fup-adapter.nix index e54d85c78..19f76eb8b 100644 --- a/src/mkFlake/fup-adapter.nix +++ b/src/mkFlake/fup-adapter.nix @@ -1,5 +1,5 @@ # constructor dependencies -{ lib, self, inputs, darwin, flake-utils-plus, internal-modules, ... }: +{ lib, self, inputs, darwin, flake-utils-plus, collectors, internal-modules, ... }: { # evaluated digga configuration @@ -106,11 +106,8 @@ let supportedSystems; inherit self inputs sharedOverlays; - hosts = builtins.mapAttrs (_: stripHost) ( - flake-utils-plus.lib.mergeAny - nixosHosts - darwinHosts - ); + hosts = builtins.mapAttrs (_: stripHost) + (collectors.collectHosts nixosHosts darwinHosts); channels = builtins.mapAttrs (name: channel: From a304ae08388874c61df0151cc3c123f8aa9d297e Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 22 Jan 2022 17:49:51 -0500 Subject: [PATCH 15/34] groupByConfig: add darwin host --- examples/groupByConfig/darwin/Darwinia.nix | 10 +++++ examples/groupByConfig/darwin/default.nix | 27 +++++++++++++ examples/groupByConfig/flake.nix | 47 ++++++++++++++++------ examples/groupByConfig/nixos/default.nix | 14 +++++-- 4 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 examples/groupByConfig/darwin/Darwinia.nix create mode 100644 examples/groupByConfig/darwin/default.nix diff --git a/examples/groupByConfig/darwin/Darwinia.nix b/examples/groupByConfig/darwin/Darwinia.nix new file mode 100644 index 000000000..1efef7c23 --- /dev/null +++ b/examples/groupByConfig/darwin/Darwinia.nix @@ -0,0 +1,10 @@ +{ config, pkgs, suites, ... }: + +{ + imports = suites.base; + + 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..54012ada2 --- /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: should we expect all of these tests to work on darwin? any + # platform limitations? + # tests = [ allProfilesTest ]; + tests = []; + }; + }; + + importables = rec { + suites = rec { + base = [ ]; + }; + }; +} diff --git a/examples/groupByConfig/flake.nix b/examples/groupByConfig/flake.nix index 350009b48..79ea909a4 100644 --- a/examples/groupByConfig/flake.nix +++ b/examples/groupByConfig/flake.nix @@ -1,27 +1,48 @@ { 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 akin to the NixOS release channel. For one, it's 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 = { + # TODO: revert before merging + url = "github:divnix/digga/darwin-support"; + inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs @ { self, nixos, digga, home }: + 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 = [ ]; From 0fede41810698b9f3893a11388f85e5e136d76d8 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sat, 29 Jan 2022 02:55:35 -0500 Subject: [PATCH 16/34] feat: pass fup's `mergeAny` through lib output --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b4621a8a9..2f03b9a1c 100644 --- a/flake.nix +++ b/flake.nix @@ -123,7 +123,7 @@ # 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; From fbfcbd81b53ebd0343e572c1ff2a0c3d6e2f1659 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 27 Feb 2022 21:16:29 -0500 Subject: [PATCH 17/34] docs: comments and formatting --- examples/groupByConfig/darwin/Darwinia.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/groupByConfig/darwin/Darwinia.nix b/examples/groupByConfig/darwin/Darwinia.nix index 1efef7c23..a17c3196b 100644 --- a/examples/groupByConfig/darwin/Darwinia.nix +++ b/examples/groupByConfig/darwin/Darwinia.nix @@ -3,6 +3,8 @@ { imports = suites.base; + # On darwin, sudoers/admins are added to the `admin` group, not `wheel` as + # they would be on Linux. nix.trustedUsers = [ "@admin" "sosumi" ]; # https://daiderd.com/nix-darwin/manual/index.html#opt-system.stateVersion From 1246668e555d0dc2f868732706e13e36f011d738 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 31 Mar 2022 00:18:48 -0400 Subject: [PATCH 18/34] devos: add a darwin host + separate os-specific configs --- examples/devos/flake.nix | 90 ++++++++++++++++--- examples/devos/hosts/darwin/Mac.nix | 6 ++ examples/devos/hosts/{ => nixos}/NixOS.nix | 0 .../devos/hosts/{ => nixos}/bootstrap.nix | 2 +- examples/devos/modules/hm-system-defaults.nix | 7 +- .../profiles/core/{default.nix => common.nix} | 74 +++------------ examples/devos/profiles/core/darwin.nix | 72 +++++++++++++++ examples/devos/profiles/core/nixos.nix | 78 ++++++++++++++++ examples/devos/users/darwin/default.nix | 8 ++ 9 files changed, 262 insertions(+), 75 deletions(-) create mode 100644 examples/devos/hosts/darwin/Mac.nix rename examples/devos/hosts/{ => nixos}/NixOS.nix (100%) rename examples/devos/hosts/{ => nixos}/bootstrap.nix (95%) rename examples/devos/profiles/core/{default.nix => common.nix} (55%) create mode 100644 examples/devos/profiles/core/darwin.nix create mode 100644 examples/devos/profiles/core/nixos.nix create mode 100644 examples/devos/users/darwin/default.nix diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 82de770b6..e74c323b5 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -10,10 +10,12 @@ # Track channels with commits tested and built by hydra nixos.url = "github:nixos/nixpkgs/nixos-21.11"; latest.url = "github:nixos/nixpkgs/nixos-unstable"; + nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; - digga.url = "github:divnix/digga"; + digga.url = "github:divnix/digga/darwin-support"; digga.inputs.nixpkgs.follows = "nixos"; digga.inputs.nixlib.follows = "nixos"; + # digga.inputs.darwin.follows = "darwin"; digga.inputs.home-manager.follows = "home"; digga.inputs.deploy.follows = "deploy"; @@ -24,7 +26,8 @@ home.url = "github:nix-community/home-manager/release-21.11"; home.inputs.nixpkgs.follows = "nixos"; - darwin.url = "github:LnL7/nix-darwin"; + # TODO: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged + darwin.url = "github:montchr/nix-darwin/add-toplevel-option-lib"; darwin.inputs.nixpkgs.follows = "nixos"; deploy.url = "github:serokell/deploy-rs"; @@ -55,6 +58,7 @@ , agenix , nvfetcher , deploy + , nixpkgs , ... } @ inputs: digga.lib.mkFlake @@ -63,18 +67,30 @@ channelsConfig = { allowUnfree = true; }; - channels = { - nixos = { - imports = [ (digga.lib.importOverlays ./overlays) ]; - overlays = [ + channels = + let + # TODO: any reason to avoid applying these to `latest` via `sharedOverlays`? + commonOverlays = [ nur.overlay agenix.overlay nvfetcher.overlay ./pkgs/default.nix ]; + in + { + nixos = { + imports = [ (digga.lib.importOverlays ./overlays) ]; + overlays = commonOverlays ++ [ ]; + }; + nixpkgs-darwin = { + imports = [ (digga.lib.importOverlays ./overlays) ]; + overlays = commonOverlays ++ [ + # TODO: create if necessary -- or perhaps a placeholder for both host types + # ./pkgs/darwin + ]; + }; + latest = { }; }; - latest = { }; - }; lib = import ./lib { lib = digga.lib // nixos.lib; }; @@ -102,9 +118,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 +128,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"; + 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,14 +171,36 @@ }; }; 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) + ; + # TODO: does it make sense to include `darwinConfigurations`? i assume no. 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/profiles/core/default.nix b/examples/devos/profiles/core/common.nix similarity index 55% rename from examples/devos/profiles/core/default.nix rename to examples/devos/profiles/core/common.nix index c1aed3fac..00cd80e2e 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 @@ -79,16 +75,13 @@ in ns = "n search --no-update-lock-file"; nf = "n flake"; nepl = "n repl ''"; + # FIXME: update this to use the correct channel based on host type -- or move to host-specific profile files 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"; - # sudo s = ifSudo "sudo -E "; si = ifSudo "sudo -i"; @@ -97,44 +90,19 @@ in # 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 - trustedUsers = [ "root" "@wheel" ]; - # Generally useful nix option defaults extraOptions = '' min-free = 536870912 @@ -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..3362a9028 --- /dev/null +++ b/examples/devos/profiles/core/darwin.nix @@ -0,0 +1,72 @@ +{ config, lib, pkgs, ... }: + +{ + imports = [ + ./common.nix + ]; + + # Recreate /run/current-system symlink after boot + services.activate-system.enable = true; + + # TODO: is there any way to check whether the system is using the daemon? or should these defs be excluded from devos? + services.nix-daemon.enable = true; + users.nix.configureBuildUsers = true; + + environment = { + + # FIXME: any more darwin essentials to add here? + systemPackages = with pkgs; [ + m-cli + terminal-notifier + ]; + + # FIXME: use devos path + # environment.darwinConfig = "$DOTFIELD_DIR/lib/compat/darwin"; + + shellAliases = { + # nix + # FIXME: does this need special args for darwin compat? + nrb = "sudo darwin-rebuild"; + }; + + }; + + # TODO: should this be set in common.nix? + fonts.enableFontDir = true; + + nix = { + + nixPath = [ + # FIXME: 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. + # + # 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)" + ''; + }; + + # FIXME: is homebrew absolutely necessary for a reasonable UX? if not, then remove. + # homebrew = { + # # enable = true; + # enable = false; + # autoUpdate = true; + # global.noLock = true; + # }; + +} diff --git a/examples/devos/profiles/core/nixos.nix b/examples/devos/profiles/core/nixos.nix new file mode 100644 index 000000000..edb2e0b2e --- /dev/null +++ b/examples/devos/profiles/core/nixos.nix @@ -0,0 +1,78 @@ +{ 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" ]; + + # Give root and @wheel special privileges with nix + trustedUsers = [ "root" "@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/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"; + }; +} From ab39edf0873f2c2e022a3539032a405ca7564483 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 31 Mar 2022 09:40:50 -0400 Subject: [PATCH 19/34] devshell: use nix 2.7 from unstable channel --- devShell.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/devShell.nix b/devShell.nix index a656db7ad..efea2b34a 100644 --- a/devShell.nix +++ b/devShell.nix @@ -2,9 +2,10 @@ , inputs ? (import ./.).inputs }: let - pkgs = inputs.nixpkgs.legacyPackages.${system}; + unstablePkgs = inputs.nixpkgs-unstable.legacyPackages.${system}; devshell = import inputs.devshell { inherit pkgs 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 = [ From 1aa990d2f90540bcff0d6b0aec419ea5f432fe15 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 31 Mar 2022 23:19:20 -0400 Subject: [PATCH 20/34] chore: clean up unnecessary args to deprecated.nix `nixosModules` and `internal-modules` could cause unwanted builds on darwin. --- deprecated.nix | 2 +- flake.nix | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) 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/flake.nix b/flake.nix index 2f03b9a1c..4514b6ff9 100644 --- a/flake.nix +++ b/flake.nix @@ -108,13 +108,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 From b8d1c7d849006881fea14e152dabd6e5bec78302 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 3 Apr 2022 23:32:48 -0400 Subject: [PATCH 21/34] darwin: update `mkDeployNodes` to account for darwin hosts --- examples/devos/flake.nix | 1 - src/generators.nix | 40 ++++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index e74c323b5..32fd3f4bb 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -200,7 +200,6 @@ (digga.lib.mkHomeConfigurations self.nixosConfigurations) ; - # TODO: does it make sense to include `darwinConfigurations`? i assume no. deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { }; } diff --git a/src/generators.nix b/src/generators.nix index 2524d8d6d..91e7795e4 100644 --- a/src/generators.nix +++ b/src/generators.nix @@ -16,9 +16,9 @@ in /** Synopsis: mkHomeConfigurations _systemConfigurations_ - Generate the `homeConfigurations` attribute expected by - `home-manager` cli from _nixosConfigurations_ or _darwinConfigurations_ - in the form _user@hostname_. + Generate the `homeConfigurations` attribute expected by `home-manager` cli + from _nixosConfigurations_ or _darwinConfigurations_ in the form + _user@hostname_. **/ let op = attrs: c: @@ -37,24 +37,32 @@ in in 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 = { - fastConnection = true; - sshOpts = [ "-p" "25" ]; - }; - hostname-2 = { - sshOpts = [ "-p" "19999" ]; - sshUser = "root"; - }; + hostname-1 = { + fastConnection = true; + sshOpts = [ "-p" "25" ]; + }; + hostname-2 = { + sshOpts = [ "-p" "19999" ]; + sshUser = "root"; + }; } ``` **/ @@ -69,6 +77,6 @@ in }; } ) - hosts) + systemConfigurations) extraConfig; } From 68ade1816c44b61993dff8ee725ce7aecf8e438f Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 4 Apr 2022 09:20:01 -0400 Subject: [PATCH 22/34] devos: devshell: add required pkgs to scope explicitly the `with pkgs` statement in `commands` muddies the origin of the variables used within: - editors are unable to provide helpful advice about undefined variables because `with pkgs` acts as a blanket "anything is possible" signifier - at a cursory glance, it may not be immediately clear that `system` is coming from `pkgs.system` - `lib` is coming from `pkgs.lib`, but we can use the `lib` module arg. - some pkgs within `commands` are still referenced with `pkgs.` unnecessarily --- devShell.nix | 2 +- examples/devos/shell/devos.nix | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/devShell.nix b/devShell.nix index efea2b34a..84ad08fba 100644 --- a/devShell.nix +++ b/devShell.nix @@ -4,7 +4,7 @@ let pkgs = inputs.nixpkgs.legacyPackages.${system}; unstablePkgs = inputs.nixpkgs-unstable.legacyPackages.${system}; - devshell = import inputs.devshell { inherit pkgs system; }; + devshell = import inputs.devshell { inherit system; }; nixBin = "${unstablePkgs.nix}/bin/nix"; withCategory = category: attrset: attrset // { inherit category; }; diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index 581aee9a7..489291192 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -1,6 +1,17 @@ -{ pkgs, extraModulesPath, inputs, ... }: +{ pkgs, extraModulesPath, inputs, lib, ... }: let + inherit (pkgs) + agenix + cachix + editorconfig-checker + mdbook + nixUnstable + nixpkgs-fmt + nvfetcher-bin + system + ; + hooks = import ./hooks; pkgWithCategory = category: package: { inherit package category; }; @@ -30,14 +41,14 @@ in unset _PATH ''); - commands = with pkgs; [ + commands = [ (devos nixUnstable) (devos agenix) { 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) From 780620d8659fdcb04d4952a2607ce363e0d3a3be Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 4 Apr 2022 09:33:05 -0400 Subject: [PATCH 23/34] devos: devshell: use platform checks from `stdenv` --- examples/devos/shell/devos.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index 489291192..ec5db646d 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -1,6 +1,7 @@ { pkgs, extraModulesPath, inputs, lib, ... }: let + inherit (pkgs.stdenv) isi686 isDarwin isLinux; inherit (pkgs) agenix cachix @@ -9,7 +10,6 @@ let nixUnstable nixpkgs-fmt nvfetcher-bin - system ; hooks = import ./hooks; @@ -56,11 +56,9 @@ in (docs mdbook) (devos inputs.deploy.packages.${pkgs.system}.deploy-rs) ] - ++ lib.optional - (system != "i686-linux") + ++ lib.optional (!isi686) (devos cachix) - ++ lib.optional - (system != "aarch64-darwin") + ++ lib.optional (isLinux) (devos inputs.nixos-generators.defaultPackage.${pkgs.system}) ; } From 4438b0f111f0799a74018c47ac806272b672dd15 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Mon, 4 Apr 2022 09:34:06 -0400 Subject: [PATCH 24/34] devos: devshell: reorder + cleanup --- examples/devos/shell/devos.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index ec5db646d..0ed9cfa91 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -15,9 +15,9 @@ let hooks = import ./hooks; pkgWithCategory = category: package: { inherit package category; }; + devos = pkgWithCategory "devos"; linter = pkgWithCategory "linter"; docs = pkgWithCategory "docs"; - devos = pkgWithCategory "devos"; in { @@ -44,17 +44,19 @@ in commands = [ (devos nixUnstable) (devos agenix) + (devos inputs.deploy.packages.${pkgs.system}.deploy-rs) + { category = "devos"; 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 (!isi686) (devos cachix) From 698551e084ce3ef54967d97063f557c1589fb7c5 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 10 Apr 2022 19:27:40 -0400 Subject: [PATCH 25/34] feat: add function to filter hosts from an attrset by system --- flake.nix | 1 + src/collectors.nix | 31 +++++++++++++++++++++++-------- src/mkFlake/outputs-builder.nix | 8 +++----- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 4514b6ff9..07a7db78a 100644 --- a/flake.nix +++ b/flake.nix @@ -127,6 +127,7 @@ inherit (generators) mkDeployNodes mkHomeConfigurations ; inherit (collectors) collectHosts + collectHostsOnSystem ; # DEPRECATED - will be removed soon diff --git a/src/collectors.nix b/src/collectors.nix index 4a1f5c794..37c428a50 100644 --- a/src/collectors.nix +++ b/src/collectors.nix @@ -1,19 +1,34 @@ { lib }: let - collectHosts = nixosHosts: darwinHosts: + collectHosts = nixosConfigurations: darwinConfigurations: /** - Synopsis: hostsOnSystem _hostOutputs_ _system_ + Synopsis: collectHosts _nixosConfigurations_ _darwinConfigurations_ + Collect all hosts across NixOS and Darwin configurations, validating for + unique hostnames to prevent collisions. **/ - (nixosHosts // lib.mapAttrs (name: value: - if builtins.hasAttr name nixosHosts - then throw '' - Hostnames must be unique across all platforms! Found a duplicate host config for '${name}'. - '' + (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 ) - darwinHosts); + 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/mkFlake/outputs-builder.nix b/src/mkFlake/outputs-builder.nix index 75bcc7c4a..e1d745f75 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 @@ -109,8 +109,7 @@ in (self.nixosConfigurations != { }) ) 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)) '' @@ -145,8 +144,7 @@ in (self.darwinConfigurations != { }) ) then let - systemSieve = _: host: host.config.nixpkgs.system == system; - hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.darwinConfigurations; + hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.darwinConfigurations system; createCustomTestOp = n: host: test: lib.warnIf (!(test ? name)) '' From b4f74f5ea0c0d733d5d5720970a06373d068a9bf Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 10 Apr 2022 19:29:50 -0400 Subject: [PATCH 26/34] darwin: avoid checking unsupported flake outputs --- examples/devos/shell/devos.nix | 5 +-- examples/groupByConfig/darwin/default.nix | 6 +-- src/mkFlake/outputs-builder.nix | 50 ++++------------------- 3 files changed, 14 insertions(+), 47 deletions(-) diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index 0ed9cfa91..684db2bf6 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -1,7 +1,6 @@ { pkgs, extraModulesPath, inputs, lib, ... }: let - inherit (pkgs.stdenv) isi686 isDarwin isLinux; inherit (pkgs) agenix cachix @@ -58,9 +57,9 @@ in (docs mdbook) ] - ++ lib.optional (!isi686) + ++ lib.optional (!pkgs.stdenv.buildPlatform.isi686) (devos cachix) - ++ lib.optional (isLinux) + ++ lib.optional (pkgs.stdenv.hostPlatform.isLinux && !pkgs.stdenv.buildPlatform.isDarwin) (devos inputs.nixos-generators.defaultPackage.${pkgs.system}) ; } diff --git a/examples/groupByConfig/darwin/default.nix b/examples/groupByConfig/darwin/default.nix index 54012ada2..d748ac0e2 100644 --- a/examples/groupByConfig/darwin/default.nix +++ b/examples/groupByConfig/darwin/default.nix @@ -12,10 +12,10 @@ in hosts = { Darwinia = { modules = [ ./Darwinia.nix ]; - # TODO: should we expect all of these tests to work on darwin? any - # platform limitations? + + # TODO: add custom test support for darwin hosts # tests = [ allProfilesTest ]; - tests = []; + tests = [ ]; }; }; diff --git a/src/mkFlake/outputs-builder.nix b/src/mkFlake/outputs-builder.nix index e1d745f75..ed7a9da06 100644 --- a/src/mkFlake/outputs-builder.nix +++ b/src/mkFlake/outputs-builder.nix @@ -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,7 +108,8 @@ in # for self.nixosConfigurations if present & non-empty if ( (builtins.hasAttr "nixosConfigurations" self) && - (self.nixosConfigurations != { }) + (self.nixosConfigurations != { }) && + (!pkgs.stdenv.buildPlatform.isDarwin) ) then let hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.nixosConfigurations system; @@ -114,7 +117,7 @@ in 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}"; @@ -136,41 +139,6 @@ in customTests else { } ) - // - ( - # for self.darwinConfigurations if present & non-empty - if ( - (builtins.hasAttr "darwinConfigurations" self) && - (self.darwinConfigurations != { }) - ) then - let - hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.darwinConfigurations system; - - createCustomTestOp = n: host: test: - lib.warnIf (!(test ? name)) '' - '${n}' has a test without a name. To distinguish tests in the flake output - all darwin tests must have names. - '' - { - name = "customTestFor-${n}-${test.name}"; - value = tests.mkTest host test; - }; - - createCustomTestsOp = n: host: - let - op = createCustomTestOp n host; - in - builtins.listToAttrs (map op config.darwin.hosts.${n}.tests); - - customTests = - if (hostConfigsOnThisSystem != [ ]) - then lib.foldl (a: b: a // b) { } (lib.attrValues (lib.mapAttrs createCustomTestsOp hostConfigsOnThisSystem)) - else { }; - - in - customTests - else { } - ) ; } From 41a49ae3a77f55c5de762b2ee8df61f28d57bbe8 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Tue, 19 Apr 2022 19:06:51 -0400 Subject: [PATCH 27/34] devos: darwin-specific profile customizations --- examples/devos/profiles/core/darwin.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/devos/profiles/core/darwin.nix b/examples/devos/profiles/core/darwin.nix index 3362a9028..6d6d72158 100644 --- a/examples/devos/profiles/core/darwin.nix +++ b/examples/devos/profiles/core/darwin.nix @@ -31,9 +31,6 @@ }; - # TODO: should this be set in common.nix? - fonts.enableFontDir = true; - nix = { nixPath = [ From 8232e94cb43084efc4cd29e465e5b043a02d5d5b Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Wed, 20 Apr 2022 20:16:34 -0400 Subject: [PATCH 28/34] chore: docs + formatting --- default.nix | 13 +++++----- examples/devos/flake.nix | 7 ++++- examples/devos/profiles/core/common.nix | 8 +++--- examples/devos/profiles/core/darwin.nix | 30 ++++++++-------------- examples/devos/profiles/core/nixos.nix | 3 --- examples/groupByConfig/darwin/Darwinia.nix | 12 ++++----- examples/groupByConfig/flake.nix | 9 ++++--- examples/hmOnly/flake.nix | 17 ++++++------ flake.nix | 10 ++++---- src/generators.nix | 16 ++++++------ 10 files changed, 59 insertions(+), 66 deletions(-) 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/examples/devos/flake.nix b/examples/devos/flake.nix index 32fd3f4bb..9bf3a4399 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -10,12 +10,17 @@ # 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.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; digga.url = "github:divnix/digga/darwin-support"; digga.inputs.nixpkgs.follows = "nixos"; digga.inputs.nixlib.follows = "nixos"; - # digga.inputs.darwin.follows = "darwin"; digga.inputs.home-manager.follows = "home"; digga.inputs.deploy.follows = "deploy"; diff --git a/examples/devos/profiles/core/common.nix b/examples/devos/profiles/core/common.nix index 00cd80e2e..beed6bc01 100644 --- a/examples/devos/profiles/core/common.nix +++ b/examples/devos/profiles/core/common.nix @@ -75,21 +75,18 @@ in ns = "n search --no-update-lock-file"; nf = "n flake"; nepl = "n repl ''"; - # FIXME: update this to use the correct channel based on host type -- or move to host-specific profile files srch = "ns nixos"; orch = "ns override"; mn = '' manix "" | grep '^# ' | sed 's/^# \(.*\) (.*/\1/;s/ (.*//;s/^# //' | sk --preview="manix '{}'" | xargs manix ''; + top = "btm"; # sudo s = ifSudo "sudo -E "; si = ifSudo "sudo -i"; se = ifSudo "sudoedit"; - # top - top = "btm"; - }; }; @@ -103,6 +100,9 @@ in # Prevents impurities in builds useSandbox = true; + # Give root user and wheel group special Nix privileges. + trustedUsers = [ "root" "@wheel" ]; + # Generally useful nix option defaults extraOptions = '' min-free = 536870912 diff --git a/examples/devos/profiles/core/darwin.nix b/examples/devos/profiles/core/darwin.nix index 6d6d72158..88123ebf4 100644 --- a/examples/devos/profiles/core/darwin.nix +++ b/examples/devos/profiles/core/darwin.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ self, config, lib, pkgs, ... }: { imports = [ @@ -8,25 +8,20 @@ # Recreate /run/current-system symlink after boot services.activate-system.enable = true; - # TODO: is there any way to check whether the system is using the daemon? or should these defs be excluded from devos? services.nix-daemon.enable = true; users.nix.configureBuildUsers = true; environment = { - # FIXME: any more darwin essentials to add here? systemPackages = with pkgs; [ m-cli terminal-notifier ]; - # FIXME: use devos path - # environment.darwinConfig = "$DOTFIELD_DIR/lib/compat/darwin"; + darwinConfig = "${self}/lib/compat"; shellAliases = { - # nix - # FIXME: does this need special args for darwin compat? - nrb = "sudo darwin-rebuild"; + nrb = "sudo darwin-rebuild switch --flake"; }; }; @@ -34,10 +29,14 @@ nix = { nixPath = [ - # FIXME: 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. + # 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" ]; @@ -51,6 +50,7 @@ # 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)" @@ -58,12 +58,4 @@ ''; }; - # FIXME: is homebrew absolutely necessary for a reasonable UX? if not, then remove. - # homebrew = { - # # enable = true; - # enable = false; - # autoUpdate = true; - # global.noLock = true; - # }; - } diff --git a/examples/devos/profiles/core/nixos.nix b/examples/devos/profiles/core/nixos.nix index edb2e0b2e..8fac9f9ab 100644 --- a/examples/devos/profiles/core/nixos.nix +++ b/examples/devos/profiles/core/nixos.nix @@ -50,9 +50,6 @@ autoOptimiseStore = true; optimise.automatic = true; allowedUsers = [ "@wheel" ]; - - # Give root and @wheel special privileges with nix - trustedUsers = [ "root" "@wheel" ]; }; programs.bash = { diff --git a/examples/groupByConfig/darwin/Darwinia.nix b/examples/groupByConfig/darwin/Darwinia.nix index a17c3196b..a1d9a82ec 100644 --- a/examples/groupByConfig/darwin/Darwinia.nix +++ b/examples/groupByConfig/darwin/Darwinia.nix @@ -1,10 +1,10 @@ -{ config, pkgs, suites, ... }: +{ lib, pkgs, config, suites, ... }: { + # TODO: remove manually-imported suites and profiles once custom test support + # is added for darwin + imports = with suites; + base; -{ - imports = suites.base; - - # On darwin, sudoers/admins are added to the `admin` group, not `wheel` as - # they would be on Linux. + # On Darwin, admins are added to the `admin` group. nix.trustedUsers = [ "@admin" "sosumi" ]; # https://daiderd.com/nix-darwin/manual/index.html#opt-system.stateVersion diff --git a/examples/groupByConfig/flake.nix b/examples/groupByConfig/flake.nix index 79ea909a4..bb4902ed4 100644 --- a/examples/groupByConfig/flake.nix +++ b/examples/groupByConfig/flake.nix @@ -6,10 +6,11 @@ nixos.url = "github:nixos/nixpkgs/nixos-21.11"; # For darwin hosts: it can be helpful to track this darwin-specific stable - # channel akin to the NixOS release channel. For one, it's 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. + # 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 = { 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.nix b/flake.nix index 07a7db78a..73845ea37 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,7 @@ nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixlib.url = "github:nix-community/nixpkgs.lib"; - # TODO: is this necessary? no references in codebase + # TODO: remove -- no references blank.url = "github:divnix/blank"; deploy.url = "github:serokell/deploy-rs"; @@ -22,7 +22,7 @@ home-manager.url = "github:nix-community/home-manager/release-21.11"; home-manager.inputs.nixpkgs.follows = "nixlib"; - # TODO: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged + # FIXME: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged darwin.url = "github:montchr/nix-darwin/add-toplevel-option-lib"; darwin.inputs.nixpkgs.follows = "nixpkgs"; @@ -84,7 +84,7 @@ flake-utils-plus internal-modules tests - ; + ; }; in { @@ -124,11 +124,11 @@ inherit mkFlake; inherit (tests) mkTest allProfilesTest; inherit (importers) flattenTree rakeLeaves importOverlays importExportableModules importHosts; - inherit (generators) mkDeployNodes mkHomeConfigurations ; + inherit (generators) mkDeployNodes mkHomeConfigurations; inherit (collectors) collectHosts collectHostsOnSystem - ; + ; # DEPRECATED - will be removed soon inherit (deprecated) diff --git a/src/generators.nix b/src/generators.nix index 91e7795e4..0011002a5 100644 --- a/src/generators.nix +++ b/src/generators.nix @@ -55,14 +55,14 @@ in ``` { - hostname-1 = { - fastConnection = true; - sshOpts = [ "-p" "25" ]; - }; - hostname-2 = { - sshOpts = [ "-p" "19999" ]; - sshUser = "root"; - }; + hostname-1 = { + fastConnection = true; + sshOpts = [ "-p" "25" ]; + }; + hostname-2 = { + sshOpts = [ "-p" "19999" ]; + sshUser = "root"; + }; } ``` **/ From 89d9b3ea97decc70598e1c26f0cf963edec8d0dd Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Fri, 22 Apr 2022 20:23:07 -0400 Subject: [PATCH 29/34] devos: move common overlays to `sharedOverlays` for fup passthrough --- examples/devos/flake.nix | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 9bf3a4399..1bed674aa 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -72,30 +72,17 @@ channelsConfig = { allowUnfree = true; }; - channels = - let - # TODO: any reason to avoid applying these to `latest` via `sharedOverlays`? - commonOverlays = [ - nur.overlay - agenix.overlay - nvfetcher.overlay - ./pkgs/default.nix - ]; - in - { - nixos = { - imports = [ (digga.lib.importOverlays ./overlays) ]; - overlays = commonOverlays ++ [ ]; - }; - nixpkgs-darwin = { - imports = [ (digga.lib.importOverlays ./overlays) ]; - overlays = commonOverlays ++ [ - # TODO: create if necessary -- or perhaps a placeholder for both host types - # ./pkgs/darwin - ]; - }; - latest = { }; + channels = { + nixos = { + imports = [ (digga.lib.importOverlays ./overlays) ]; + overlays = [ ]; + }; + nixpkgs-darwin = { + imports = [ (digga.lib.importOverlays ./overlays) ]; + overlays = [ ]; }; + latest = { }; + }; lib = import ./lib { lib = digga.lib // nixos.lib; }; @@ -106,6 +93,12 @@ our = self.lib; }); }) + + nur.overlay + agenix.overlay + nvfetcher.overlay + + (import ./pkgs) ]; nixos = { From 139d6e673d564aeac423fada7d8976a607c6d87a Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 24 Apr 2022 12:49:40 -0400 Subject: [PATCH 30/34] docs: update api references --- doc/api-reference-channels.md | 18 ++++++++++++- doc/api-reference-home.md | 48 ----------------------------------- doc/api-reference-nixos.md | 48 ----------------------------------- doc/api-reference.md | 3 ++- 4 files changed, 19 insertions(+), 98 deletions(-) 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_* From dd8d0b7927c1f6db2a3a9711d35c792cde01bc54 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Sun, 24 Apr 2022 13:00:37 -0400 Subject: [PATCH 31/34] chore: update inputs --- flake.lock | 58 ++++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/flake.lock b/flake.lock index a91fe16db..7a48b1f84 100644 --- a/flake.lock +++ b/flake.lock @@ -66,11 +66,11 @@ ] }, "locked": { - "lastModified": 1647857022, - "narHash": "sha256-Aw70NWLOIwKhT60MHDGjgWis3DP3faCzr6ap9CSayek=", + "lastModified": 1650389807, + "narHash": "sha256-GFRBdHMJ/T/ifaE2GS58RWpxyufH0LqI3oGS6oWAnHk=", "owner": "numtide", "repo": "devshell", - "rev": "0a5ff74dacb9ea22614f64e61aeb3ca0bf0e7311", + "rev": "5a53bbf3eb4c908d83884d725a86b3a3bde35979", "type": "github" }, "original": { @@ -98,11 +98,11 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1648199409, - "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=", + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", "owner": "edolstra", "repo": "flake-compat", - "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", "type": "github" }, "original": { @@ -166,11 +166,11 @@ ] }, "locked": { - "lastModified": 1648834319, - "narHash": "sha256-i5Aj4Aw64D/A0X6XW5LxSS4XBnYj7gMz+kN4dpsbdk8=", + "lastModified": 1649887911, + "narHash": "sha256-Af0Ppb1RZ7HWuxUvF0/O7h3cy8tqU2eKFyVwyA1ZD+w=", "owner": "nix-community", "repo": "home-manager", - "rev": "0bdbdea2e26c984b096f4f7d10e3c88536a980b0", + "rev": "7244c6715cb8f741f3b3e1220a9279e97b2ed8f5", "type": "github" }, "original": { @@ -182,11 +182,11 @@ }, "latest": { "locked": { - "lastModified": 1649012074, - "narHash": "sha256-vQUROcJ3FfT3GTB/nJrXwVvjuq8WfK0ImN+RUgDVN1c=", + "lastModified": 1650701402, + "narHash": "sha256-XKfstdtqDg+O+gNBx1yGVKWIhLgfEDg/e2lvJSsp9vU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "bc4b9eef3ce3d5a90d8693e8367c9cbfc9fc1e13", + "rev": "bc41b01dd7a9fdffd32d9b03806798797532a5fe", "type": "github" }, "original": { @@ -198,11 +198,11 @@ }, "nixlib": { "locked": { - "lastModified": 1648946675, - "narHash": "sha256-ibAfLJJ0WvKjObaFG+QzZHnm42MQtjl2zciPZiLeVjs=", + "lastModified": 1650761098, + "narHash": "sha256-pllwIuJiY3HDOg5JfO19NnnoHQZ8ZZtrAJMQ9/BX3Y0=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "58c55a3dbff82bdd04d50e3e58120503bc6d7d14", + "rev": "50b30201342fd191180fa95948ee4ba4c1e67183", "type": "github" }, "original": { @@ -213,11 +213,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1649537291, - "narHash": "sha256-V6VYIwTeI5BCfYK9f5EsMbjsjsis1rUDHMsaDbTvt+A=", + "lastModified": 1650728030, + "narHash": "sha256-VfCYsC/0mZQlQqsXf5o5Cib1ncJQ5l7WHN7hEIMmZNw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "715dc137b08213aabbbe0965b78ab938e5d8d3b7", + "rev": "5fb3a179605141bfa4c9c423f9b1c33658b059c8", "type": "github" }, "original": { @@ -229,27 +229,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1648219316, - "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-unstable": { - "locked": { - "lastModified": 1648219316, - "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "lastModified": 1650726686, + "narHash": "sha256-hE5PCqQlsdgWH3AUTwesvjZWs5ZUZ8SjMS5cnFB6W54=", "owner": "nixos", "repo": "nixpkgs", - "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "rev": "3c0f57e36ed0cf9947281e3b31f1bebb7ce5d4a1", "type": "github" }, "original": { From 64bd6388fcea7340575d61616f1a4f3fd66e9029 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Wed, 27 Apr 2022 19:10:44 -0400 Subject: [PATCH 32/34] darwin: standardize nix-darwin input and nixpkgs-darwin-stable usages https://github.com/LnL7/nix-darwin/pull/429 was merged recently, providing the top-level `lib` option --- examples/devos/flake.nix | 11 +++++------ examples/groupByConfig/flake.nix | 3 +++ flake.lock | 11 +++++------ flake.nix | 3 +-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 1bed674aa..2d366c7d0 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -16,7 +16,7 @@ # 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.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; + nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; digga.url = "github:divnix/digga/darwin-support"; digga.inputs.nixpkgs.follows = "nixos"; @@ -31,9 +31,8 @@ home.url = "github:nix-community/home-manager/release-21.11"; home.inputs.nixpkgs.follows = "nixos"; - # TODO: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged - darwin.url = "github:montchr/nix-darwin/add-toplevel-option-lib"; - darwin.inputs.nixpkgs.follows = "nixos"; + darwin.url = "github:LnL7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs-darwin-stable"; deploy.url = "github:serokell/deploy-rs"; deploy.inputs.nixpkgs.follows = "nixos"; @@ -77,7 +76,7 @@ imports = [ (digga.lib.importOverlays ./overlays) ]; overlays = [ ]; }; - nixpkgs-darwin = { + nixpkgs-darwin-stable = { imports = [ (digga.lib.importOverlays ./overlays) ]; overlays = [ ]; }; @@ -134,7 +133,7 @@ darwin = { hostDefaults = { system = "x86_64-darwin"; - channelName = "nixpkgs-darwin"; + channelName = "nixpkgs-darwin-stable"; imports = [ (digga.lib.importExportableModules ./modules) ]; modules = [ { lib.our = self.lib; } diff --git a/examples/groupByConfig/flake.nix b/examples/groupByConfig/flake.nix index bb4902ed4..2d37383f3 100644 --- a/examples/groupByConfig/flake.nix +++ b/examples/groupByConfig/flake.nix @@ -19,6 +19,9 @@ inputs.nixpkgs.follows = "nixos"; }; + 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"; }; diff --git a/flake.lock b/flake.lock index 7a48b1f84..693a5b0eb 100644 --- a/flake.lock +++ b/flake.lock @@ -22,16 +22,15 @@ ] }, "locked": { - "lastModified": 1646015191, - "narHash": "sha256-+gemBNsqBiSwR5OJA2F/0eZc3xWOsxLDbFNu7/nMcxw=", - "owner": "montchr", + "lastModified": 1650976225, + "narHash": "sha256-PGM65SQHS63Dd5MmLJo3GJsZP9lJVZmpWxluQoG1Dt8=", + "owner": "LnL7", "repo": "nix-darwin", - "rev": "3bb62d40a2ef5c7c1b5634c58c47dd4a239d7618", + "rev": "bb3baef6e115ae47bc2ab4973bd3a486488485b0", "type": "github" }, "original": { - "owner": "montchr", - "ref": "add-toplevel-option-lib", + "owner": "LnL7", "repo": "nix-darwin", "type": "github" } diff --git a/flake.nix b/flake.nix index 73845ea37..1862d6abe 100644 --- a/flake.nix +++ b/flake.nix @@ -22,8 +22,7 @@ home-manager.url = "github:nix-community/home-manager/release-21.11"; home-manager.inputs.nixpkgs.follows = "nixlib"; - # FIXME: update url once https://github.com/LnL7/nix-darwin/pull/429 is merged - darwin.url = "github:montchr/nix-darwin/add-toplevel-option-lib"; + darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs"; devshell.url = "github:numtide/devshell"; From e6b14d39d6d2e0a0544dbc50c7cc235acb2bc123 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Wed, 27 Apr 2022 19:52:39 -0400 Subject: [PATCH 33/34] devos: override `nix-index` pkg with latest the version in the 21.11 channel is old and doesn't include support for `aarch64-darwin`. this version does. --- examples/devos/overlays/overrides.nix | 1 + 1 file changed, 1 insertion(+) 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 From 580fc57ffaaf9cf3a582372235759dccfe44ac92 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Wed, 27 Apr 2022 20:21:50 -0400 Subject: [PATCH 34/34] chore: restore examples digga input branch to main --- examples/devos/flake.nix | 2 +- examples/groupByConfig/flake.nix | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 2d366c7d0..4c89496f3 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -18,7 +18,7 @@ # failures on Linux systems. nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; - digga.url = "github:divnix/digga/darwin-support"; + digga.url = "github:divnix/digga"; digga.inputs.nixpkgs.follows = "nixos"; digga.inputs.nixlib.follows = "nixos"; digga.inputs.home-manager.follows = "home"; diff --git a/examples/groupByConfig/flake.nix b/examples/groupByConfig/flake.nix index 2d37383f3..db966de38 100644 --- a/examples/groupByConfig/flake.nix +++ b/examples/groupByConfig/flake.nix @@ -13,11 +13,8 @@ # failures on Linux systems. nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; - digga = { - # TODO: revert before merging - url = "github:divnix/digga/darwin-support"; - inputs.nixpkgs.follows = "nixos"; - }; + digga.url = "github:divnix/digga"; + digga.inputs.nixpkgs.follows = "nixos"; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs-darwin-stable";