From 2c3f17a458aebb98be4198bf6d75e0f3f42d27a8 Mon Sep 17 00:00:00 2001 From: lycheese <4779944-lycheese@users.noreply.gitlab.com> Date: Sat, 3 Apr 2021 16:25:28 +0200 Subject: [PATCH 001/137] Fix documentation mistake after project rename --- cachix/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cachix/README.md b/cachix/README.md index 8c1027a..de732dc 100644 --- a/cachix/README.md +++ b/cachix/README.md @@ -5,7 +5,7 @@ add your own cache, assuming the template lives in /etc/nixos, by simply running `sudo cachix use yourcache`. These caches are only added to the system after a `nixos-rebuild switch`, so it -is recommended to call `cachix use divnix` before the initial deployment, as it +is recommended to call `cachix use nrdxp` before the initial deployment, as it will save a lot of build time. In the future, users will be able to skip this step once the ability to define From a76ca177fdba72b9621568eafc6411bcc0e5bb32 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 30 Mar 2021 11:10:58 -0700 Subject: [PATCH 002/137] lib: init mkFlake to create a devos flake general lib function - not devos specific --- lib/default.nix | 2 ++ lib/mkFlake/default.nix | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 lib/mkFlake/default.nix diff --git a/lib/default.nix b/lib/default.nix index 8ed28a4..61fe6dd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -17,6 +17,8 @@ lib.makeExtensible (final: lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; + mkFlake = callLibs ./mkFlake; + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir pathsToImportedAttrs concatAttrs filterPackages; inherit (lists) pathsIn; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix new file mode 100644 index 0000000..37d055f --- /dev/null +++ b/lib/mkFlake/default.nix @@ -0,0 +1,60 @@ +{ dev, nixos, inputs, ... }: +let + inherit (dev) os; + inherit (inputs) utils deploy; + evalFlakeArgs = dev.callLibs ./evalArgs.nix; +in + +{ self, ... } @ args: +let + + cfg = (lib.evalFlakeArgs { inherit args; }).config; + + multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; + + outputs = { + nixosConfigurations = os.mkHosts { + inherit self multiPkgs; + inherit (cfg) extern suites overrides; + dir = cfg.hosts; + }; + + homeConfigurations = os.mkHomeConfigurations; + + nixosModules = cfg.modules; + + homeModules = cfg.userModules; + + overlay = cfg.packages; + inherit (cfg) overlays; + + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + }; + + systemOutputs = utils.lib.eachDefaultSystem (system: + let + pkgs = multiPkgs.${system}; + # all packages that are defined in ./pkgs + legacyPackages = os.mkPackages { inherit pkgs; }; + in + { + checks = + let + tests = nixos.lib.optionalAttrs (system == "x86_64-linux") + (import "${self}/tests" { inherit self pkgs; }); + deployHosts = nixos.lib.filterAttrs + (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; + deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + in + nixos.lib.recursiveUpdate tests deployChecks; + + inherit legacyPackages; + packages = dev.filterPackages system legacyPackages; + + devShell = import "${self}/shell" { + inherit self system; + }; + }); +in + outputs // systemOutputs + From 340784df6ddaaeb40095f18de8107b92fa25fa30 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 26 Mar 2021 11:57:24 -0700 Subject: [PATCH 003/137] lib: init evalFlakeArgs for mkFlake args module describing devos flake arguments --- lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalArgs.nix | 151 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 lib/mkFlake/evalArgs.nix diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 37d055f..4ff3cd4 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -8,7 +8,7 @@ in { self, ... } @ args: let - cfg = (lib.evalFlakeArgs { inherit args; }).config; + cfg = (evalFlakeArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix new file mode 100644 index 0000000..8e4f14d --- /dev/null +++ b/lib/mkFlake/evalArgs.nix @@ -0,0 +1,151 @@ +{ self, dev, nixos, inputs, ... }: + +{ args }: +let + argOpts = with nixos.lib; { config, options, ... }: + let + inherit (dev) os; + + inherit (config) self; + + inputAttrs = with types; functionTo attrs; + moduleType = with types; anything // { + inherit (submodule {}) check; + description = "valid module"; + }; + in + { + options = with types; { + self = mkOption { + type = addCheck attrs nixos.lib.isStorePath; + description = "The flake to create the devos outputs for"; + }; + hosts = mkOption { + type = path; + default = "${self}/hosts"; + defaultText = "\${self}/hosts"; + apply = toString; + description = '' + Path to directory containing host configurations that will be exported + to the 'nixosConfigurations' output. + ''; + }; + packages = mkOption { + # functionTo changes arg names which breaks flake check + type = types.anything // { + check = builtins.isFunction; + description = "Nixpkgs overlay"; + }; + default = (final: prev: {}); + defaultText = "(final: prev: {})"; + description = '' + Overlay for custom packages that will be included in treewide 'pkgs'. + This should follow the standard nixpkgs overlay format - two argument function + that returns an attrset. + These packages will be exported to the 'packages' and 'legacyPackages' outputs. + ''; + }; + modules = mkOption { + type = listOf moduleType; + default = []; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confgurations and export in 'nixosModules' output + ''; + }; + userModules = mkOption { + type = listOf moduleType; + default = []; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in home-manager configurations and export in + 'homeModules' output + ''; + }; + profiles = mkOption { + type = path; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to profiles folder that can be collected into suites"; + }; + userProfiles = mkOption { + type = path; + default = "${self}/users/profiles"; + defaultText = "\${self}/users/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to user profiles folder that can be collected into userSuites"; + }; + suites = + let + defaults = { user = {}; system = {}; }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = "{ user = {}; system = {}; }"; + apply = suites: defaults // os.mkSuites { + inherit suites; + inherit (config) profiles users userProfiles; + }; + description = '' + Function with inputs 'users' and 'profiles' that returns attribute set + with user and system suites. The former for Home Manager and the latter + for nixos configurations. + These can be accessed through the 'suites' specialArg in each config system. + ''; + }; + users = mkOption { + type = path; + default = "${self}/users"; + defaultText = "\${self}/users"; + apply = x: os.mkProfileAttrs (toString x); + description = '' + path to folder containing profiles that define system users + ''; + }; + extern = + let + defaults = { + modules = []; overlays = []; specialArgs = {}; + userModules = []; userSpecialArgs = []; + }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = '' + { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } + ''; + # So unneeded extern attributes can safely be deleted + apply = x: defaults // (x { inputs = inputs // self.inputs; }); + description = '' + Function with argument 'inputs' that contains all devos and ''${self}'s inputs. + The function should return an attribute set with modules, overlays, and + specialArgs to be included across nixos and home manager configurations. + Only attributes that are used should be returned. + ''; + }; + overlays = mkOption { + type = path; + default = "${self}/overlays"; + defaultText = "\${self}/overlays"; + apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + description = '' + path to folder containing overlays which will be applied to pkgs and exported in + the 'overlays' output + ''; + }; + overrides = mkOption rec { + type = attrs; + default = { modules = []; disabledModules = []; packages = _: _: _: {}; }; + defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; + apply = x: default // x; + description = "attrset of packages and modules that will be pulled from nixpkgs master"; + }; + }; + }; +in + nixos.lib.evalModules { + modules = [ argOpts args ]; + } From d068d79bfd2a37d8ea015b19558a2cc0cddcea37 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 26 Mar 2021 11:59:10 -0700 Subject: [PATCH 004/137] flake: use mkFlake this is where we create devos's template structure --- flake.nix | 93 ++++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 73 deletions(-) diff --git a/flake.nix b/flake.nix index 2af7520..71d449b 100644 --- a/flake.nix +++ b/flake.nix @@ -28,79 +28,26 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: - let - inherit (self) lib; - inherit (lib) os; - - extern = import ./extern { inherit inputs; }; - overrides = import ./overrides; - - multiPkgs = os.mkPkgs { - inherit extern overrides; - }; - - suites = os.mkSuites { - suites = import ./suites; - users = os.mkProfileAttrs "${self}/users"; - profiles = os.mkProfileAttrs "${self}/profiles"; - userProfiles = os.mkProfileAttrs "${self}/users/profiles"; - }; - - outputs = { - nixosConfigurations = os.mkHosts { - dir = "${self}/hosts"; + outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: + let + lib = import ./lib { inherit self nixos inputs; }; + in + lib.mkFlake { + inherit self; + hosts = ./hosts; + packages = import ./pkgs; + suites = import ./suites; + extern = import ./extern; overrides = import ./overrides; - inherit multiPkgs suites extern; + overlays = ./overlays; + profiles = ./profiles; + userProfiles = ./users/profiles; + modules = import ./modules/module-list.nix; + userModules = import ./users/modules/module-list.nix; + } // { + inherit lib; + defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; }; - - homeConfigurations = os.mkHomeConfigurations; - - nixosModules = - let moduleList = import ./modules/module-list.nix; - in lib.pathsToImportedAttrs moduleList; - - homeModules = - let moduleList = import ./users/modules/module-list.nix; - in lib.pathsToImportedAttrs moduleList; - - overlay = import ./pkgs; - overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays); - - lib = import ./lib { inherit nixos self inputs; }; - - templates.flk.path = ./.; - templates.flk.description = "flk template"; - defaultTemplate = self.templates.flk; - - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; - }; - - systemOutputs = utils.lib.eachDefaultSystem (system: - let - pkgs = multiPkgs.${system}; - # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { inherit pkgs; }; - in - { - checks = - let - tests = nixos.lib.optionalAttrs (system == "x86_64-linux") - (import ./tests { inherit self pkgs; }); - deployHosts = nixos.lib.filterAttrs - (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; - in - nixos.lib.recursiveUpdate tests deployChecks; - - inherit legacyPackages; - packages = lib.filterPackages system legacyPackages; - - devShell = import ./shell { - inherit self system extern overrides; - }; - } - ); - in - nixos.lib.recursiveUpdate outputs systemOutputs; } From 930b3e96b4f330d1380011e7363c9373b2f5ca64 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 6 Apr 2021 17:02:30 -0700 Subject: [PATCH 005/137] drop toString in pathsIn - trying to fix CI issues --- lib/lists.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lists.nix b/lib/lists.nix index b6530f1..c5823d3 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -2,7 +2,7 @@ { pathsIn = dir: let - fullPath = name: "${toString dir}/${name}"; + fullPath = name: "${dir}/${name}"; in map fullPath (lib.attrNames (dev.safeReadDir dir)); } From a2530339310bf2ae6a58deda15c66889b292a1df Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 6 Apr 2021 17:33:05 -0700 Subject: [PATCH 006/137] drop toString in evalArgs - trying to fix CI --- lib/mkFlake/evalArgs.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 8e4f14d..5e9bb40 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -66,7 +66,7 @@ let type = path; default = "${self}/profiles"; defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (toString x); + apply = x: os.mkProfileAttrs (x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { From 115f1e6711e3fac5041974b3dbe6df2aa22f78db Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 3 Apr 2021 08:09:36 -0700 Subject: [PATCH 007/137] make core an unecessary profile and add to suites Prevents mkHosts subverting standard devos api to import core and add all necessary core features to mkHosts, so core can be safely deleted in suites --- lib/devos/mkHosts.nix | 6 ++++-- profiles/core/default.nix | 3 --- suites/default.nix | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 1d1bfce..8a8abdb 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -12,7 +12,6 @@ let ]; modules = { - core = "${self}/profiles/core"; modOverrides = { config, overrideModulesPath, ... }: let inherit (overrides) modules disabledModules; @@ -24,7 +23,7 @@ let modules; }; - global = { config, ... }: { + global = { config, pkgs, ... }: { home-manager = { useGlobalPkgs = true; useUserPackages = true; @@ -32,6 +31,7 @@ let extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); }; + users.mutableUsers = lib.mkDefault false; hardware.enableRedistributableFirmware = lib.mkDefault true; @@ -49,6 +49,8 @@ let override.flake = inputs.override; }; + nix.package = pkgs.nixFlakes; + nix.extraOptions = '' experimental-features = ${lib.concatStringsSep " " experimentalFeatures diff --git a/profiles/core/default.nix b/profiles/core/default.nix index 1e789a4..1e8b698 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -2,7 +2,6 @@ let inherit (lib) fileContents; in { - nix.package = pkgs.nixFlakes; nix.systemFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; @@ -145,6 +144,4 @@ in services.earlyoom.enable = true; - users.mutableUsers = false; - } diff --git a/suites/default.nix b/suites/default.nix index 4a65b55..eadb20c 100644 --- a/suites/default.nix +++ b/suites/default.nix @@ -2,7 +2,7 @@ { system = with profiles; rec { - base = [ users.nixos users.root ]; + base = [ core users.nixos users.root ]; }; user = with userProfiles; rec { base = [ direnv git ]; From ab2919df217d2c0230f1f41f8d1812425575d9d7 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 8 Apr 2021 22:03:38 -0500 Subject: [PATCH 008/137] core: add usbutils Looks like core does not include `lsusb` by default, now it does. --- profiles/core/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/profiles/core/default.nix b/profiles/core/default.nix index 1e8b698..f5a654c 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -28,6 +28,7 @@ in ripgrep skim tealdeer + usbutils utillinux whois ]; From eaff91c0f99d2ecd7904f31265f1a21d5b0b2024 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 8 Apr 2021 21:17:24 -0600 Subject: [PATCH 009/137] Revert "drop toString in pathsIn - trying to fix CI issues" This reverts commit 930b3e96b4f330d1380011e7363c9373b2f5ca64. --- lib/lists.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lists.nix b/lib/lists.nix index c5823d3..b6530f1 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -2,7 +2,7 @@ { pathsIn = dir: let - fullPath = name: "${dir}/${name}"; + fullPath = name: "${toString dir}/${name}"; in map fullPath (lib.attrNames (dev.safeReadDir dir)); } From 18dbc7d0e456ec1dc4b920ae188c5180231e7bb7 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 8 Apr 2021 21:18:08 -0600 Subject: [PATCH 010/137] Revert "drop toString in evalArgs - trying to fix CI" This reverts commit a2530339310bf2ae6a58deda15c66889b292a1df. --- lib/mkFlake/evalArgs.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 5e9bb40..8e4f14d 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -66,7 +66,7 @@ let type = path; default = "${self}/profiles"; defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (x); + apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { From 3daa99072841d590aa8bdeef7f1d8d0087bd0f44 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 9 Apr 2021 10:03:42 -0700 Subject: [PATCH 011/137] fix userSpecialArgs defaults (#234) Co-authored-by: Pacman99 --- lib/mkFlake/evalArgs.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 8e4f14d..658ac6d 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -108,7 +108,7 @@ let let defaults = { modules = []; overlays = []; specialArgs = {}; - userModules = []; userSpecialArgs = []; + userModules = []; userSpecialArgs = {}; }; in mkOption { From be4b612b23817abb6c99e92ad80cf77be4f7a582 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 9 Apr 2021 19:22:08 -0600 Subject: [PATCH 012/137] treewide: format with nixpkgs-fmt --- extern/default.nix | 3 +- flake.nix | 45 +++++++++++++++--------------- lib/attrs.nix | 4 +-- lib/devos/mkHomeConfigurations.nix | 4 +-- lib/mkFlake/default.nix | 5 ++-- lib/mkFlake/evalArgs.nix | 25 +++++++++-------- tests/lib.nix | 2 +- tests/profiles/t/default.nix | 1 + users/modules/module-list.nix | 2 +- 9 files changed, 48 insertions(+), 43 deletions(-) diff --git a/extern/default.nix b/extern/default.nix index 66f4e78..4ca9df6 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -25,6 +25,5 @@ ]; # passed to all home-manager modules - userSpecialArgs = { - }; + userSpecialArgs = { }; } diff --git a/flake.nix b/flake.nix index 71d449b..dbb30bf 100644 --- a/flake.nix +++ b/flake.nix @@ -28,26 +28,27 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: - let - lib = import ./lib { inherit self nixos inputs; }; - in - lib.mkFlake { - inherit self; - hosts = ./hosts; - packages = import ./pkgs; - suites = import ./suites; - extern = import ./extern; - overrides = import ./overrides; - overlays = ./overlays; - profiles = ./profiles; - userProfiles = ./users/profiles; - modules = import ./modules/module-list.nix; - userModules = import ./users/modules/module-list.nix; - } // { - inherit lib; - defaultTemplate = self.templates.flk; - templates.flk.path = ./.; - templates.flk.description = "flk template"; - }; + outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: + let + lib = import ./lib { inherit self nixos inputs; }; + in + lib.mkFlake + { + inherit self; + hosts = ./hosts; + packages = import ./pkgs; + suites = import ./suites; + extern = import ./extern; + overrides = import ./overrides; + overlays = ./overlays; + profiles = ./profiles; + userProfiles = ./users/profiles; + modules = import ./modules/module-list.nix; + userModules = import ./users/modules/module-list.nix; + } // { + inherit lib; + defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; + }; } diff --git a/lib/attrs.nix b/lib/attrs.nix index 63df32c..50c72d2 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -37,9 +37,9 @@ rec { let # Everything that nix flake check requires for the packages output filter = (n: v: with v; let platforms = meta.hydraPlatforms or meta.platforms or [ ]; in - lib.isDerivation v && !meta.broken && builtins.elem system platforms); + lib.isDerivation v && !meta.broken && builtins.elem system platforms); in - lib.filterAttrs filter packages; + lib.filterAttrs filter packages; safeReadDir = path: lib.optionalAttrs (builtins.pathExists path) (builtins.readDir path); } diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index ab84393..c0588e2 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -4,9 +4,9 @@ with lib; let mkHomes = host: config: mapAttrs' (user: v: nameValuePair "${user}@${host}" v) - config.config.system.build.homes; + config.config.system.build.homes; hmConfigs = mapAttrs mkHomes self.nixosConfigurations; in -foldl recursiveUpdate {} (attrValues hmConfigs) +foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 4ff3cd4..b2864a1 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -43,7 +43,8 @@ let tests = nixos.lib.optionalAttrs (system == "x86_64-linux") (import "${self}/tests" { inherit self pkgs; }); deployHosts = nixos.lib.filterAttrs - (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; + (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) + self.deploy.nodes; deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; in nixos.lib.recursiveUpdate tests deployChecks; @@ -56,5 +57,5 @@ let }; }); in - outputs // systemOutputs +outputs // systemOutputs diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 658ac6d..29d04bc 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -10,7 +10,7 @@ let inputAttrs = with types; functionTo attrs; moduleType = with types; anything // { - inherit (submodule {}) check; + inherit (submodule { }) check; description = "valid module"; }; in @@ -36,7 +36,7 @@ let check = builtins.isFunction; description = "Nixpkgs overlay"; }; - default = (final: prev: {}); + default = (final: prev: { }); defaultText = "(final: prev: {})"; description = '' Overlay for custom packages that will be included in treewide 'pkgs'. @@ -47,7 +47,7 @@ let }; modules = mkOption { type = listOf moduleType; - default = []; + default = [ ]; apply = dev.pathsToImportedAttrs; description = '' list of modules to include in confgurations and export in 'nixosModules' output @@ -55,7 +55,7 @@ let }; userModules = mkOption { type = listOf moduleType; - default = []; + default = [ ]; apply = dev.pathsToImportedAttrs; description = '' list of modules to include in home-manager configurations and export in @@ -78,7 +78,7 @@ let }; suites = let - defaults = { user = {}; system = {}; }; + defaults = { user = { }; system = { }; }; in mkOption { type = inputAttrs; @@ -107,8 +107,11 @@ let extern = let defaults = { - modules = []; overlays = []; specialArgs = {}; - userModules = []; userSpecialArgs = {}; + modules = [ ]; + overlays = [ ]; + specialArgs = { }; + userModules = [ ]; + userSpecialArgs = { }; }; in mkOption { @@ -138,7 +141,7 @@ let }; overrides = mkOption rec { type = attrs; - default = { modules = []; disabledModules = []; packages = _: _: _: {}; }; + default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; apply = x: default // x; description = "attrset of packages and modules that will be pulled from nixpkgs master"; @@ -146,6 +149,6 @@ let }; }; in - nixos.lib.evalModules { - modules = [ argOpts args ]; - } +nixos.lib.evalModules { + modules = [ argOpts args ]; +} diff --git a/tests/lib.nix b/tests/lib.nix index 900cb57..e215157 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -92,7 +92,7 @@ lib.runTests { system = { bar = [ profiles.foo.default ]; allProfiles = [ profiles.foo.default profiles.t.default ]; - allUsers = []; + allUsers = [ ]; }; }; }; diff --git a/tests/profiles/t/default.nix b/tests/profiles/t/default.nix index e69de29..8b13789 100644 --- a/tests/profiles/t/default.nix +++ b/tests/profiles/t/default.nix @@ -0,0 +1 @@ + diff --git a/users/modules/module-list.nix b/users/modules/module-list.nix index fe51488..1e3ec72 100644 --- a/users/modules/module-list.nix +++ b/users/modules/module-list.nix @@ -1 +1 @@ -[] +[ ] From ac4c26755b1bb74f3d6b7ec6fa6070e7e725763e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 10 Apr 2021 10:59:10 -0700 Subject: [PATCH 013/137] init pkgs-lib, move tests and shell there --- flake.nix | 2 +- lib/default.nix | 2 + lib/mkFlake/default.nix | 20 ++++------ lib/pkgs-lib/default.nix | 20 ++++++++++ {shell => lib/pkgs-lib/shell}/default.nix | 26 ++++++------- {shell => lib/pkgs-lib/shell}/devshell.toml | 0 {shell => lib/pkgs-lib/shell}/flk.nix | 0 {shell => lib/pkgs-lib/shell}/flk.sh | 0 {shell => lib/pkgs-lib/shell}/pre-commit.sh | 0 {tests => lib/pkgs-lib/tests}/default.nix | 39 ++++++++++++------- {tests => lib/pkgs-lib/tests}/lib.nix | 38 ++++++++---------- .../pkgs-lib/tests}/profiles/foo/default.nix | 0 .../pkgs-lib/tests}/profiles/t/default.nix | 0 lib/pkgs-lib/tests/testPathsIn/bar | 0 lib/pkgs-lib/tests/testPathsIn/baz | 0 lib/pkgs-lib/tests/testPathsIn/foo | 0 .../tests}/testPathsToImportedAttrs/bar.nix | 0 .../testPathsToImportedAttrs/dir/default.nix | 0 .../tests}/testPathsToImportedAttrs/f.nix | 0 .../tests}/testPathsToImportedAttrs/foo.nix | 0 .../tests}/testPathsToImportedAttrs/t.nix | 0 tests/README.md | 36 ----------------- 22 files changed, 82 insertions(+), 101 deletions(-) create mode 100644 lib/pkgs-lib/default.nix rename {shell => lib/pkgs-lib/shell}/default.nix (75%) rename {shell => lib/pkgs-lib/shell}/devshell.toml (100%) rename {shell => lib/pkgs-lib/shell}/flk.nix (100%) rename {shell => lib/pkgs-lib/shell}/flk.sh (100%) rename {shell => lib/pkgs-lib/shell}/pre-commit.sh (100%) rename {tests => lib/pkgs-lib/tests}/default.nix (60%) rename {tests => lib/pkgs-lib/tests}/lib.nix (69%) rename {tests => lib/pkgs-lib/tests}/profiles/foo/default.nix (100%) rename {tests => lib/pkgs-lib/tests}/profiles/t/default.nix (100%) create mode 100644 lib/pkgs-lib/tests/testPathsIn/bar create mode 100644 lib/pkgs-lib/tests/testPathsIn/baz create mode 100644 lib/pkgs-lib/tests/testPathsIn/foo rename {tests => lib/pkgs-lib/tests}/testPathsToImportedAttrs/bar.nix (100%) rename {tests => lib/pkgs-lib/tests}/testPathsToImportedAttrs/dir/default.nix (100%) rename {tests => lib/pkgs-lib/tests}/testPathsToImportedAttrs/f.nix (100%) rename {tests => lib/pkgs-lib/tests}/testPathsToImportedAttrs/foo.nix (100%) rename {tests => lib/pkgs-lib/tests}/testPathsToImportedAttrs/t.nix (100%) delete mode 100644 tests/README.md diff --git a/flake.nix b/flake.nix index dbb30bf..fddbc85 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: let - lib = import ./lib { inherit self nixos inputs; }; + lib = import ./lib { inherit self nixos utils inputs; }; in lib.mkFlake { diff --git a/lib/default.nix b/lib/default.nix index 61fe6dd..ee06a3c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -19,6 +19,8 @@ lib.makeExtensible (final: mkFlake = callLibs ./mkFlake; + pkgs-lib = callLibs ./pkgs-lib; + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir pathsToImportedAttrs concatAttrs filterPackages; inherit (lists) pathsIn; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index b2864a1..700773f 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -34,27 +34,21 @@ let systemOutputs = utils.lib.eachDefaultSystem (system: let pkgs = multiPkgs.${system}; + pkgs-lib = dev.pkgs-lib.${system}; # all packages that are defined in ./pkgs legacyPackages = os.mkPackages { inherit pkgs; }; in { - checks = - let - tests = nixos.lib.optionalAttrs (system == "x86_64-linux") - (import "${self}/tests" { inherit self pkgs; }); - deployHosts = nixos.lib.filterAttrs - (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) - self.deploy.nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; - in - nixos.lib.recursiveUpdate tests deployChecks; + checks = pkgs-lib.tests.mkChecks { + inherit (self.deploy) nodes; + hosts = self.nixosConfigurations; + homes = self.homeConfigurations; + }; inherit legacyPackages; packages = dev.filterPackages system legacyPackages; - devShell = import "${self}/shell" { - inherit self system; - }; + devShell = pkgs-lib.shell; }); in outputs // systemOutputs diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix new file mode 100644 index 0000000..807b44f --- /dev/null +++ b/lib/pkgs-lib/default.nix @@ -0,0 +1,20 @@ +args@{ lib, dev, utils, nixos, ... }: +lib.genAttrs utils.lib.defaultSystems (system: + lib.makeExtensible (final: + let + pkgs = import nixos { inherit system; }; + callLibs = file: import file + (args // { + inherit pkgs system; + pkgs-lib = final; + }); + in + with final; + { + inherit callLibs; + + tests = callLibs ./tests; + shell = callLibs ./shell; + } + ) +) diff --git a/shell/default.nix b/lib/pkgs-lib/shell/default.nix similarity index 75% rename from shell/default.nix rename to lib/pkgs-lib/shell/default.nix index 0b132f9..ed78187 100644 --- a/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,25 +1,23 @@ -{ self ? (import ../compat).defaultNix -, system ? builtins.currentSystem -, extern ? import ../extern { inherit (self) inputs; } -, overrides ? import ../overrides -}: +{ lib, dev, inputs, system, nixos, ... }: let - pkgs = (self.lib.os.mkPkgs { - inherit overrides extern; - }).${system}; + overlays = [ + inputs.devshell.overlay + (final: prev: { + deploy-rs = + inputs.deploy.packages.${prev.system}.deploy-rs; + }) + ]; - inherit (pkgs) lib; + pkgs = dev.os.pkgImport nixos overlays system; + + flk = pkgs.callPackage ./flk.nix { }; installPkgs = (lib.nixosSystem { inherit system; modules = [ ]; }).config.system.build; - - flk = pkgs.callPackage ./flk.nix { }; - in -pkgs.devshell.mkShell -{ +pkgs.devshell.mkShell { imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; packages = with installPkgs; [ diff --git a/shell/devshell.toml b/lib/pkgs-lib/shell/devshell.toml similarity index 100% rename from shell/devshell.toml rename to lib/pkgs-lib/shell/devshell.toml diff --git a/shell/flk.nix b/lib/pkgs-lib/shell/flk.nix similarity index 100% rename from shell/flk.nix rename to lib/pkgs-lib/shell/flk.nix diff --git a/shell/flk.sh b/lib/pkgs-lib/shell/flk.sh similarity index 100% rename from shell/flk.sh rename to lib/pkgs-lib/shell/flk.sh diff --git a/shell/pre-commit.sh b/lib/pkgs-lib/shell/pre-commit.sh similarity index 100% rename from shell/pre-commit.sh rename to lib/pkgs-lib/shell/pre-commit.sh diff --git a/tests/default.nix b/lib/pkgs-lib/tests/default.nix similarity index 60% rename from tests/default.nix rename to lib/pkgs-lib/tests/default.nix index 3c2539a..323d86d 100644 --- a/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,17 +1,29 @@ -{ self, pkgs }: +{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }: let - inherit (self.inputs) nixos; - inherit (self.nixosConfigurations.NixOS.config.lib) testModule specialArgs; + mkChecks = { hosts, nodes, homes ? { } }: + let + deployHosts = lib.filterAttrs + (n: _: hosts.${n}.config.nixpkgs.system == system) + nodes; + deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + tests = + { libTests = libTests; } + // lib.optionalAttrs (deployHosts != { }) { + profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + } // lib.mapAttrs (n: v: v.home.activationPackage) homes; - mkTest = + in + lib.recursiveUpdate tests deployChecks; + + mkTest = host: let nixosTesting = (import "${nixos}/nixos/lib/testing-python.nix" { - inherit (pkgs.stdenv.hostPlatform) system; - inherit specialArgs; + inherit system; + inherit (host.config.lib) specialArgs; inherit pkgs; extraConfigurations = [ - testModule + host.config.lib.testModule ]; }); in @@ -27,9 +39,8 @@ let else loadedTest; in nixosTesting.makeTest calledTest; -in -{ - profilesTest = mkTest { + + profilesTest = host: mkTest host { name = "profiles"; machine = { suites, ... }: { @@ -41,14 +52,12 @@ in ''; }; - homeTest = self.homeConfigurations."nixos@NixOS".home.activationPackage; - libTests = pkgs.runCommandNoCC "devos-lib-tests" { buildInputs = [ pkgs.nix ( - let tests = import ./lib.nix { inherit self pkgs; }; + let tests = pkgs-lib.callLibs ./lib.nix; in if tests == [ ] then null @@ -70,5 +79,5 @@ in touch $out ''; -} - +in +{ inherit mkTest libTests profilesTest mkChecks; } diff --git a/tests/lib.nix b/lib/pkgs-lib/tests/lib.nix similarity index 69% rename from tests/lib.nix rename to lib/pkgs-lib/tests/lib.nix index e215157..68baa9f 100644 --- a/tests/lib.nix +++ b/lib/pkgs-lib/tests/lib.nix @@ -1,6 +1,5 @@ -{ self, pkgs }: -let inherit (self.inputs.nixos) lib; in -with self.lib; +{ pkgs, lib, dev, ... }: +with dev; lib.runTests { testConcatAttrs = { expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; @@ -28,29 +27,24 @@ lib.runTests { expected = { foobar = 1; }; }; - testPathsIn = - let testPaths = pkgs.runCommandNoCC "test-paths-in" { } '' - mkdir -p $out/{foo,bar,baz} - ''; - in - { - expr = pathsIn testPaths; + testPathsIn = { + expr = pathsIn (toString ./testPathsIn); - expected = [ - "${testPaths}/bar" - "${testPaths}/baz" - "${testPaths}/foo" - ]; - }; + expected = map toString [ + ./testPathsIn/bar + ./testPathsIn/baz + ./testPathsIn/foo + ]; + }; testPathsToImportedAttrs = { expr = pathsToImportedAttrs [ - "${self}/tests/testPathsToImportedAttrs/dir" - "${self}/tests/testPathsToImportedAttrs/foo.nix" - "${self}/tests/testPathsToImportedAttrs/bar.nix" - "${self}/tests/testPathsToImportedAttrs/t.nix" - "${self}/tests/testPathsToImportedAttrs/f.nix" + (toString ./testPathsToImportedAttrs/dir) + ./testPathsToImportedAttrs/foo.nix + ./testPathsToImportedAttrs/bar.nix + ./testPathsToImportedAttrs/t.nix + ./testPathsToImportedAttrs/f.nix ]; expected = { @@ -70,7 +64,7 @@ lib.runTests { ]; testSafeReadDir = { - expr = safeReadDir "${self}/tests/profiles" // safeReadDir "${self}/nonexistentdir"; + expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir; expected = { foo = "directory"; t = "directory"; diff --git a/tests/profiles/foo/default.nix b/lib/pkgs-lib/tests/profiles/foo/default.nix similarity index 100% rename from tests/profiles/foo/default.nix rename to lib/pkgs-lib/tests/profiles/foo/default.nix diff --git a/tests/profiles/t/default.nix b/lib/pkgs-lib/tests/profiles/t/default.nix similarity index 100% rename from tests/profiles/t/default.nix rename to lib/pkgs-lib/tests/profiles/t/default.nix diff --git a/lib/pkgs-lib/tests/testPathsIn/bar b/lib/pkgs-lib/tests/testPathsIn/bar new file mode 100644 index 0000000..e69de29 diff --git a/lib/pkgs-lib/tests/testPathsIn/baz b/lib/pkgs-lib/tests/testPathsIn/baz new file mode 100644 index 0000000..e69de29 diff --git a/lib/pkgs-lib/tests/testPathsIn/foo b/lib/pkgs-lib/tests/testPathsIn/foo new file mode 100644 index 0000000..e69de29 diff --git a/tests/testPathsToImportedAttrs/bar.nix b/lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix similarity index 100% rename from tests/testPathsToImportedAttrs/bar.nix rename to lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix diff --git a/tests/testPathsToImportedAttrs/dir/default.nix b/lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix similarity index 100% rename from tests/testPathsToImportedAttrs/dir/default.nix rename to lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix diff --git a/tests/testPathsToImportedAttrs/f.nix b/lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix similarity index 100% rename from tests/testPathsToImportedAttrs/f.nix rename to lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix diff --git a/tests/testPathsToImportedAttrs/foo.nix b/lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix similarity index 100% rename from tests/testPathsToImportedAttrs/foo.nix rename to lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix diff --git a/tests/testPathsToImportedAttrs/t.nix b/lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix similarity index 100% rename from tests/testPathsToImportedAttrs/t.nix rename to lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 4b2c36e..0000000 --- a/tests/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Testing - -Testing is always an important aspect of any software development project, and -NixOS offers some incredibly powerful tools to write tests for your -configuration, and, optionally, run them in -[CI](../doc/integrations/hercules.md). - -## Lib Tests -You can easily write tests for your own library functions in the -___tests/lib.nix___ file and they will be run on every `nix flake check` or -during a CI run. - -## Unit Tests -Unit tests are can be created from regular derivations, and they can do -almost anything you can imagine. By convention, it is best to test your -packages during their [check phase][check]. All packages and their tests will -be built during CI. - -## Integration Tests -You can write integration tests for one or more NixOS VMs that can, -optionally, be networked together, and yes, it's as awesome as it sounds! - -Be sure to use the `mkTest` function, in the [___tests/default.nix___][default] -which wraps the official [testing-python][testing-python] function to ensure -that the system is setup exactly as it is for a bare DevOS system. There are -already great resources for learning how to use these tests effectively, -including the official [docs][test-doc], a fantastic [blog post][test-blog], -and the examples in [nixpkgs][nixos-tests]. - -[test-doc]: https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests -[test-blog]: https://www.haskellforall.com/2020/11/how-to-use-nixos-for-lightweight.html -[default]: https://github.com/divnix/devos/tree/core/tests/default.nix -[run-test]: https://github.com/NixOS/nixpkgs/blob/6571462647d7316aff8b8597ecdf5922547bf365/lib/debug.nix#L154-L166 -[nixos-tests]: https://github.com/NixOS/nixpkgs/tree/master/nixos/tests -[testing-python]: https://github.com/NixOS/nixpkgs/tree/master/nixos/lib/testing-python.nix -[check]: https://nixos.org/manual/nixpkgs/stable/#ssec-check-phase From 8ba7bffc3f0960fddd864a9c1760b8b439d55d57 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 10 Apr 2021 22:04:49 -0700 Subject: [PATCH 014/137] export users home for home-manager --flake home-manager --flake needs the activationPackage in the root of the homeConfiguration --- lib/devos/mkHomeConfigurations.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index c0588e2..490975a 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -3,7 +3,7 @@ with lib; let mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v) + mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; hmConfigs = mapAttrs mkHomes self.nixosConfigurations; From 401566af34ab9891335366db49bd12482bbf125c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 10 Apr 2021 22:13:54 -0700 Subject: [PATCH 015/137] lib/pkgs-lib: update checks for new hm format --- lib/pkgs-lib/tests/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 323d86d..3c28468 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -10,7 +10,7 @@ let { libTests = libTests; } // lib.optionalAttrs (deployHosts != { }) { profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); - } // lib.mapAttrs (n: v: v.home.activationPackage) homes; + } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; From 658cd2bb082b259ef27cfdb910d4bc1f5193fcf1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 10:24:00 -0700 Subject: [PATCH 016/137] pkgs-lib/shell: update to new homeConfigurations flk should switch to use home-manager --flake whenever the updated package is made available in the hm flake or nixpkgs --- lib/pkgs-lib/shell/flk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkgs-lib/shell/flk.sh b/lib/pkgs-lib/shell/flk.sh index 344e9d3..2d46045 100755 --- a/lib/pkgs-lib/shell/flk.sh +++ b/lib/pkgs-lib/shell/flk.sh @@ -81,7 +81,7 @@ case "$1" in ;; "home") - ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.home.activationPackage" + ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.activationPackage" if [[ "$4" == "switch" ]]; then nix build "$ref" && result/activate && From b7bcaea497ed24c0e26266f3d1b1cdf32d1c8bd1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 20:01:13 -0700 Subject: [PATCH 017/137] Update evalArgs to match the new planned api --- lib/mkFlake/evalArgs.nix | 311 ++++++++++++++++++++++++--------------- 1 file changed, 195 insertions(+), 116 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 29d04bc..e6f055e 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,150 +1,229 @@ -{ self, dev, nixos, inputs, ... }: +{ self, dev, nixos, inputs, utils, ... }: { args }: let - argOpts = with nixos.lib; { config, options, ... }: + argOpts = with nixos.lib; { config, ... }: let inherit (dev) os; inherit (config) self; - inputAttrs = with types; functionTo attrs; + maybeImport = obj: + if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then + import obj + else + obj; + + /* Custom types needed for arguments */ + moduleType = with types; anything // { inherit (submodule { }) check; description = "valid module"; }; + overlayType = types.anything // { + check = builtins.isFunction; + description = "valid Nixpkgs overlay"; + }; + systemType = types.enum (builtins.attrValues config.supportedSystems); + flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { + description = "nix flake"; + }; + + # Applys maybeImport during merge and before check + # To simplify apply keys and improve type checking + pathTo = elemType: mkOptionType { + name = "pathTo"; + description = "path that evaluates to a(n) ${elemType.name}"; + check = x: elemType.check (maybeImport x); + merge = loc: defs: + (mergeDefinitions loc elemType (map + (x: { + inherit (x) file; + value = maybeImport x.value; + }) + defs)).mergedValue; + getSubOptions = elemType.getSubOptions; + getSubModules = elemType.getSubModules; + substSubModules = m: pathTo (elemType.substSubModules m); + }; + + + /* Submodules needed for API containers */ + + channelsModule = { + options = with types; { + input = mkOption { + type = flakeType; + default = inputs.nixos; + description = '' + nixpkgs flake input to use for this channel + ''; + }; + overlays = mkOption { + type = pathTo (listOf overlayType); + default = [ ]; + description = '' + overlays to apply to this channel + these will get exported under the 'overlays' flake output as / + ''; + }; + externalOverlays = mkOption { + type = pathTo (listOf overlayType); + default = [ ]; + description = '' + overlays to apply to the channel that don't get exported to the flake output + useful to include overlays from inputs + ''; + }; + config = mkOption { + type = pathTo attrs; + default = { }; + description = '' + nixpkgs config for this channel + ''; + }; + }; + }; + + configModule = { name, ... }: { + options = with types; { + system = mkOption { + type = systemType; + default = "x86_64-linux"; + description = '' + system for this config + ''; + }; + channelName = mkOption { + type = types.enum (builtins.attrValues self.channels); + default = "nixpkgs"; + description = '' + Channel this config should follow + ''; + }; + modules = mkOption { + type = pathTo moduleType; + default = [ ]; + description = '' + The configuration for this config + ''; + }; + externalmodules = mkOption { + type = pathTo moduleType; + default = [ ]; + description = '' + The configuration for this config + ''; + }; + }; + }; + + # Home-manager's configs get exported automatically from nixos.hosts + # So there is no need for a config options in the home namespace + # This is only needed for nixos + includeConfigsModule = { + options = with types; { + configDefaults = mkOption { + type = submodule configModule; + default = { }; + description = '' + defaults for all configs + ''; + }; + configs = mkOption { + type = pathTo (attrsOf (submodule configModule)); + default = { }; + description = '' + configurations to include in the ${name}Configurations output + ''; + }; + }; + }; + + # Options to import: modules, profiles, suites + importsModule = { name, ... }: { + options = with types; { + modules = mkOption { + type = pathTo (listOf moduleType); + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confgurations and export in '${name}Modules' output + ''; + }; + externalModules = mkOption { + type = pathTo (listOf moduleType); + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confguration but these are not exported to the '${name}Modules' output + ''; + }; + profiles = mkOption { + type = path; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to profiles folder that can be collected into suites"; + }; + suites = mkOption { + type = pathTo (functionTo attrs); + default = _: { }; + apply = suites: os.mkSuites { + inherit suites; + inherit (config) profiles; + }; + description = '' + Function with the input of 'profiles' that returns an attribute set + with the suites for this config system. + These can be accessed through the 'suites' special argument. + ''; + }; + }; + }; in { options = with types; { self = mkOption { - type = addCheck attrs nixos.lib.isStorePath; + type = flakeType; description = "The flake to create the devos outputs for"; }; - hosts = mkOption { - type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; - apply = toString; + supportedSystems = mkOption { + type = listOf str; + default = utils.lib.defaultSystems; description = '' - Path to directory containing host configurations that will be exported - to the 'nixosConfigurations' output. + The systems supported by this flake ''; }; - packages = mkOption { - # functionTo changes arg names which breaks flake check - type = types.anything // { - check = builtins.isFunction; - description = "Nixpkgs overlay"; - }; - default = (final: prev: { }); - defaultText = "(final: prev: {})"; - description = '' - Overlay for custom packages that will be included in treewide 'pkgs'. - This should follow the standard nixpkgs overlay format - two argument function - that returns an attrset. - These packages will be exported to the 'packages' and 'legacyPackages' outputs. - ''; - }; - modules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = dev.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in 'nixosModules' output - ''; - }; - userModules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = dev.pathsToImportedAttrs; - description = '' - list of modules to include in home-manager configurations and export in - 'homeModules' output - ''; - }; - profiles = mkOption { - type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to profiles folder that can be collected into suites"; - }; - userProfiles = mkOption { - type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to user profiles folder that can be collected into userSuites"; - }; - suites = + channels = let - defaults = { user = { }; system = { }; }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = "{ user = {}; system = {}; }"; - apply = suites: defaults // os.mkSuites { - inherit suites; - inherit (config) profiles users userProfiles; - }; - description = '' - Function with inputs 'users' and 'profiles' that returns attribute set - with user and system suites. The former for Home Manager and the latter - for nixos configurations. - These can be accessed through the 'suites' specialArg in each config system. - ''; - }; - users = mkOption { - type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; - apply = x: os.mkProfileAttrs (toString x); - description = '' - path to folder containing profiles that define system users - ''; - }; - extern = - let - defaults = { - modules = [ ]; - overlays = [ ]; - specialArgs = { }; - userModules = [ ]; - userSpecialArgs = { }; + default = { + nixpkgs = { + input = inputs.nixos; + }; }; in mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = '' - { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } - ''; - # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); + type = attrsOf (submodule channelsModule); + inherit default; + apply = x: default // x; description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. - The function should return an attribute set with modules, overlays, and - specialArgs to be included across nixos and home manager configurations. - Only attributes that are used should be returned. + nixpkgs channels to create ''; }; - overlays = mkOption { - type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; - apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + nixos = mkOption { + type = submodule [ includeConfigsModule importsModule ]; + default = { }; description = '' - path to folder containing overlays which will be applied to pkgs and exported in - the 'overlays' output + hosts, modules, suites, and profiles for nixos ''; }; - overrides = mkOption rec { - type = attrs; - default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; - defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; - apply = x: default // x; - description = "attrset of packages and modules that will be pulled from nixpkgs master"; + home = mkOption { + type = submodule importsModule; + default = { }; + description = '' + hosts, modules, suites, and profiles for home-manager + ''; }; }; }; From 2b70cd3ae607d8c5d05b4266530be6011e94371b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 22:25:37 -0700 Subject: [PATCH 018/137] fix some small bugs in mkFlake/evalArgs --- lib/default.nix | 5 ++++- lib/mkFlake/default.nix | 5 ++--- lib/mkFlake/evalArgs.nix | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index ee06a3c..cf8d862 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -17,7 +17,10 @@ lib.makeExtensible (final: lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; - mkFlake = callLibs ./mkFlake; + mkFlake = { + __functor = callLibs ./mkFlake; + evalArgs = callLibs ./mkFlake/evalArgs.nix; + }; pkgs-lib = callLibs ./pkgs-lib; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 700773f..31f019f 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -2,13 +2,12 @@ let inherit (dev) os; inherit (inputs) utils deploy; - evalFlakeArgs = dev.callLibs ./evalArgs.nix; in -{ self, ... } @ args: +_: { self, ... } @ args: let - cfg = (evalFlakeArgs { inherit args; }).config; + cfg = (dev.mkFlake.evalArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index e6f055e..d368176 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -24,7 +24,7 @@ let check = builtins.isFunction; description = "valid Nixpkgs overlay"; }; - systemType = types.enum (builtins.attrValues config.supportedSystems); + systemType = types.enum config.supportedSystems; flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { description = "nix flake"; }; @@ -85,7 +85,7 @@ let }; }; - configModule = { name, ... }: { + configModule = { options = with types; { system = mkOption { type = systemType; @@ -95,7 +95,7 @@ let ''; }; channelName = mkOption { - type = types.enum (builtins.attrValues self.channels); + type = types.enum (builtins.attrValues config.channels); default = "nixpkgs"; description = '' Channel this config should follow @@ -108,7 +108,7 @@ let The configuration for this config ''; }; - externalmodules = mkOption { + externalModules = mkOption { type = pathTo moduleType; default = [ ]; description = '' @@ -121,7 +121,7 @@ let # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a config options in the home namespace # This is only needed for nixos - includeConfigsModule = { + includeConfigsModule = { name, ... }: { options = with types; { configDefaults = mkOption { type = submodule configModule; From 0db2bb041e8cfecbbec08010d150539f4e11963e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 13 Apr 2021 11:24:10 -0700 Subject: [PATCH 019/137] add old evalArgs as evalOldArgs, so flake works --- lib/default.nix | 1 + lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalOldArgs.nix | 154 ++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 lib/mkFlake/evalOldArgs.nix diff --git a/lib/default.nix b/lib/default.nix index cf8d862..4ed82a4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -20,6 +20,7 @@ lib.makeExtensible (final: mkFlake = { __functor = callLibs ./mkFlake; evalArgs = callLibs ./mkFlake/evalArgs.nix; + evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; }; pkgs-lib = callLibs ./pkgs-lib; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 31f019f..4fd6947 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -7,7 +7,7 @@ in _: { self, ... } @ args: let - cfg = (dev.mkFlake.evalArgs { inherit args; }).config; + cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix new file mode 100644 index 0000000..29d04bc --- /dev/null +++ b/lib/mkFlake/evalOldArgs.nix @@ -0,0 +1,154 @@ +{ self, dev, nixos, inputs, ... }: + +{ args }: +let + argOpts = with nixos.lib; { config, options, ... }: + let + inherit (dev) os; + + inherit (config) self; + + inputAttrs = with types; functionTo attrs; + moduleType = with types; anything // { + inherit (submodule { }) check; + description = "valid module"; + }; + in + { + options = with types; { + self = mkOption { + type = addCheck attrs nixos.lib.isStorePath; + description = "The flake to create the devos outputs for"; + }; + hosts = mkOption { + type = path; + default = "${self}/hosts"; + defaultText = "\${self}/hosts"; + apply = toString; + description = '' + Path to directory containing host configurations that will be exported + to the 'nixosConfigurations' output. + ''; + }; + packages = mkOption { + # functionTo changes arg names which breaks flake check + type = types.anything // { + check = builtins.isFunction; + description = "Nixpkgs overlay"; + }; + default = (final: prev: { }); + defaultText = "(final: prev: {})"; + description = '' + Overlay for custom packages that will be included in treewide 'pkgs'. + This should follow the standard nixpkgs overlay format - two argument function + that returns an attrset. + These packages will be exported to the 'packages' and 'legacyPackages' outputs. + ''; + }; + modules = mkOption { + type = listOf moduleType; + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in confgurations and export in 'nixosModules' output + ''; + }; + userModules = mkOption { + type = listOf moduleType; + default = [ ]; + apply = dev.pathsToImportedAttrs; + description = '' + list of modules to include in home-manager configurations and export in + 'homeModules' output + ''; + }; + profiles = mkOption { + type = path; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to profiles folder that can be collected into suites"; + }; + userProfiles = mkOption { + type = path; + default = "${self}/users/profiles"; + defaultText = "\${self}/users/profiles"; + apply = x: os.mkProfileAttrs (toString x); + description = "path to user profiles folder that can be collected into userSuites"; + }; + suites = + let + defaults = { user = { }; system = { }; }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = "{ user = {}; system = {}; }"; + apply = suites: defaults // os.mkSuites { + inherit suites; + inherit (config) profiles users userProfiles; + }; + description = '' + Function with inputs 'users' and 'profiles' that returns attribute set + with user and system suites. The former for Home Manager and the latter + for nixos configurations. + These can be accessed through the 'suites' specialArg in each config system. + ''; + }; + users = mkOption { + type = path; + default = "${self}/users"; + defaultText = "\${self}/users"; + apply = x: os.mkProfileAttrs (toString x); + description = '' + path to folder containing profiles that define system users + ''; + }; + extern = + let + defaults = { + modules = [ ]; + overlays = [ ]; + specialArgs = { }; + userModules = [ ]; + userSpecialArgs = { }; + }; + in + mkOption { + type = inputAttrs; + default = { ... }: defaults; + defaultText = '' + { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } + ''; + # So unneeded extern attributes can safely be deleted + apply = x: defaults // (x { inputs = inputs // self.inputs; }); + description = '' + Function with argument 'inputs' that contains all devos and ''${self}'s inputs. + The function should return an attribute set with modules, overlays, and + specialArgs to be included across nixos and home manager configurations. + Only attributes that are used should be returned. + ''; + }; + overlays = mkOption { + type = path; + default = "${self}/overlays"; + defaultText = "\${self}/overlays"; + apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + description = '' + path to folder containing overlays which will be applied to pkgs and exported in + the 'overlays' output + ''; + }; + overrides = mkOption rec { + type = attrs; + default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; + defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; + apply = x: default // x; + description = "attrset of packages and modules that will be pulled from nixpkgs master"; + }; + }; + }; +in +nixos.lib.evalModules { + modules = [ argOpts args ]; +} From 863c17621c33f8d86aaf949c608155e7fc00e0f6 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 19:30:55 -0500 Subject: [PATCH 020/137] libtests: outfactor in preparation of lib/flake.nix --- lib/pkgs-lib/tests/default.nix | 35 +------ lib/tests/default.nix | 27 ++++++ lib/tests/lib.nix | 93 +++++++++++++++++++ .../tests/profiles/foo/default.nix | 0 .../tests/profiles/t/default.nix | 0 lib/{pkgs-lib => }/tests/testPathsIn/bar | 0 lib/{pkgs-lib => }/tests/testPathsIn/baz | 0 lib/{pkgs-lib => }/tests/testPathsIn/foo | 0 .../tests/testPathsToImportedAttrs/bar.nix | 0 .../testPathsToImportedAttrs/dir/default.nix | 0 .../tests/testPathsToImportedAttrs/f.nix | 0 .../tests/testPathsToImportedAttrs/foo.nix | 0 .../tests/testPathsToImportedAttrs/t.nix | 0 13 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 lib/tests/default.nix create mode 100644 lib/tests/lib.nix rename lib/{pkgs-lib => }/tests/profiles/foo/default.nix (100%) rename lib/{pkgs-lib => }/tests/profiles/t/default.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/bar (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/baz (100%) rename lib/{pkgs-lib => }/tests/testPathsIn/foo (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/bar.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/dir/default.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/f.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/foo.nix (100%) rename lib/{pkgs-lib => }/tests/testPathsToImportedAttrs/t.nix (100%) diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 3c28468..891baee 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }: +{ pkgs, system, inputs, nixos, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let @@ -7,8 +7,7 @@ let nodes; deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = - { libTests = libTests; } - // lib.optionalAttrs (deployHosts != { }) { + lib.optionalAttrs (deployHosts != { }) { profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); } // lib.mapAttrs (n: v: v.activationPackage) homes; @@ -51,33 +50,5 @@ let machine.systemctl("is-system-running --wait") ''; }; - - libTests = pkgs.runCommandNoCC "devos-lib-tests" - { - buildInputs = [ - pkgs.nix - ( - let tests = pkgs-lib.callLibs ./lib.nix; - in - if tests == [ ] - then null - else throw (builtins.toJSON tests) - ) - ]; - } '' - datadir="${pkgs.nix}/share" - export TEST_ROOT=$(pwd)/test-tmp - export NIX_BUILD_HOOK= - export NIX_CONF_DIR=$TEST_ROOT/etc - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix - export NIX_STATE_DIR=$TEST_ROOT/var/nix - export NIX_STORE_DIR=$TEST_ROOT/store - export PAGER=cat - cacheDir=$TEST_ROOT/binary-cache - nix-store --init - - touch $out - ''; in -{ inherit mkTest libTests profilesTest mkChecks; } +{ inherit mkTest profilesTest mkChecks; } diff --git a/lib/tests/default.nix b/lib/tests/default.nix new file mode 100644 index 0000000..c13dd8a --- /dev/null +++ b/lib/tests/default.nix @@ -0,0 +1,27 @@ +{ pkgs, lib, dev, ... }: + +pkgs.runCommandNoCC "devos-lib-tests" + { + buildInputs = [ + pkgs.nix + ( + let tests = import ./lib.nix { inherit pkgs lib dev; }; in + if tests == [ ] then null + else throw (builtins.toJSON tests) + ) + ]; + } '' + datadir="${pkgs.nix}/share" + export TEST_ROOT=$(pwd)/test-tmp + export NIX_BUILD_HOOK= + export NIX_CONF_DIR=$TEST_ROOT/etc + export NIX_LOCALSTATE_DIR=$TEST_ROOT/var + export NIX_LOG_DIR=$TEST_ROOT/var/log/nix + export NIX_STATE_DIR=$TEST_ROOT/var/nix + export NIX_STORE_DIR=$TEST_ROOT/store + export PAGER=cat + cacheDir=$TEST_ROOT/binary-cache + nix-store --init + + touch $out + '' diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix new file mode 100644 index 0000000..68baa9f --- /dev/null +++ b/lib/tests/lib.nix @@ -0,0 +1,93 @@ +{ pkgs, lib, dev, ... }: +with dev; +lib.runTests { + testConcatAttrs = { + expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; + + expected = { foo = 1; bar = 2; baz = 3; }; + }; + + testGenAttrs' = { + expr = genAttrs' + [ "/foo/bar" "/baz/buzz" ] + (path: { + name = baseNameOf path; + value = "${path}/fizz"; + }); + + expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; }; + }; + + testMapFilterAttrs = { + expr = mapFilterAttrs + (n: v: n == "foobar" && v == 1) + (n: v: lib.nameValuePair ("${n}bar") (v + 1)) + { foo = 0; bar = 2; }; + + expected = { foobar = 1; }; + }; + + testPathsIn = { + expr = pathsIn (toString ./testPathsIn); + + expected = map toString [ + ./testPathsIn/bar + ./testPathsIn/baz + ./testPathsIn/foo + ]; + }; + + testPathsToImportedAttrs = { + expr = + pathsToImportedAttrs [ + (toString ./testPathsToImportedAttrs/dir) + ./testPathsToImportedAttrs/foo.nix + ./testPathsToImportedAttrs/bar.nix + ./testPathsToImportedAttrs/t.nix + ./testPathsToImportedAttrs/f.nix + ]; + + expected = { + dir = { a = 5; }; + foo = { bar = 1; }; + bar = { foo = 2; }; + t = true; + f = false; + }; + }; + + testRgxToString = lib.testAllTrue [ + (rgxToString ".+x" "vxk" == "vx") + (rgxToString "^fo" "foo" == "fo") + (rgxToString "a?" "a" == "a") + (rgxToString "hat" "foohatbar" == "hat") + ]; + + testSafeReadDir = { + expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir; + expected = { + foo = "directory"; + t = "directory"; + }; + }; + + testSuites = + let + profiles = os.mkProfileAttrs (toString ./profiles); + users = ""; + userProfiles = ""; + suites = { profiles, ... }: { + system.bar = [ profiles.foo ]; + }; + in + { + expr = os.mkSuites { inherit profiles users userProfiles suites; }; + expected = { + system = { + bar = [ profiles.foo.default ]; + allProfiles = [ profiles.foo.default profiles.t.default ]; + allUsers = [ ]; + }; + }; + }; +} diff --git a/lib/pkgs-lib/tests/profiles/foo/default.nix b/lib/tests/profiles/foo/default.nix similarity index 100% rename from lib/pkgs-lib/tests/profiles/foo/default.nix rename to lib/tests/profiles/foo/default.nix diff --git a/lib/pkgs-lib/tests/profiles/t/default.nix b/lib/tests/profiles/t/default.nix similarity index 100% rename from lib/pkgs-lib/tests/profiles/t/default.nix rename to lib/tests/profiles/t/default.nix diff --git a/lib/pkgs-lib/tests/testPathsIn/bar b/lib/tests/testPathsIn/bar similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/bar rename to lib/tests/testPathsIn/bar diff --git a/lib/pkgs-lib/tests/testPathsIn/baz b/lib/tests/testPathsIn/baz similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/baz rename to lib/tests/testPathsIn/baz diff --git a/lib/pkgs-lib/tests/testPathsIn/foo b/lib/tests/testPathsIn/foo similarity index 100% rename from lib/pkgs-lib/tests/testPathsIn/foo rename to lib/tests/testPathsIn/foo diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix b/lib/tests/testPathsToImportedAttrs/bar.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/bar.nix rename to lib/tests/testPathsToImportedAttrs/bar.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix b/lib/tests/testPathsToImportedAttrs/dir/default.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/dir/default.nix rename to lib/tests/testPathsToImportedAttrs/dir/default.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix b/lib/tests/testPathsToImportedAttrs/f.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/f.nix rename to lib/tests/testPathsToImportedAttrs/f.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix b/lib/tests/testPathsToImportedAttrs/foo.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/foo.nix rename to lib/tests/testPathsToImportedAttrs/foo.nix diff --git a/lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix b/lib/tests/testPathsToImportedAttrs/t.nix similarity index 100% rename from lib/pkgs-lib/tests/testPathsToImportedAttrs/t.nix rename to lib/tests/testPathsToImportedAttrs/t.nix From 5f89d274284e05a0cf35f8b58cae537756375567 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 1 Apr 2021 21:10:24 -0500 Subject: [PATCH 021/137] ref: extract lib into subflake --- flake.nix | 58 +++++++++++++-------------- lib/default.nix | 32 --------------- lib/devos/default.nix | 2 +- lib/devos/devosSystem.nix | 4 +- lib/devos/mkHosts.nix | 6 +-- lib/devos/mkPkgs.nix | 4 +- lib/flake.nix | 72 ++++++++++++++++++++++++++++++++++ lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalArgs.nix | 14 +++---- lib/mkFlake/evalOldArgs.nix | 8 ++-- lib/pkgs-lib/default.nix | 4 +- lib/pkgs-lib/shell/default.nix | 4 +- lib/pkgs-lib/tests/default.nix | 4 +- lib/tests/default.nix | 4 +- lib/tests/lib.nix | 4 +- 15 files changed, 131 insertions(+), 91 deletions(-) delete mode 100644 lib/default.nix create mode 100644 lib/flake.nix diff --git a/flake.nix b/flake.nix index fddbc85..b030f5c 100644 --- a/flake.nix +++ b/flake.nix @@ -5,17 +5,22 @@ { nixos.url = "nixpkgs/nixos-unstable"; override.url = "nixpkgs"; + devos.url = "path:./lib"; # TODO: outfactor into separate repo + devos.inputs = { + nixpkgs.follows = "nixos"; + deploy.inputs = { + flake-compat.follows = "flake-compat"; + naersk.follows = "naersk"; + nixpkgs.follows = "nixos"; + }; + }; + ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "override"; }; }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "override"; - deploy = { - url = "github:serokell/deploy-rs"; - inputs = { flake-compat.follows = "flake-compat"; naersk.follows = "naersk"; nixpkgs.follows = "override"; utils.follows = "utils"; }; - }; - devshell.url = "github:numtide/devshell"; flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; home.url = "github:nix-community/home-manager"; @@ -23,32 +28,27 @@ naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "override"; nixos-hardware.url = "github:nixos/nixos-hardware"; - utils.url = "github:numtide/flake-utils"; + pkgs.url = "path:./pkgs"; pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: - let - lib = import ./lib { inherit self nixos utils inputs; }; - in - lib.mkFlake - { - inherit self; - hosts = ./hosts; - packages = import ./pkgs; - suites = import ./suites; - extern = import ./extern; - overrides = import ./overrides; - overlays = ./overlays; - profiles = ./profiles; - userProfiles = ./users/profiles; - modules = import ./modules/module-list.nix; - userModules = import ./users/modules/module-list.nix; - } // { - inherit lib; - defaultTemplate = self.templates.flk; - templates.flk.path = ./.; - templates.flk.description = "flk template"; - }; + outputs = inputs@{ self, devos, nixos, nur, ... }: + devos.lib.mkFlake { + inherit self; + hosts = ./hosts; + packages = import ./pkgs; + suites = import ./suites; + extern = import ./extern; + overrides = import ./overrides; + overlays = ./overlays; + profiles = ./profiles; + userProfiles = ./users/profiles; + modules = import ./modules/module-list.nix; + userModules = import ./users/modules/module-list.nix; + } // { + defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; + }; } diff --git a/lib/default.nix b/lib/default.nix deleted file mode 100644 index 4ed82a4..0000000 --- a/lib/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -args@{ nixos, self, ... }: -let inherit (nixos) lib; in -lib.makeExtensible (final: - let callLibs = file: import file - ({ - inherit lib; - - dev = final; - } // args); - in - with final; - { - inherit callLibs; - - attrs = callLibs ./attrs.nix; - os = callLibs ./devos; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; - - mkFlake = { - __functor = callLibs ./mkFlake; - evalArgs = callLibs ./mkFlake/evalArgs.nix; - evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; - }; - - pkgs-lib = callLibs ./pkgs-lib; - - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir - pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn; - inherit (strings) rgxToString; - }) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index e580ef0..6851725 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, nixos, dev, ... }: +{ lib, dev, ... }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index b0f53fd..32af38a 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixos, self, inputs, ... }: +{ lib, nixpkgs, self, inputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -13,7 +13,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${nixpkgs}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 8a8abdb..984e70c 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixos, inputs, self, ... }: +{ lib, dev, nixpkgs, inputs, self, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -36,7 +36,7 @@ let hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixos}" + "nixpkgs=${nixpkgs}" "nixos-config=${self}/compat/nixos" "home-manager=${inputs.home}" ]; @@ -45,7 +45,7 @@ let nix.registry = { devos.flake = self; - nixos.flake = nixos; + nixos.flake = nixpkgs; override.flake = inputs.override; }; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index f3126ea..260e97b 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixos, self, inputs, ... }: +{ lib, dev, nixpkgs, self, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem @@ -22,6 +22,6 @@ ++ extern.overlays ++ (lib.attrValues self.overlays); in - { pkgs = dev.os.pkgImport nixos overlays system; } + { pkgs = dev.os.pkgImport nixpkgs overlays system; } ) ).pkgs diff --git a/lib/flake.nix b/lib/flake.nix new file mode 100644 index 0000000..b0d362b --- /dev/null +++ b/lib/flake.nix @@ -0,0 +1,72 @@ +{ + description = "DevOS environment configuriguration library."; + + inputs = + { + deploy.url = "github:serokell/deploy-rs"; + deploy.inputs = { + utils.follows = "flake-utils"; + }; + devshell.url = "github:numtide/devshell"; + flake-utils.url = "github:numtide/flake-utils"; + + }; + + outputs = inputs@{ self, nixpkgs, deploy, devshell, flake-utils, ... }: let + + inherit (nixpkgs) lib; + + # We work with a combined lib, internally ... + combinedLib = lib.extend (final: prev: + let callLibs = file: import file + ({ + lib = final; + dev = final; + inputs = inputs; + } // inputs); + in + with final; + { + inherit callLibs; + + attrs = callLibs ./attrs.nix; + os = callLibs ./devos; + lists = callLibs ./lists.nix; + strings = callLibs ./strings.nix; + + mkFlake = { + __functor = callLibs ./mkFlake; + evalArgs = callLibs ./mkFlake/evalArgs.nix; + evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; + }; + + pkgs-lib = callLibs ./pkgs-lib; + + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir + pathsToImportedAttrs concatAttrs filterPackages; + inherit (lists) pathsIn; + inherit (strings) rgxToString; + }); + + in { + + # ... but don't force that choice onto the user + lib = { + mkFlake = combinedLib.mkFlake; + pkgs-lib = combinedLib.pkgs-lib; + }; + + + checks = flake-utils.lib.eachDefaultSystem (system: let + nixpkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + in + { + tests = import ./tests { + inherit (nixpkgs) pkgs; + inherit (self) lib; + }; + } + ); + }; + +} diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 4fd6947..916e349 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ dev, nixos, inputs, ... }: +{ dev, inputs, ... }: let inherit (dev) os; inherit (inputs) utils deploy; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index d368176..ac3d0c8 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,8 +1,8 @@ -{ self, dev, nixos, inputs, utils, ... }: +{ self, dev, lib, inputs, utils, ... }: { args }: let - argOpts = with nixos.lib; { config, ... }: + argOpts = with lib; { config, ... }: let inherit (dev) os; @@ -25,7 +25,7 @@ let description = "valid Nixpkgs overlay"; }; systemType = types.enum config.supportedSystems; - flakeType = with types; (addCheck attrs nixos.lib.isStorePath) // { + flakeType = with types; (addCheck attrs lib.isStorePath) // { description = "nix flake"; }; @@ -54,10 +54,10 @@ let options = with types; { input = mkOption { type = flakeType; - default = inputs.nixos; + default = inputs.nixpkgs; description = '' nixpkgs flake input to use for this channel - ''; + ''; }; overlays = mkOption { type = pathTo (listOf overlayType); @@ -199,7 +199,7 @@ let let default = { nixpkgs = { - input = inputs.nixos; + input = inputs.nixpkgs; }; }; in @@ -228,6 +228,6 @@ let }; }; in -nixos.lib.evalModules { +lib.evalModules { modules = [ argOpts args ]; } diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 29d04bc..ef9360a 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,8 +1,8 @@ -{ self, dev, nixos, inputs, ... }: +{ self, dev, lib, inputs, ... }: { args }: let - argOpts = with nixos.lib; { config, options, ... }: + argOpts = with lib; { config, options, ... }: let inherit (dev) os; @@ -17,7 +17,7 @@ let { options = with types; { self = mkOption { - type = addCheck attrs nixos.lib.isStorePath; + type = addCheck attrs lib.isStorePath; description = "The flake to create the devos outputs for"; }; hosts = mkOption { @@ -149,6 +149,6 @@ let }; }; in -nixos.lib.evalModules { +lib.evalModules { modules = [ argOpts args ]; } diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 807b44f..cf74b7f 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,8 +1,8 @@ -args@{ lib, dev, utils, nixos, ... }: +args@{ lib, dev, utils, nixpkgs, ... }: lib.genAttrs utils.lib.defaultSystems (system: lib.makeExtensible (final: let - pkgs = import nixos { inherit system; }; + pkgs = import nixpkgs { inherit system; }; callLibs = file: import file (args // { inherit pkgs system; diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index ed78187..6a3e4bf 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, inputs, system, nixos, ... }: +{ lib, dev, inputs, system, nixpkgs, ... }: let overlays = [ inputs.devshell.overlay @@ -8,7 +8,7 @@ let }) ]; - pkgs = dev.os.pkgImport nixos overlays system; + pkgs = dev.os.pkgImport nixpkgs overlays system; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 891baee..64ca44e 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs, system, inputs, nixos, lib, ... }: +{ pkgs, system, inputs, nixpkgs, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let @@ -17,7 +17,7 @@ let mkTest = host: let nixosTesting = - (import "${nixos}/nixos/lib/testing-python.nix" { + (import "${nixpkgs}/nixos/lib/testing-python.nix" { inherit system; inherit (host.config.lib) specialArgs; inherit pkgs; diff --git a/lib/tests/default.nix b/lib/tests/default.nix index c13dd8a..4863cdf 100644 --- a/lib/tests/default.nix +++ b/lib/tests/default.nix @@ -1,11 +1,11 @@ -{ pkgs, lib, dev, ... }: +{ pkgs, lib }: pkgs.runCommandNoCC "devos-lib-tests" { buildInputs = [ pkgs.nix ( - let tests = import ./lib.nix { inherit pkgs lib dev; }; in + let tests = import ./lib.nix { inherit pkgs lib; }; in if tests == [ ] then null else throw (builtins.toJSON tests) ) diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index 68baa9f..6626478 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -1,5 +1,5 @@ -{ pkgs, lib, dev, ... }: -with dev; +{ pkgs, lib }: +with lib; lib.runTests { testConcatAttrs = { expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; From 21a03fa94c9a3bb63f1be88857c80e5900c18cf4 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:23:27 -0500 Subject: [PATCH 022/137] fixup: nix flake check I / X --- flake.lock | 131 +++++++++++++++++++++++++++++++++++++++----------- lib/flake.nix | 30 +++++++----- 2 files changed, 123 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index 3996268..a3c6ce9 100644 --- a/flake.lock +++ b/flake.lock @@ -52,25 +52,17 @@ }, "deploy": { "inputs": { - "flake-compat": [ - "flake-compat" - ], - "naersk": [ - "naersk" - ], - "nixpkgs": [ - "override" - ], - "utils": [ - "utils" - ] + "flake-compat": "flake-compat", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "utils": "utils" }, "locked": { - "lastModified": 1614654775, - "narHash": "sha256-3mLxoxIXSWUuKE8YgIuqM5AZzXFd1aWxkTlplEDeXIA=", + "lastModified": 1616406726, + "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", "owner": "serokell", "repo": "deploy-rs", - "rev": "6278b9bef5ad624676a565980417cbbef42d5227", + "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", "type": "github" }, "original": { @@ -79,13 +71,32 @@ "type": "github" } }, + "devos": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixos" + ] + }, + "locked": { + "narHash": "sha256-077+hIF3WGvzgD3DeykCCKFL4xsgnE3ONaCNDnxH1t4=", + "path": "./lib", + "type": "path" + }, + "original": { + "path": "./lib", + "type": "path" + } + }, "devshell": { "locked": { - "lastModified": 1613641255, - "narHash": "sha256-iSvjFK4WYAKhuXCCtkY7uy/cFQTzS3D3Ml5WZqjEfL0=", + "lastModified": 1618523768, + "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", "owner": "numtide", "repo": "devshell", - "rev": "ff6cffba08600f5b7b43f398fcb58bef023bc4c4", + "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", "type": "github" }, "original": { @@ -95,6 +106,22 @@ } }, "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { "flake": false, "locked": { "lastModified": 1611461076, @@ -111,6 +138,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1618217525, + "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home": { "inputs": { "nixpkgs": [ @@ -132,6 +174,27 @@ } }, "naersk": { + "inputs": { + "nixpkgs": [ + "override" + ] + }, + "locked": { + "lastModified": 1610392286, + "narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=", + "owner": "nmattia", + "repo": "naersk", + "rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "naersk_2": { "inputs": { "nixpkgs": [ "override" @@ -181,6 +244,22 @@ "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1610942247, + "narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7d71001b796340b219d1bfa8552c81995017544a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "locked": { "lastModified": 1615921934, @@ -245,26 +324,24 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "deploy": "deploy", - "devshell": "devshell", - "flake-compat": "flake-compat", + "devos": "devos", + "flake-compat": "flake-compat_2", "home": "home", - "naersk": "naersk", + "naersk": "naersk_2", "nixos": "nixos", "nixos-hardware": "nixos-hardware", "nur": "nur", "override": "override", - "pkgs": "pkgs", - "utils": "utils" + "pkgs": "pkgs" } }, "utils": { "locked": { - "lastModified": 1614513358, - "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "lastModified": 1610051610, + "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", "owner": "numtide", "repo": "flake-utils", - "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", "type": "github" }, "original": { diff --git a/lib/flake.nix b/lib/flake.nix index b0d362b..620e208 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -5,14 +5,14 @@ { deploy.url = "github:serokell/deploy-rs"; deploy.inputs = { - utils.follows = "flake-utils"; + utils.follows = "utils"; }; devshell.url = "github:numtide/devshell"; - flake-utils.url = "github:numtide/flake-utils"; + utils.url = "github:numtide/flake-utils"; }; - outputs = inputs@{ self, nixpkgs, deploy, devshell, flake-utils, ... }: let + outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let inherit (nixpkgs) lib; @@ -48,7 +48,9 @@ inherit (strings) rgxToString; }); - in { + in + + { # ... but don't force that choice onto the user lib = { @@ -57,16 +59,22 @@ }; - checks = flake-utils.lib.eachDefaultSystem (system: let - nixpkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + } + + // + + utils.lib.eachDefaultSystem (system: + let + nixpkgs' = import nixpkgs { inherit system; overlays = []; config = {}; }; in { - tests = import ./tests { - inherit (nixpkgs) pkgs; - inherit (self) lib; + checks = { + tests = import ./tests { + inherit (nixpkgs') pkgs; + lib = combinedLib; + }; }; } - ); - }; + ); } From 6116779b23e5e5e189175fd29b220f13525fbdb0 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:40:57 -0500 Subject: [PATCH 023/137] fixup: nix flake check II / II --- lib/flake.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 620e208..25e451c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -26,13 +26,15 @@ } // inputs); in with final; + let + attrs = callLibs ./attrs.nix; + lists = callLibs ./lists.nix; + strings = callLibs ./strings.nix; + in { inherit callLibs; - attrs = callLibs ./attrs.nix; os = callLibs ./devos; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; mkFlake = { __functor = callLibs ./mkFlake; From 19c900e2933999f27fbe5a2015745a02adb3a6e6 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 17:45:51 -0500 Subject: [PATCH 024/137] workarround for unkown problem --- flake.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b030f5c..443c9b9 100644 --- a/flake.nix +++ b/flake.nix @@ -8,11 +8,11 @@ devos.url = "path:./lib"; # TODO: outfactor into separate repo devos.inputs = { nixpkgs.follows = "nixos"; - deploy.inputs = { - flake-compat.follows = "flake-compat"; - naersk.follows = "naersk"; - nixpkgs.follows = "nixos"; - }; + # deploy.inputs = { + # flake-compat.follows = "flake-compat"; + # naersk.follows = "naersk"; + # nixpkgs.follows = "nixos"; + # }; }; ci-agent = { From c24199649a3f58a6203f823d555143394a8cd134 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 18:30:07 -0500 Subject: [PATCH 025/137] fixup: distinguish self and userSelf --- lib/devos/devosSystem.nix | 6 +++--- lib/devos/mkHomeConfigurations.nix | 4 ++-- lib/devos/mkHosts.nix | 14 +++++++------- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 6 +++--- lib/mkFlake/default.nix | 12 +++++++----- lib/mkFlake/evalArgs.nix | 6 +++--- lib/mkFlake/evalOldArgs.nix | 26 +++++++++++++------------- 8 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 32af38a..dbe3af4 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, self, inputs, ... }: +{ lib, nixpkgs, userSelf, inputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -27,11 +27,11 @@ lib.nixosSystem (args // { isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = self; + source = userSelf; target = "/devos/"; }]; isoImage.storeContents = [ - self.devShell.${config.nixpkgs.system} + userSelf.devShell.${config.nixpkgs.system} # include also closures that are "switched off" by the # above profile filter on the local config attribute fullHostConfig.system.build.toplevel diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 490975a..5d39cdd 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,4 @@ -{ lib, self, ... }: +{ lib, userSelf, ... }: with lib; let @@ -6,7 +6,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes self.nixosConfigurations; + hmConfigs = mapAttrs mkHomes userSelf.nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 984e70c..1bc6bf9 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, inputs, self, ... }: +{ lib, dev, nixpkgs, inputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -29,7 +29,7 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues userSelf.homeModules); }; users.mutableUsers = lib.mkDefault false; @@ -37,14 +37,14 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" - "nixos-config=${self}/compat/nixos" + "nixos-config=${userSelf}/compat/nixos" "home-manager=${inputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = self; + devos.flake = userSelf; nixos.flake = nixpkgs; override.flake = inputs.override; }; @@ -57,11 +57,11 @@ let } ''; - system.configurationRevision = lib.mkIf (self ? rev) self.rev; + system.configurationRevision = lib.mkIf (userSelf ? rev) userSelf.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues userSelf.nixosModules ++ extern.modules; }; cachix = ../../cachix.nix; }; @@ -78,7 +78,7 @@ let networking = { inherit hostName; }; _module.args = { - inherit self; + self = userSelf; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index a876ea0..1b3404a 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,8 +1,8 @@ -{ lib, dev, self, ... }: +{ lib, dev, userSelf, ... }: { pkgs }: let - inherit (self) overlay overlays; + inherit (userSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) ++ lib.attrNames (dev.concatAttrs (lib.attrValues diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 260e97b..d2d07db 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, self, inputs, ... }: +{ lib, dev, nixpkgs, userSelf, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem @@ -17,10 +17,10 @@ }); }) (overridesOverlay overridePkgs) - self.overlay + userSelf.overlay ] ++ extern.overlays - ++ (lib.attrValues self.overlays); + ++ (lib.attrValues userSelf.overlays); in { pkgs = dev.os.pkgImport nixpkgs overlays system; } ) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 916e349..6fdca16 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -7,13 +7,15 @@ in _: { self, ... } @ args: let + userSelf = self; + cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; outputs = { nixosConfigurations = os.mkHosts { - inherit self multiPkgs; + inherit userSelf multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; @@ -27,7 +29,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + deploy.nodes = os.mkNodes deploy userSelf.nixosConfigurations; }; systemOutputs = utils.lib.eachDefaultSystem (system: @@ -39,9 +41,9 @@ let in { checks = pkgs-lib.tests.mkChecks { - inherit (self.deploy) nodes; - hosts = self.nixosConfigurations; - homes = self.homeConfigurations; + inherit (userSelf.deploy) nodes; + hosts = userSelf.nixosConfigurations; + homes = userSelf.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ac3d0c8..ad866ea 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ self, dev, lib, inputs, utils, ... }: +{ userSelf, dev, lib, inputs, utils, ... }: { args }: let @@ -161,8 +161,8 @@ let }; profiles = mkOption { type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; + default = "${userSelf}/profiles"; + defaultText = "\${userSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index ef9360a..f728b48 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,4 @@ -{ self, dev, lib, inputs, ... }: +{ userSelf, dev, lib, inputs, ... }: { args }: let @@ -22,8 +22,8 @@ let }; hosts = mkOption { type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; + default = "${userSelf}/hosts"; + defaultText = "\${userSelf}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -64,15 +64,15 @@ let }; profiles = mkOption { type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; + default = "${userSelf}/profiles"; + defaultText = "\${userSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; + default = "${userSelf}/users/profiles"; + defaultText = "\${userSelf}/users/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to user profiles folder that can be collected into userSuites"; }; @@ -97,8 +97,8 @@ let }; users = mkOption { type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; + default = "${userSelf}/users"; + defaultText = "\${userSelf}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -121,9 +121,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); + apply = x: defaults // (x { inputs = inputs // userSelf.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. + Function with argument 'inputs' that contains all devos and ''${userSelf}'s inputs. The function should return an attribute set with modules, overlays, and specialArgs to be included across nixos and home manager configurations. Only attributes that are used should be returned. @@ -131,8 +131,8 @@ let }; overlays = mkOption { type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; + default = "${userSelf}/overlays"; + defaultText = "\${userSelf}/overlays"; apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in From fb6c6ba4cf693df6f87921d418a2e8d176d45a4b Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 19:15:53 -0500 Subject: [PATCH 026/137] fix: update devos in flake.lock --- flake.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index a3c6ce9..531c981 100644 --- a/flake.lock +++ b/flake.lock @@ -75,13 +75,13 @@ "inputs": { "deploy": "deploy", "devshell": "devshell", - "flake-utils": "flake-utils", "nixpkgs": [ "nixos" - ] + ], + "utils": "utils_2" }, "locked": { - "narHash": "sha256-077+hIF3WGvzgD3DeykCCKFL4xsgnE3ONaCNDnxH1t4=", + "narHash": "sha256-/SJJ8u/qBnCtMbMxBmDNBDnLWnmro2ioi35gL45hP9w=", "path": "./lib", "type": "path" }, @@ -138,21 +138,6 @@ "type": "github" } }, - "flake-utils": { - "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "home": { "inputs": { "nixpkgs": [ @@ -349,6 +334,21 @@ "repo": "flake-utils", "type": "github" } + }, + "utils_2": { + "locked": { + "lastModified": 1618217525, + "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", From 16b3fad559b6f44eda5068eb369d1dd83827de7f Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:35:05 -0500 Subject: [PATCH 027/137] ref: merge dev into lib --- lib/devos/default.nix | 20 ++++++++++---------- lib/devos/mkHosts.nix | 6 +++--- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 8 ++++---- lib/devos/mkProfileAttrs.nix | 4 ++-- lib/devos/mkSuites.nix | 4 ++-- lib/devos/recImport.nix | 6 +++--- lib/flake.nix | 1 - lib/lists.nix | 4 ++-- lib/mkFlake/default.nix | 8 ++++---- lib/mkFlake/evalArgs.nix | 8 ++++---- lib/mkFlake/evalOldArgs.nix | 10 +++++----- lib/pkgs-lib/default.nix | 2 +- lib/pkgs-lib/shell/default.nix | 4 ++-- lib/pkgs-lib/tests/lib.nix | 4 ++-- 15 files changed, 46 insertions(+), 47 deletions(-) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 6851725..fb9e990 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, ... }: +{ lib, ... }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: @@ -9,22 +9,22 @@ profileMap = map (profile: profile.default); - mkNodes = dev.callLibs ./mkNodes.nix; + mkNodes = lib.callLibs ./mkNodes.nix; - mkHosts = dev.callLibs ./mkHosts.nix; + mkHosts = lib.callLibs ./mkHosts.nix; - mkSuites = dev.callLibs ./mkSuites.nix; + mkSuites = lib.callLibs ./mkSuites.nix; - mkProfileAttrs = dev.callLibs ./mkProfileAttrs.nix; + mkProfileAttrs = lib.callLibs ./mkProfileAttrs.nix; - mkPkgs = dev.callLibs ./mkPkgs.nix; + mkPkgs = lib.callLibs ./mkPkgs.nix; - recImport = dev.callLibs ./recImport.nix; + recImport = lib.callLibs ./recImport.nix; - devosSystem = dev.callLibs ./devosSystem.nix; + devosSystem = lib.callLibs ./devosSystem.nix; - mkHomeConfigurations = dev.callLibs ./mkHomeConfigurations.nix; + mkHomeConfigurations = lib.callLibs ./mkHomeConfigurations.nix; - mkPackages = dev.callLibs ./mkPackages.nix; + mkPackages = lib.callLibs ./mkPackages.nix; } diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 1bc6bf9..056c4e7 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, dev, nixpkgs, inputs, userSelf, ... }: +{ lib, nixpkgs, inputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -90,13 +90,13 @@ let }; }; in - dev.os.devosSystem { + lib.os.devosSystem { inherit specialArgs; system = defaultSystem; modules = modules // { inherit local lib; }; }; - hosts = dev.os.recImport + hosts = lib.os.recImport { inherit dir; _import = mkHostConfig; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index 1b3404a..a9d37bb 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,10 +1,10 @@ -{ lib, dev, userSelf, ... }: +{ lib, userSelf, ... }: { pkgs }: let inherit (userSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) - ++ lib.attrNames (dev.concatAttrs + ++ lib.attrNames (lib.concatAttrs (lib.attrValues (lib.mapAttrs (_: v: v null null) overlays) ) diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index d2d07db..fda3cad 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,16 +1,16 @@ -{ lib, dev, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, inputs, ... }: { extern, overrides }: (inputs.utils.lib.eachDefaultSystem (system: let - overridePkgs = dev.os.pkgImport inputs.override [ ] system; + overridePkgs = lib.os.pkgImport inputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ (final: prev: { lib = prev.lib.extend (lfinal: lprev: { - inherit dev; + inherit lib; inherit (lib) nixosSystem; utils = inputs.utils.lib; @@ -22,6 +22,6 @@ ++ extern.overlays ++ (lib.attrValues userSelf.overlays); in - { pkgs = dev.os.pkgImport nixpkgs overlays system; } + { pkgs = lib.os.pkgImport nixpkgs overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index d89c6ba..7168b29 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -1,4 +1,4 @@ -{ lib, dev, ... }: +{ lib, ... }: let mkProfileAttrs = /** @@ -16,7 +16,7 @@ let mkProfileAttrs = let imports = let - files = dev.safeReadDir dir; + files = lib.safeReadDir dir; p = n: v: v == "directory" diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index a3a3294..0a5950b 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,8 +1,8 @@ -{ lib, dev, ... }: +{ lib, ... }: { users, profiles, userProfiles, suites } @ args: let - inherit (dev) os; + inherit (lib) os; definedSuites = suites { inherit (args) users profiles userProfiles; diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix index d7f2aa8..e9e5da6 100644 --- a/lib/devos/recImport.nix +++ b/lib/devos/recImport.nix @@ -1,7 +1,7 @@ -{ lib, dev, ... }: +{ lib, ... }: { dir, _import ? base: import "${dir}/${base}.nix" }: -dev.mapFilterAttrs +lib.mapFilterAttrs (_: v: v != null) (n: v: if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" @@ -9,4 +9,4 @@ dev.mapFilterAttrs let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) else lib.nameValuePair ("") (null)) - (dev.safeReadDir dir) + (lib.safeReadDir dir) diff --git a/lib/flake.nix b/lib/flake.nix index 25e451c..75bfb89 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,7 +21,6 @@ let callLibs = file: import file ({ lib = final; - dev = final; inputs = inputs; } // inputs); in diff --git a/lib/lists.nix b/lib/lists.nix index b6530f1..74cf9bd 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,8 +1,8 @@ -{ lib, dev, ... }: +{ lib, ... }: { pathsIn = dir: let fullPath = name: "${toString dir}/${name}"; in - map fullPath (lib.attrNames (dev.safeReadDir dir)); + map fullPath (lib.attrNames (lib.safeReadDir dir)); } diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 6fdca16..eadb7e4 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ dev, inputs, ... }: +{ lib, inputs, ... }: let inherit (dev) os; inherit (inputs) utils deploy; @@ -9,7 +9,7 @@ let userSelf = self; - cfg = (dev.mkFlake.evalOldArgs { inherit args; }).config; + cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; @@ -35,7 +35,7 @@ let systemOutputs = utils.lib.eachDefaultSystem (system: let pkgs = multiPkgs.${system}; - pkgs-lib = dev.pkgs-lib.${system}; + pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs legacyPackages = os.mkPackages { inherit pkgs; }; in @@ -47,7 +47,7 @@ let }; inherit legacyPackages; - packages = dev.filterPackages system legacyPackages; + packages = lib.filterPackages system legacyPackages; devShell = pkgs-lib.shell; }); diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ad866ea..9836b25 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,10 +1,10 @@ -{ userSelf, dev, lib, inputs, utils, ... }: +{ userSelf, lib, inputs, utils, ... }: { args }: let argOpts = with lib; { config, ... }: let - inherit (dev) os; + inherit (lib) os; inherit (config) self; @@ -146,7 +146,7 @@ let modules = mkOption { type = pathTo (listOf moduleType); default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confgurations and export in '${name}Modules' output ''; @@ -154,7 +154,7 @@ let externalModules = mkOption { type = pathTo (listOf moduleType); default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confguration but these are not exported to the '${name}Modules' output ''; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index f728b48..68a0d5f 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,10 +1,10 @@ -{ userSelf, dev, lib, inputs, ... }: +{ userSelf, lib, inputs, ... }: { args }: let argOpts = with lib; { config, options, ... }: let - inherit (dev) os; + inherit (lib) os; inherit (config) self; @@ -48,7 +48,7 @@ let modules = mkOption { type = listOf moduleType; default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in confgurations and export in 'nixosModules' output ''; @@ -56,7 +56,7 @@ let userModules = mkOption { type = listOf moduleType; default = [ ]; - apply = dev.pathsToImportedAttrs; + apply = lib.pathsToImportedAttrs; description = '' list of modules to include in home-manager configurations and export in 'homeModules' output @@ -133,7 +133,7 @@ let type = path; default = "${userSelf}/overlays"; defaultText = "\${userSelf}/overlays"; - apply = x: dev.pathsToImportedAttrs (dev.pathsIn (toString x)); + apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in the 'overlays' output diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index cf74b7f..ae448a4 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,4 +1,4 @@ -args@{ lib, dev, utils, nixpkgs, ... }: +args@{ lib, utils, nixpkgs, ... }: lib.genAttrs utils.lib.defaultSystems (system: lib.makeExtensible (final: let diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 6a3e4bf..e5c2d7c 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,4 +1,4 @@ -{ lib, dev, inputs, system, nixpkgs, ... }: +{ lib, inputs, system, nixpkgs, ... }: let overlays = [ inputs.devshell.overlay @@ -8,7 +8,7 @@ let }) ]; - pkgs = dev.os.pkgImport nixpkgs overlays system; + pkgs = lib.os.pkgImport nixpkgs overlays system; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/lib.nix b/lib/pkgs-lib/tests/lib.nix index 68baa9f..586eac3 100644 --- a/lib/pkgs-lib/tests/lib.nix +++ b/lib/pkgs-lib/tests/lib.nix @@ -1,5 +1,5 @@ -{ pkgs, lib, dev, ... }: -with dev; +{ pkgs, lib, ... }: +with lib; lib.runTests { testConcatAttrs = { expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; From cd7fb4f54c81e19c93e7cc067b2022d6216bf0fc Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:46:20 -0500 Subject: [PATCH 028/137] ref: flatten out inputs --- lib/devos/devosSystem.nix | 4 ++-- lib/devos/mkHosts.nix | 6 +++--- lib/devos/mkPkgs.nix | 6 +++--- lib/flake.nix | 2 +- lib/mkFlake/default.nix | 3 +-- lib/mkFlake/evalArgs.nix | 6 +++--- lib/pkgs-lib/shell/default.nix | 6 +++--- lib/pkgs-lib/tests/default.nix | 4 ++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index dbe3af4..249e2c7 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, userFlakeInputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -23,7 +23,7 @@ lib.nixosSystem (args // { disabledModules = map (x: [ x ]) (lib.remove modules.core suites.allProfiles); - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; + nix.registry = lib.mapAttrs (n: v: { flake = v; }) userFlakeInputs; isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 056c4e7..21ece03 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, inputs, userSelf, ... }: +{ lib, nixpkgs, userFlakeInputs, userSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -38,7 +38,7 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" "nixos-config=${userSelf}/compat/nixos" - "home-manager=${inputs.home}" + "home-manager=${userFlakeInputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; @@ -46,7 +46,7 @@ let nix.registry = { devos.flake = userSelf; nixos.flake = nixpkgs; - override.flake = inputs.override; + override.flake = userFlakeInputs.override; }; nix.package = pkgs.nixFlakes; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index fda3cad..6165707 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,10 +1,10 @@ -{ lib, nixpkgs, userSelf, inputs, ... }: +{ lib, nixpkgs, userSelf, utils, userFlakeInputs, ... }: { extern, overrides }: -(inputs.utils.lib.eachDefaultSystem +(utils.lib.eachDefaultSystem (system: let - overridePkgs = lib.os.pkgImport inputs.override [ ] system; + overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ diff --git a/lib/flake.nix b/lib/flake.nix index 75bfb89..47b9ffc 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,7 +21,7 @@ let callLibs = file: import file ({ lib = final; - inputs = inputs; + userFlakeInputs = {}; # TODO: Erm, this must become a proper argument to mkFlake } // inputs); in with final; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index eadb7e4..a37fa83 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,7 +1,6 @@ -{ lib, inputs, ... }: +{ lib, utils, deploy, ... }: let inherit (dev) os; - inherit (inputs) utils deploy; in _: { self, ... } @ args: diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 9836b25..c157164 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, inputs, utils, ... }: +{ userSelf, lib, nixpkgs, utils, ... }: { args }: let @@ -54,7 +54,7 @@ let options = with types; { input = mkOption { type = flakeType; - default = inputs.nixpkgs; + default = nixpkgs; description = '' nixpkgs flake input to use for this channel ''; @@ -199,7 +199,7 @@ let let default = { nixpkgs = { - input = inputs.nixpkgs; + input = nixpkgs; }; }; in diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index e5c2d7c..71c6c29 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,10 +1,10 @@ -{ lib, inputs, system, nixpkgs, ... }: +{ lib, devshell, deploy, system, nixpkgs, ... }: let overlays = [ - inputs.devshell.overlay + devshell.overlay (final: prev: { deploy-rs = - inputs.deploy.packages.${prev.system}.deploy-rs; + deploy.packages.${prev.system}.deploy-rs; }) ]; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 64ca44e..a72ade6 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,11 +1,11 @@ -{ pkgs, system, inputs, nixpkgs, lib, ... }: +{ pkgs, system, deploy, nixpkgs, lib, ... }: let mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs (n: _: hosts.${n}.config.nixpkgs.system == system) nodes; - deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = lib.optionalAttrs (deployHosts != { }) { profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); From 6cccb5526378452afeafd7fca5e66dee41a44b46 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 19:35:11 -0500 Subject: [PATCH 029/137] ref: userSelf -> userFlakeSelf --- lib/devos/devosSystem.nix | 6 +++--- lib/devos/mkHomeConfigurations.nix | 4 ++-- lib/devos/mkHosts.nix | 14 +++++++------- lib/devos/mkPackages.nix | 4 ++-- lib/devos/mkPkgs.nix | 6 +++--- lib/mkFlake/default.nix | 12 ++++++------ lib/mkFlake/evalArgs.nix | 6 +++--- lib/mkFlake/evalOldArgs.nix | 26 +++++++++++++------------- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 249e2c7..121638c 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, userFlakeInputs, ... }: +{ lib, nixpkgs, userFlakeSelf, userFlakeInputs, ... }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -27,11 +27,11 @@ lib.nixosSystem (args // { isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = userSelf; + source = userFlakeSelf; target = "/devos/"; }]; isoImage.storeContents = [ - userSelf.devShell.${config.nixpkgs.system} + userFlakeSelf.devShell.${config.nixpkgs.system} # include also closures that are "switched off" by the # above profile filter on the local config attribute fullHostConfig.system.build.toplevel diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 5d39cdd..34c5e93 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,4 @@ -{ lib, userSelf, ... }: +{ lib, userFlakeSelf, ... }: with lib; let @@ -6,7 +6,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes userSelf.nixosConfigurations; + hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 21ece03..b11bda9 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userFlakeInputs, userSelf, ... }: +{ lib, nixpkgs, userFlakeInputs, userFlakeSelf, ... }: { dir, extern, suites, overrides, multiPkgs, ... }: let @@ -29,7 +29,7 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues userSelf.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues userFlakeSelf.homeModules); }; users.mutableUsers = lib.mkDefault false; @@ -37,14 +37,14 @@ let nix.nixPath = [ "nixpkgs=${nixpkgs}" - "nixos-config=${userSelf}/compat/nixos" + "nixos-config=${userFlakeSelf}/compat/nixos" "home-manager=${userFlakeInputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = userSelf; + devos.flake = userFlakeSelf; nixos.flake = nixpkgs; override.flake = userFlakeInputs.override; }; @@ -57,11 +57,11 @@ let } ''; - system.configurationRevision = lib.mkIf (userSelf ? rev) userSelf.rev; + system.configurationRevision = lib.mkIf (userFlakeSelf ? rev) userFlakeSelf.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues userSelf.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; cachix = ../../cachix.nix; }; @@ -78,7 +78,7 @@ let networking = { inherit hostName; }; _module.args = { - self = userSelf; + self = userFlakeSelf; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index a9d37bb..17cba0e 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,8 +1,8 @@ -{ lib, userSelf, ... }: +{ lib, userFlakeSelf, ... }: { pkgs }: let - inherit (userSelf) overlay overlays; + inherit (userFlakeSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) ++ lib.attrNames (lib.concatAttrs (lib.attrValues diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 6165707..ed669e4 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,4 +1,4 @@ -{ lib, nixpkgs, userSelf, utils, userFlakeInputs, ... }: +{ lib, nixpkgs, userFlakeSelf, utils, userFlakeInputs, ... }: { extern, overrides }: (utils.lib.eachDefaultSystem @@ -17,10 +17,10 @@ }); }) (overridesOverlay overridePkgs) - userSelf.overlay + userFlakeSelf.overlay ] ++ extern.overlays - ++ (lib.attrValues userSelf.overlays); + ++ (lib.attrValues userFlakeSelf.overlays); in { pkgs = lib.os.pkgImport nixpkgs overlays system; } ) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index a37fa83..fbb2554 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -6,7 +6,7 @@ in _: { self, ... } @ args: let - userSelf = self; + userFlakeSelf = self; cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; @@ -14,7 +14,7 @@ let outputs = { nixosConfigurations = os.mkHosts { - inherit userSelf multiPkgs; + inherit userFlakeSelf multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; @@ -28,7 +28,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy userSelf.nixosConfigurations; + deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; }; systemOutputs = utils.lib.eachDefaultSystem (system: @@ -40,9 +40,9 @@ let in { checks = pkgs-lib.tests.mkChecks { - inherit (userSelf.deploy) nodes; - hosts = userSelf.nixosConfigurations; - homes = userSelf.homeConfigurations; + inherit (userFlakeSelf.deploy) nodes; + hosts = userFlakeSelf.nixosConfigurations; + homes = userFlakeSelf.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index c157164..3f85080 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, nixpkgs, utils, ... }: +{ userFlakeSelf, lib, nixpkgs, utils, ... }: { args }: let @@ -161,8 +161,8 @@ let }; profiles = mkOption { type = path; - default = "${userSelf}/profiles"; - defaultText = "\${userSelf}/profiles"; + default = "${userFlakeSelf}/profiles"; + defaultText = "\${userFlakeSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 68a0d5f..25dd7c9 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,4 @@ -{ userSelf, lib, inputs, ... }: +{ userFlakeSelf, lib, inputs, ... }: { args }: let @@ -22,8 +22,8 @@ let }; hosts = mkOption { type = path; - default = "${userSelf}/hosts"; - defaultText = "\${userSelf}/hosts"; + default = "${userFlakeSelf}/hosts"; + defaultText = "\${userFlakeSelf}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -64,15 +64,15 @@ let }; profiles = mkOption { type = path; - default = "${userSelf}/profiles"; - defaultText = "\${userSelf}/profiles"; + default = "${userFlakeSelf}/profiles"; + defaultText = "\${userFlakeSelf}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { type = path; - default = "${userSelf}/users/profiles"; - defaultText = "\${userSelf}/users/profiles"; + default = "${userFlakeSelf}/users/profiles"; + defaultText = "\${userFlakeSelf}/users/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to user profiles folder that can be collected into userSuites"; }; @@ -97,8 +97,8 @@ let }; users = mkOption { type = path; - default = "${userSelf}/users"; - defaultText = "\${userSelf}/users"; + default = "${userFlakeSelf}/users"; + defaultText = "\${userFlakeSelf}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -121,9 +121,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // userSelf.inputs; }); + apply = x: defaults // (x { inputs = inputs // userFlakeSelf.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${userSelf}'s inputs. + Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. The function should return an attribute set with modules, overlays, and specialArgs to be included across nixos and home manager configurations. Only attributes that are used should be returned. @@ -131,8 +131,8 @@ let }; overlays = mkOption { type = path; - default = "${userSelf}/overlays"; - defaultText = "\${userSelf}/overlays"; + default = "${userFlakeSelf}/overlays"; + defaultText = "\${userFlakeSelf}/overlays"; apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in From 9dca402914d6cd20791836d0da559adb03466aa5 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 20:56:24 -0500 Subject: [PATCH 030/137] ref: make onion with flake-utils --- lib/devos/mkPkgs.nix | 2 -- lib/flake.nix | 11 ++++++++--- lib/mkFlake/default.nix | 4 ++-- lib/mkFlake/evalArgs.nix | 4 ++-- lib/pkgs-lib/default.nix | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index ed669e4..7fb2570 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -12,8 +12,6 @@ lib = prev.lib.extend (lfinal: lprev: { inherit lib; inherit (lib) nixosSystem; - - utils = inputs.utils.lib; }); }) (overridesOverlay overridePkgs) diff --git a/lib/flake.nix b/lib/flake.nix index 47b9ffc..506fdb2 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -30,6 +30,11 @@ lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; in + + utils.lib + + // + { inherit callLibs; @@ -47,19 +52,19 @@ pathsToImportedAttrs concatAttrs filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; - }); + } + ); in { # ... but don't force that choice onto the user - lib = { + lib = utils.lib // { mkFlake = combinedLib.mkFlake; pkgs-lib = combinedLib.pkgs-lib; }; - } // diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index fbb2554..19dd1cf 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ lib, utils, deploy, ... }: +{ lib, deploy, ... }: let inherit (dev) os; in @@ -31,7 +31,7 @@ let deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; }; - systemOutputs = utils.lib.eachDefaultSystem (system: + systemOutputs = lib.eachDefaultSystem (system: let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 3f85080..b7902b8 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ userFlakeSelf, lib, nixpkgs, utils, ... }: +{ userFlakeSelf, lib, nixpkgs, ... }: { args }: let @@ -190,7 +190,7 @@ let }; supportedSystems = mkOption { type = listOf str; - default = utils.lib.defaultSystems; + default = lib.defaultSystems; description = '' The systems supported by this flake ''; diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index ae448a4..d2dde9b 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,5 +1,5 @@ -args@{ lib, utils, nixpkgs, ... }: -lib.genAttrs utils.lib.defaultSystems (system: +args@{ lib, nixpkgs, ... }: +lib.genAttrs lib.defaultSystems (system: lib.makeExtensible (final: let pkgs = import nixpkgs { inherit system; }; From 048171ecafb0c572a83039b4433a2613c5d8a3e1 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 9 Apr 2021 19:42:33 -0600 Subject: [PATCH 031/137] lib: improve `profileMap` for added convenience Simplify the definition of suites a bit by removing the need for list concatenation. --- lib/devos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index e580ef0..bac5b13 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -7,7 +7,7 @@ config = { allowUnfree = true; }; }; - profileMap = map (profile: profile.default); + profileMap = list: map (profile: profile.default) (lib.flatten list); mkNodes = dev.callLibs ./mkNodes.nix; From 2d91946745eed8994e6bd4cb7c648ed431b818a0 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 20:26:27 -0600 Subject: [PATCH 032/137] doc: move all docs under `doc` --- .gitignore | 2 +- README.md | 8 ++--- SUMMARY.md | 32 ----------------- doc/{README.md => CONTRIBUTING.md} | 0 doc/SUMMARY.md | 34 ++++++++++++++++++ book.toml => doc/book.toml | 0 extern/README.md => doc/concepts/extern.md | 0 hosts/README.md => doc/concepts/hosts.md | 6 ++-- doc/concepts/index.md | 4 +++ .../README.md => doc/concepts/overrides.md | 0 .../README.md => doc/concepts/profiles.md | 10 +++--- suites/README.md => doc/concepts/suites.md | 0 users/README.md => doc/concepts/users.md | 10 +++--- doc/flk/home.md | 2 +- doc/flk/update.md | 4 +-- .../README.md => doc/integrations/cachix.md | 0 doc/integrations/deploy.md | 2 +- doc/layout.md | 4 --- lib/README.md => doc/lib.md | 0 doc/outputs/index.md | 3 ++ modules/README.md => doc/outputs/modules.md | 4 +-- overlays/README.md => doc/outputs/overlays.md | 2 +- pkgs/README.md => doc/outputs/pkgs.md | 9 +++-- secrets/README.md => doc/secrets.md | 0 doc/start/bootstrapping.md | 20 +++++------ doc/start/from-nixos.md | 4 +-- doc/start/index.md | 2 +- doc/tests.md | 36 +++++++++++++++++++ {theme => doc/theme}/highlight.js | 0 29 files changed, 120 insertions(+), 78 deletions(-) delete mode 100644 SUMMARY.md rename doc/{README.md => CONTRIBUTING.md} (100%) create mode 100644 doc/SUMMARY.md rename book.toml => doc/book.toml (100%) rename extern/README.md => doc/concepts/extern.md (100%) rename hosts/README.md => doc/concepts/hosts.md (95%) create mode 100644 doc/concepts/index.md rename overrides/README.md => doc/concepts/overrides.md (100%) rename profiles/README.md => doc/concepts/profiles.md (87%) rename suites/README.md => doc/concepts/suites.md (100%) rename users/README.md => doc/concepts/users.md (75%) rename cachix/README.md => doc/integrations/cachix.md (100%) delete mode 100644 doc/layout.md rename lib/README.md => doc/lib.md (100%) create mode 100644 doc/outputs/index.md rename modules/README.md => doc/outputs/modules.md (95%) rename overlays/README.md => doc/outputs/overlays.md (96%) rename pkgs/README.md => doc/outputs/pkgs.md (84%) rename secrets/README.md => doc/secrets.md (100%) create mode 100644 doc/tests.md rename {theme => doc/theme}/highlight.js (100%) diff --git a/.gitignore b/.gitignore index 509d869..72a0166 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ result up hosts/up-* .direnv -book +doc/index.html diff --git a/README.md b/README.md index 38baf39..b64c51c 100644 --- a/README.md +++ b/README.md @@ -55,10 +55,10 @@ There are two branches from which to choose: [core][core] and several ready-made profiles for discretionary use. Every package and NixOS profile declared in community is uploaded to -[cachix](./cachix), so everything provided is available without building -anything. This is especially useful for the packages that are -[overridden](./overrides) from master, as without the cache, rebuilds are -quite frequent. +[cachix](./integrations/cachix.md), so everything provided is available +without building anything. This is especially useful for the packages that are +[overridden](./concepts/overrides.md) from master, as without the cache, +rebuilds are quite frequent. ## Inspiration & Art - [hlissner/dotfiles][dotfiles] diff --git a/SUMMARY.md b/SUMMARY.md deleted file mode 100644 index 1f34ee6..0000000 --- a/SUMMARY.md +++ /dev/null @@ -1,32 +0,0 @@ -# Summary - -- [Introduction](./README.md) -- [Quick Start](./doc/start/index.md) - - [ISO](./doc/start/iso.md) - - [Bootstrapping](./doc/start/bootstrapping.md) - - [From NixOS](./doc/start/from-nixos.md) -- [Layout](./doc/layout.md) - - [Cachix](./cachix/README.md) - - [Extern](./extern/README.md) - - [Hosts](./hosts/README.md) - - [Lib](./lib/README.md) - - [Modules](./modules/README.md) - - [Overlays](./overlays/README.md) - - [Overrides](./overrides/README.md) - - [Packages](./pkgs/README.md) - - [Profiles](./profiles/README.md) - - [Secrets](./secrets/README.md) - - [Suites](./suites/README.md) - - [Tests](./tests/README.md) - - [Users](./users/README.md) -- [flk](./doc/flk/index.md) - - [up](./doc/flk/up.md) - - [update](./doc/flk/update.md) - - [get](./doc/flk/get.md) - - [iso](./doc/flk/iso.md) - - [install](./doc/flk/install.md) - - [home](./doc/flk/home.md) -- [Integrations](doc/integrations/index.md) - - [Deploy RS](./doc/integrations/deploy.md) - - [Hercules CI](./doc/integrations/hercules.md) -- [Contributing](./doc/README.md) diff --git a/doc/README.md b/doc/CONTRIBUTING.md similarity index 100% rename from doc/README.md rename to doc/CONTRIBUTING.md diff --git a/doc/SUMMARY.md b/doc/SUMMARY.md new file mode 100644 index 0000000..f35bf37 --- /dev/null +++ b/doc/SUMMARY.md @@ -0,0 +1,34 @@ +# Summary + +- [Introduction](../README.md) +- [Quick Start](./start/index.md) + - [ISO](./start/iso.md) + - [Bootstrapping](./start/bootstrapping.md) + - [From NixOS](./start/from-nixos.md) +- [Key Concepts](./concepts/index.md) + - [Extern](./concepts/extern.md) + - [Hosts](./concepts/hosts.md) + - [Overrides](./concepts/overrides.md) + - [Profiles](./concepts/profiles.md) + - [Suites](./concepts/suites.md) + - [Users](./concepts/users.md) +- [Outputs](./outputs/index.md) + - [Modules](./outputs/modules.md) + - [Overlays](./outputs/overlays.md) + - [Packages](./outputs/pkgs.md) +- [Concerns]() + - [Lib](./lib.md) + - [Secrets](./secrets.md) + - [Tests](./tests.md) +- [Helper Script – `flk`](./flk/index.md) + - [up](./flk/up.md) + - [update](./flk/update.md) + - [get](./flk/get.md) + - [iso](./flk/iso.md) + - [install](./flk/install.md) + - [home](./flk/home.md) +- [Integrations](./integrations/index.md) + - [Cachix](./integrations/cachix.md) + - [Deploy RS](./integrations/deploy.md) + - [Hercules CI](./integrations/hercules.md) +- [Contributing](./CONTRIBUTING.md) diff --git a/book.toml b/doc/book.toml similarity index 100% rename from book.toml rename to doc/book.toml diff --git a/extern/README.md b/doc/concepts/extern.md similarity index 100% rename from extern/README.md rename to doc/concepts/extern.md diff --git a/hosts/README.md b/doc/concepts/hosts.md similarity index 95% rename from hosts/README.md rename to doc/concepts/hosts.md index b573f50..0a74dd1 100644 --- a/hosts/README.md +++ b/doc/concepts/hosts.md @@ -17,16 +17,16 @@ matching the current systems hostname if one is not specified explicitly. It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines -is best saved for [profile modules](../profiles). +is best saved for [profile modules](./profiles.md). -This is a good place to import sets of profiles, called [suites](../suites), +This is a good place to import sets of profiles, called [suites](./suites.md), that you intend to use on your machine. Additionally, this is the perfect place to import anything you might need from the [nixos-hardware][nixos-hardware] repository. > ##### _Note:_ -> Set `nixpkgs.system` to the architecture of this host, default is "x86_64-linux". +> Set `nixpkgs.system` to the architecture of this host, default is "x86_64-linux". > Keep in mind that not all packages are available for all architectures. ## Example diff --git a/doc/concepts/index.md b/doc/concepts/index.md new file mode 100644 index 0000000..8aca6e5 --- /dev/null +++ b/doc/concepts/index.md @@ -0,0 +1,4 @@ +# Key Concepts + +There are few idioms unique to DevOS. This section is dedicated to helping you +understand them. diff --git a/overrides/README.md b/doc/concepts/overrides.md similarity index 100% rename from overrides/README.md rename to doc/concepts/overrides.md diff --git a/profiles/README.md b/doc/concepts/profiles.md similarity index 87% rename from profiles/README.md rename to doc/concepts/profiles.md index fe2a6f6..1c8f416 100644 --- a/profiles/README.md +++ b/doc/concepts/profiles.md @@ -12,17 +12,17 @@ is maintained to help get up to speed on their usage. For the sake of consistency, a profile should always be defined in a ___default.nix___ containing a [nixos module config][config]. A profile's directory is used for quick modularization of -[interelated bits](./#subprofiles). +[interelated bits](./profiles.md#subprofiles). > ##### _Notes:_ -> * For _declaring_ module options, there's the [modules](../modules) directory. +> * For _declaring_ module options, there's the [modules](../outputs/modules.md) directory. > * This directory takes inspiration from > [upstream](https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/profiles) > . > * Sticking to a simple [spec][spec] has refreshing advantages. -> [hercules-ci](../doc/integrations/hercules.md) expects all profiles to be +> [hercules-ci](../integrations/hercules.md) expects all profiles to be > defined in a ___default.nix___, allowing them to be built automatically when -> added. Congruently, [suites](../suites) expect ___default.nix___ to avoid +> added. Congruently, [suites](suites.md) expect ___default.nix___ to avoid > having to manage their paths manually. ## Subprofiles @@ -56,7 +56,7 @@ profiles/develop/zsh/default.nix: Profiles are the most important concept in DevOS. They allow us to keep our Nix expressions self contained and modular. This way we can maximize reuse across hosts while minimizing boilerplate. Remember, anything machine -specific belongs in your [host](../hosts) files instead. +specific belongs in your [host](hosts.md) files instead. [definition]: https://nixos.org/manual/nixos/stable/index.html#sec-option-definitions [declaration]: https://nixos.org/manual/nixos/stable/index.html#sec-option-declarations diff --git a/suites/README.md b/doc/concepts/suites.md similarity index 100% rename from suites/README.md rename to doc/concepts/suites.md diff --git a/users/README.md b/doc/concepts/users.md similarity index 75% rename from users/README.md rename to doc/concepts/users.md index 5fdb029..235884a 100644 --- a/users/README.md +++ b/doc/concepts/users.md @@ -1,6 +1,6 @@ # Users -Users are a special case of [profiles](../profiles) that define system +Users are a special case of [profiles](profiles.md) that define system users and [home-manager][home-manager] configurations. For your convenience, home manager is wired in by default so all you have to worry about is declaring your users. For a fully fleshed out example, check out the developers personal @@ -24,14 +24,14 @@ your users. For a fully fleshed out example, check out the developers personal ## Home Manager Home Manager support follows the same principles as regular nixos configurations. -All modules defined in [user modules](./modules/module-list.nix) will be imported to -Home Manager. All profiles are availabe in [suites](../suites/default.nix) as userProfiles. +All modules defined in [user modules][modules-list] will be imported to +Home Manager. All profiles are availabe in [suites][suites] as userProfiles. The `userSuites` output will be available in your Home Manager Configuration as the special argument, `suites`. ## External Usage You can easily use the defined home-manager configurations outside of NixOS -using the `homeConfigurations` flake output. The [flk](../doc/flk) helper +using the `homeConfigurations` flake output. The [flk](../flk/index.md) helper script makes this even easier. This is great for keeping your environment consistent across Unix systems, @@ -56,3 +56,5 @@ nix build "github:divnix/devos#homeConfigurations.nixos@NixOS.home.activationPac ``` [home-manager]: https://nix-community.github.io/home-manager +[suites]: https://github.com/divnix/devos/tree/core/suites/default.nix +[modules-list]: https://github.com/divnix/devos/tree/core/modules/module-list.nix diff --git a/doc/flk/home.md b/doc/flk/home.md index 01cb52e..f0bae76 100644 --- a/doc/flk/home.md +++ b/doc/flk/home.md @@ -4,5 +4,5 @@ NixOS, providing an awesome mechanism for keeping your environments synchronized, even when using other systems. ## Usage -The [users](../../users/index.md#external-usage) page contains a good usage +The [users](../concepts/users.md#external-usage) page contains a good usage example. diff --git a/doc/flk/update.md b/doc/flk/update.md index 8163dda..869db72 100644 --- a/doc/flk/update.md +++ b/doc/flk/update.md @@ -11,8 +11,8 @@ contains a flake.nix, with an optional arguement to update only a specific input in the subflake. For example, you can update any -[package sources](../../pkgs#automatic-source-updates) you may have declared -in _pkgs/flake.nix_: +[package sources](../outputs/pkgs.md#automatic-source-updates) you may have +declared in _pkgs/flake.nix_: ```sh flk update pkgs ``` diff --git a/cachix/README.md b/doc/integrations/cachix.md similarity index 100% rename from cachix/README.md rename to doc/integrations/cachix.md diff --git a/doc/integrations/deploy.md b/doc/integrations/deploy.md index 710bfbc..2903210 100644 --- a/doc/integrations/deploy.md +++ b/doc/integrations/deploy.md @@ -4,7 +4,7 @@ chosen for devos after the author experienced some frustrations with the stateful nature of nixops' db. It was also designed from scratch to support flake based deployments, and so is an excellent tool for the job. -By default, all the [hosts](../../hosts) are also available as deploy-rs nodes, +By default, all the [hosts](../concepts/hosts.md) are also available as deploy-rs nodes, configured with the hostname set to `networking.hostName`; overridable via the command line. diff --git a/doc/layout.md b/doc/layout.md deleted file mode 100644 index 1883118..0000000 --- a/doc/layout.md +++ /dev/null @@ -1,4 +0,0 @@ -# Layout -Each of the following sections is a directory in the root of the project -serving a singular purpose. Select a chapter to read more about its purpose -and usage. diff --git a/lib/README.md b/doc/lib.md similarity index 100% rename from lib/README.md rename to doc/lib.md diff --git a/doc/outputs/index.md b/doc/outputs/index.md new file mode 100644 index 0000000..3620718 --- /dev/null +++ b/doc/outputs/index.md @@ -0,0 +1,3 @@ +# Layout +Each of the following sections is a directory whose contents are output to the +outside world via the flake's outputs. Check each chapter for details. diff --git a/modules/README.md b/doc/outputs/modules.md similarity index 95% rename from modules/README.md rename to doc/outputs/modules.md index 1f3d9d9..f698e9f 100644 --- a/modules/README.md +++ b/doc/outputs/modules.md @@ -4,13 +4,13 @@ The modules directory is a replica of nixpkg's NixOS [modules][nixpkgs-modules] nixpkgs proper once your module is sufficiently stable. All modules linked in _module-list.nix_ are automatically exported via -`nixosModules.`, and imported into all [hosts](../hosts). +`nixosModules.`, and imported into all [hosts](../concepts/hosts.md). > ##### _Note:_ > This is reserved for declaring brand new module options. If you just want to > declare a coherent configuration of already existing and related NixOS options -> , use [profiles](../profiles) instead. +> , use [profiles](../concepts/profiles.md) instead. ## Semantics In case you've never written a module for nixpkgs before, here is a brief diff --git a/overlays/README.md b/doc/outputs/overlays.md similarity index 96% rename from overlays/README.md rename to doc/outputs/overlays.md index 7d8ecdb..d71b459 100644 --- a/overlays/README.md +++ b/doc/outputs/overlays.md @@ -3,7 +3,7 @@ Writing overlays is a common occurence when using a NixOS system. Therefore, we want to keep the process as simple and straightforward as possible. Any _.nix_ files declared in this directory will be assumed to be a valid -overlay, and will be automatically imported into all [hosts](../hosts), and +overlay, and will be automatically imported into all [hosts](../concepts/hosts.md), and exported via `overlays.` _as well as_ `packages..` (for valid systems), so all you have to do is write it. diff --git a/pkgs/README.md b/doc/outputs/pkgs.md similarity index 84% rename from pkgs/README.md rename to doc/outputs/pkgs.md index 1d0ac69..99684b5 100644 --- a/pkgs/README.md +++ b/doc/outputs/pkgs.md @@ -1,5 +1,5 @@ # Packages -Similar to [modules](../modules), the pkgs directory mirrors the upstream +Similar to [modules](./modules.md), the pkgs directory mirrors the upstream [nixpkgs/pkgs][pkgs], and for the same reason; if you ever want to upstream your package, it's as simple as dropping it into the nixpkgs/pkgs directory. @@ -12,18 +12,17 @@ And all the packages are exported via `packages..`, for all the supported systems listed in the package's `meta.platforms` attribute. And, as usual, every package in the overlay is also available to any NixOS -[host](../hosts). +[host](../concepts/hosts.md). ## Automatic Source Updates There is the added, but optional, convenience of declaring your sources in _pkgs/flake.nix_ as an input. You can then access them from the `srcs` package. This allows updates to be managed automatically by simply -[updating](../doc/flk/update.md#updating-package-sources) the lock file. No +[updating](../flk/update.md#updating-package-sources) the lock file. No more manually entering sha256 hashes! As an added bonus, version strings are also generated automatically from either -the flake ref, or the date and git revision of the source. For examples, -definitely checkout the [community branch](../#community-profiles). +the flake ref, or the date and git revision of the source. ## Example pkgs/development/libraries/libinih/default.nix: diff --git a/secrets/README.md b/doc/secrets.md similarity index 100% rename from secrets/README.md rename to doc/secrets.md diff --git a/doc/start/bootstrapping.md b/doc/start/bootstrapping.md index 8e44ce9..873af32 100644 --- a/doc/start/bootstrapping.md +++ b/doc/start/bootstrapping.md @@ -1,9 +1,9 @@ # Bootstrapping -This will help you boostrap a bare host with the help of the -[bespoke iso](./iso) live installer. +This will help you boostrap a bare host with the help of the +[bespoke iso](./iso.md) live installer. -_Note: nothing prevents you from remotely executing the boostrapping +_Note: nothing prevents you from remotely executing the boostrapping process. See below._ Once your target host has booted into the live iso, you need to partion @@ -14,7 +14,7 @@ and format your disk according to the [official manual][manual]. Then properly mount the formatted partitions at `/mnt`, so that you can install your system to those new partitions. -Mount `nixos` partition to `/mnt` and — for UEFI — `boot` +Mount `nixos` partition to `/mnt` and — for UEFI — `boot` partition to `/mnt/boot`: ```console @@ -25,7 +25,7 @@ $ swapon /dev/$your_swap_partition ## Install -Install using the `flk` wrapper baked into the iso off of a copy of devos +Install using the `flk` wrapper baked into the iso off of a copy of devos from the time the iso was built: ```console @@ -41,7 +41,7 @@ $ flk install NixOS --impure # use same host as above ### Remote access to the live installer The iso live installer comes preconfigured with a network configuration -which announces it's hostname via [MulticastDNS][mDNS] as `hostname.local`, +which announces it's hostname via [MulticastDNS][mDNS] as `hostname.local`, that is `NixOS.local` in the [iso example](./iso). In the rare case that [MulticastDNS][mDNS] is not availabe or turned off @@ -50,7 +50,7 @@ in your network, there is a static link-local IPv6 address configured to `n=14 i=9 x=24; 47 = n+i+x`). Provided that you have added your public key to the authorized keys of the -`root` user _(hint: [`deploy-rs`](../integrations/deploy) needs passwordless +`root` user _(hint: [`deploy-rs`](../integrations/deploy.md) needs passwordless sudo access)_: ```nix @@ -62,7 +62,7 @@ sudo access)_: } ``` -You can then ssh into the live installer through one of the +You can then ssh into the live installer through one of the following options: ```console @@ -73,7 +73,7 @@ ssh root@fe80::47%eno1 # where eno1 is your network interface on which you are _Note: the [static link-local IPv6 address][staticLLA] and [MulticastDNS][mDNS] is only configured on the live installer. If you wish to enable [MulticastDNS][mDNS] -for your environment, you ought to configure that in a regular [profile](../../profiles)._ +for your environment, you ought to configure that in a regular [profile](../concepts/profiles.md)._ ### EUI-64 LLA & Host Identity @@ -88,7 +88,7 @@ specific address over [NDP][NDP] for example with: ip -6 neigh show # also shows fe80::47 ``` -***This LLA is stable for the host, unless you need to swap that particular network card.*** +***This LLA is stable for the host, unless you need to swap that particular network card.*** Under this reservation, though, you may use this EUI-64 to wire up a specific (cryptographic) host identity. diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index 7c37cdc..bbb0e55 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -15,8 +15,8 @@ your region. Keep in mind that `networking.hostName` with be automatically set to the filename of your hosts file, so `hosts/my-host.nix` will have the hostname `my-host`. -Now might be a good time to read the docs on [suites](../../suites) and -[profiles](../../profiles) and add or create any that you need. +Now might be a good time to read the docs on [suites](../concepts/suites.md) and +[profiles](../concepts/profiles.md) and add or create any that you need. > ##### _Note:_ > While the `up` sub-command is provided as a convenience to quickly set up and diff --git a/doc/start/index.md b/doc/start/index.md index 48d2b16..1cc252b 100644 --- a/doc/start/index.md +++ b/doc/start/index.md @@ -22,7 +22,7 @@ This will place you in a new folder named `flk` with git initialized, and a nix-shell that provides all the dependencies, including the unstable nix version required. -In addition, the [binary cache](../../cachix) is added for faster deployment. +In addition, the [binary cache](../integrations/cachix.md) is added for faster deployment. > ##### _Notes:_ > - You can change `core` to [`community`](../../index.md#community-profiles) diff --git a/doc/tests.md b/doc/tests.md new file mode 100644 index 0000000..033d75a --- /dev/null +++ b/doc/tests.md @@ -0,0 +1,36 @@ +# Testing + +Testing is always an important aspect of any software development project, and +NixOS offers some incredibly powerful tools to write tests for your +configuration, and, optionally, run them in +[CI](./integrations/hercules.md). + +## Lib Tests +You can easily write tests for your own library functions in the +___tests/lib.nix___ file and they will be run on every `nix flake check` or +during a CI run. + +## Unit Tests +Unit tests are can be created from regular derivations, and they can do +almost anything you can imagine. By convention, it is best to test your +packages during their [check phase][check]. All packages and their tests will +be built during CI. + +## Integration Tests +You can write integration tests for one or more NixOS VMs that can, +optionally, be networked together, and yes, it's as awesome as it sounds! + +Be sure to use the `mkTest` function, in the [___tests/default.nix___][default] +which wraps the official [testing-python][testing-python] function to ensure +that the system is setup exactly as it is for a bare DevOS system. There are +already great resources for learning how to use these tests effectively, +including the official [docs][test-doc], a fantastic [blog post][test-blog], +and the examples in [nixpkgs][nixos-tests]. + +[test-doc]: https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests +[test-blog]: https://www.haskellforall.com/2020/11/how-to-use-nixos-for-lightweight.html +[default]: https://github.com/divnix/devos/tree/core/tests/default.nix +[run-test]: https://github.com/NixOS/nixpkgs/blob/6571462647d7316aff8b8597ecdf5922547bf365/lib/debug.nix#L154-L166 +[nixos-tests]: https://github.com/NixOS/nixpkgs/tree/master/nixos/tests +[testing-python]: https://github.com/NixOS/nixpkgs/tree/master/nixos/lib/testing-python.nix +[check]: https://nixos.org/manual/nixpkgs/stable/#ssec-check-phase diff --git a/theme/highlight.js b/doc/theme/highlight.js similarity index 100% rename from theme/highlight.js rename to doc/theme/highlight.js From fbce126f4d72c40c6a00948fe05d42ccba7233e2 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 20:43:37 -0600 Subject: [PATCH 033/137] cachix: move out of root and into profile --- doc/integrations/cachix.md | 13 +++++++++---- lib/devos/mkHosts.nix | 6 +++++- cachix.nix => profiles/cachix/default.nix | 5 ++--- {cachix => profiles/cachix}/nix-community.nix | 0 {cachix => profiles/cachix}/nrdxp.nix | 0 profiles/core/default.nix | 1 + 6 files changed, 17 insertions(+), 8 deletions(-) rename cachix.nix => profiles/cachix/default.nix (76%) rename {cachix => profiles/cachix}/nix-community.nix (100%) rename {cachix => profiles/cachix}/nrdxp.nix (100%) diff --git a/doc/integrations/cachix.md b/doc/integrations/cachix.md index de732dc..3e4f3b5 100644 --- a/doc/integrations/cachix.md +++ b/doc/integrations/cachix.md @@ -1,8 +1,13 @@ # Cachix -The cachix directory simple captures the output of `sudo cachix use` for the -developers personal cache, as well as the nix-community cache. You can easily -add your own cache, assuming the template lives in /etc/nixos, by simply -running `sudo cachix use yourcache`. +The system will automatically pull a cachix.nix at the root if one exists. +This is usually created automatically by a `sudo cachix use`. If your more +inclined to keep the root clean, you can drop any generated files in the +`cachix` directory into the `profiles/cachix` directory without further +modification. + +For example, to add your own cache, assuming the template lives in /etc/nixos, +by simply running `sudo cachix use yourcache`. Then, optionally, move +`cachix/yourcache.nix` to `profiles/cachix/yourcache.nix` These caches are only added to the system after a `nixos-rebuild switch`, so it is recommended to call `cachix use nrdxp` before the initial deployment, as it diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 8a8abdb..b48b440 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -63,7 +63,11 @@ let # Everything in `./modules/list.nix`. flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - cachix = ../../cachix.nix; + cachix = let rootCachix = ../../cachix.nix; in + if builtins.pathExists rootCachix + then rootCachix + else { } + ; }; specialArgs = extern.specialArgs // { suites = suites.system; }; diff --git a/cachix.nix b/profiles/cachix/default.nix similarity index 76% rename from cachix.nix rename to profiles/cachix/default.nix index 32a3e8d..d88a3f7 100644 --- a/cachix.nix +++ b/profiles/cachix/default.nix @@ -1,9 +1,8 @@ -# WARN: this file will get overwritten by $ cachix use { pkgs, lib, ... }: let - folder = ./cachix; + folder = ./.; toImport = name: value: folder + ("/" + name); - filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key; + filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key && key != "default.nix"; imports = lib.mapAttrsToList toImport (lib.filterAttrs filterCaches (builtins.readDir folder)); in { diff --git a/cachix/nix-community.nix b/profiles/cachix/nix-community.nix similarity index 100% rename from cachix/nix-community.nix rename to profiles/cachix/nix-community.nix diff --git a/cachix/nrdxp.nix b/profiles/cachix/nrdxp.nix similarity index 100% rename from cachix/nrdxp.nix rename to profiles/cachix/nrdxp.nix diff --git a/profiles/core/default.nix b/profiles/core/default.nix index f5a654c..1bca2b9 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -2,6 +2,7 @@ let inherit (lib) fileContents; in { + imports = [ ../cachix ]; nix.systemFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; From 127cb25bd1787da6c638860f8deb8a77b694502d Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 20:51:47 -0600 Subject: [PATCH 034/137] lib: move compat to lib --- default.nix | 2 +- {compat => lib/compat}/default.nix | 4 ++-- {compat => lib/compat}/nixos/default.nix | 0 lib/devos/mkHosts.nix | 2 +- nix/ci.nix | 2 +- profiles/core/default.nix | 2 +- shell.nix | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename {compat => lib/compat}/default.nix (74%) rename {compat => lib/compat}/nixos/default.nix (100%) diff --git a/default.nix b/default.nix index b348226..e3c4ca1 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ let inherit (default.inputs.nixos) lib; - default = (import ./compat).defaultNix; + default = (import ./lib/compat).defaultNix; in builtins.mapAttrs (_: v: lib.recurseIntoAttrs v) default.packages // { shell = import ./shell.nix; diff --git a/compat/default.nix b/lib/compat/default.nix similarity index 74% rename from compat/default.nix rename to lib/compat/default.nix index 2ee185c..9ed54a7 100644 --- a/compat/default.nix +++ b/lib/compat/default.nix @@ -1,7 +1,7 @@ let inherit (lock.nodes.flake-compat.locked) rev narHash; - lock = builtins.fromJSON (builtins.readFile ../flake.lock); + lock = builtins.fromJSON (builtins.readFile ../../flake.lock); flake = (import ( fetchTarball { @@ -10,7 +10,7 @@ let } ) { - src = ../.; + src = ../../.; }); in flake diff --git a/compat/nixos/default.nix b/lib/compat/nixos/default.nix similarity index 100% rename from compat/nixos/default.nix rename to lib/compat/nixos/default.nix diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index b48b440..abb7c4e 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -37,7 +37,7 @@ let nix.nixPath = [ "nixpkgs=${nixos}" - "nixos-config=${self}/compat/nixos" + "nixos-config=${self}/lib/compat/nixos" "home-manager=${inputs.home}" ]; diff --git a/nix/ci.nix b/nix/ci.nix index 5152cd2..f36d2b2 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -1,7 +1,7 @@ let inherit (default.inputs.nixos) lib; - default = (import "${../.}/compat").defaultNix; + default = (import "${../lib}/compat").defaultNix; ciSystems = [ "aarch64-linux" diff --git a/profiles/core/default.nix b/profiles/core/default.nix index 1bca2b9..15824b0 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -77,7 +77,7 @@ in ''; # fix nixos-option - nixos-option = "nixos-option -I nixpkgs=${toString ../../compat}"; + nixos-option = "nixos-option -I nixpkgs=${toString ../../lib/compat}"; # sudo s = ifSudo "sudo -E "; diff --git a/shell.nix b/shell.nix index c05730d..575a5d8 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1 @@ -(import ./compat).shellNix +(import ./lib/compat).shellNix From f2543047969d2bbac5669325c459638661518525 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:00:45 -0600 Subject: [PATCH 035/137] mv `nix/ci.nix` directly to `default.nix` --- default.nix | 31 +++++++++++++++++++++++++++---- doc/integrations/hercules.md | 2 +- lib/compat/default.nix | 2 +- nix/ci.nix | 31 ------------------------------- 4 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 nix/ci.nix diff --git a/default.nix b/default.nix index e3c4ca1..5d437c7 100644 --- a/default.nix +++ b/default.nix @@ -1,8 +1,31 @@ let inherit (default.inputs.nixos) lib; - default = (import ./lib/compat).defaultNix; + default = (import "${./lib}/compat").defaultNix; + + ciSystems = [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + ]; + + filterSystems = lib.filterAttrs + (system: _: lib.elem system ciSystems); + + recurseIntoAttrsRecursive = lib.mapAttrs (_: v: + if lib.isAttrs v + then recurseIntoAttrsRecursive (lib.recurseIntoAttrs v) + else v + ); + + systemOutputs = lib.filterAttrs + (name: set: lib.isAttrs set + && lib.any + (system: set ? ${system} && name != "legacyPackages") + ciSystems + ) + default.outputs; + + ciDrvs = lib.mapAttrs (_: system: filterSystems system) systemOutputs; in -builtins.mapAttrs (_: v: lib.recurseIntoAttrs v) default.packages // { - shell = import ./shell.nix; -} +(recurseIntoAttrsRecursive ciDrvs) // { shell = import ./shell.nix; } diff --git a/doc/integrations/hercules.md b/doc/integrations/hercules.md index f50443a..aa0185e 100644 --- a/doc/integrations/hercules.md +++ b/doc/integrations/hercules.md @@ -15,7 +15,7 @@ binary cache (and of course you do), be sure _not_ to skip the [binary-caches.json][cache]. ## Ready to Use -The repo is already set up with the proper _nix/ci.nix_ file, building all +The repo is already set up with the proper _default.nix_ file, building all declared packages, checks, profiles and shells. So you can see if something breaks, and never build the same package twice! diff --git a/lib/compat/default.nix b/lib/compat/default.nix index 9ed54a7..0a63b0b 100644 --- a/lib/compat/default.nix +++ b/lib/compat/default.nix @@ -1,7 +1,7 @@ let inherit (lock.nodes.flake-compat.locked) rev narHash; - lock = builtins.fromJSON (builtins.readFile ../../flake.lock); + lock = builtins.fromJSON (builtins.readFile "${../..}/flake.lock"); flake = (import ( fetchTarball { diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index f36d2b2..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,31 +0,0 @@ -let - inherit (default.inputs.nixos) lib; - - default = (import "${../lib}/compat").defaultNix; - - ciSystems = [ - "aarch64-linux" - "i686-linux" - "x86_64-linux" - ]; - - filterSystems = lib.filterAttrs - (system: _: lib.elem system ciSystems); - - recurseIntoAttrsRecursive = lib.mapAttrs (_: v: - if lib.isAttrs v - then recurseIntoAttrsRecursive (lib.recurseIntoAttrs v) - else v - ); - - systemOutputs = lib.filterAttrs - (name: set: lib.isAttrs set - && lib.any - (system: set ? ${system} && name != "legacyPackages") - ciSystems - ) - default.outputs; - - ciDrvs = lib.mapAttrs (_: system: filterSystems system) systemOutputs; -in -recurseIntoAttrsRecursive ciDrvs From e13a65b33c761a1686de71625b5f1dece52190a7 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:06:47 -0600 Subject: [PATCH 036/137] overrides: move to extern --- doc/concepts/overrides.md | 5 +++-- overrides/default.nix => extern/overrides.nix | 0 flake.nix | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) rename overrides/default.nix => extern/overrides.nix (100%) diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index ad0670b..28194cd 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -1,6 +1,6 @@ # Overrides -By default, the NixOS systems are based on the latest release. While it is -trivial to change this to nixos-unstable or any other branch of nixpkgs by +By default, the NixOS systems are based on unstable. While it is trivial to +change this to a stable release, or any other branch of nixpkgs by changing the flake url, sometimes all we want is a single package from another branch. @@ -8,6 +8,7 @@ This is what the overrides are for. By default, they are pulled directly from nixpkgs/master, but you can change the `override` flake input url to nixos-unstable, or even a specific sha revision. +They are defined in the `extern/overrides.nix` file. ## Example diff --git a/overrides/default.nix b/extern/overrides.nix similarity index 100% rename from overrides/default.nix rename to extern/overrides.nix diff --git a/flake.nix b/flake.nix index fddbc85..24c9a4b 100644 --- a/flake.nix +++ b/flake.nix @@ -39,7 +39,7 @@ packages = import ./pkgs; suites = import ./suites; extern = import ./extern; - overrides = import ./overrides; + overrides = import ./extern/overrides.nix; overlays = ./overlays; profiles = ./profiles; userProfiles = ./users/profiles; From e1e0f99af949b8833ea04f9f04b965e33d2a7126 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:13:12 -0600 Subject: [PATCH 037/137] suites: move to `profles/suites.nix` --- doc/concepts/suites.md | 2 ++ flake.nix | 2 +- suites/default.nix => profiles/suites.nix | 0 3 files changed, 3 insertions(+), 1 deletion(-) rename suites/default.nix => profiles/suites.nix (100%) diff --git a/doc/concepts/suites.md b/doc/concepts/suites.md index 68bb868..e6a8bff 100644 --- a/doc/concepts/suites.md +++ b/doc/concepts/suites.md @@ -6,6 +6,8 @@ profiles. For good examples, check out the suites defined in the community In the future, we will use suites as a mechanism for deploying various machine types which don't depend on hardware, such as vm's and containers. +They are defined in `profiles/suites.nix`. + ## Definition ```nix rec { diff --git a/flake.nix b/flake.nix index 24c9a4b..a9551d8 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ inherit self; hosts = ./hosts; packages = import ./pkgs; - suites = import ./suites; + suites = import ./profiles/suites.nix; extern = import ./extern; overrides = import ./extern/overrides.nix; overlays = ./overlays; diff --git a/suites/default.nix b/profiles/suites.nix similarity index 100% rename from suites/default.nix rename to profiles/suites.nix From be924bcb27432d1e3293a12be5675f849bfe3afc Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 17 Apr 2021 21:29:45 -0500 Subject: [PATCH 038/137] ref: reduce exposure to callLibs for clarity's sake, expose which function uses final and prev, so that people can have a clearer understanding how they relate to each other in terms of dependencies. also a simple `{ lib = final; }` probably does not warrant a complete callLibs obscurization. --- lib/attrs.nix | 2 +- lib/devos/default.nix | 2 +- lib/flake.nix | 18 ++++++++++++------ lib/lists.nix | 2 +- lib/pkgs-lib/default.nix | 2 +- lib/strings.nix | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/attrs.nix b/lib/attrs.nix index 50c72d2..1ecc254 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: rec { # mapFilterAttrs :: # (name -> value -> bool ) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index fb9e990..a8ecd94 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: diff --git a/lib/flake.nix b/lib/flake.nix index 506fdb2..1810b1b 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -21,14 +21,17 @@ let callLibs = file: import file ({ lib = final; - userFlakeInputs = {}; # TODO: Erm, this must become a proper argument to mkFlake + userFlakeNixos = {}; + userFlakeSelf = {}; + userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake } // inputs); in with final; let - attrs = callLibs ./attrs.nix; - lists = callLibs ./lists.nix; - strings = callLibs ./strings.nix; + + attrs = import ./attrs.nix { lib = prev; }; + lists = import ./lists.nix { lib = prev; }; + strings = import ./strings.nix { lib = prev; }; in utils.lib @@ -38,7 +41,7 @@ { inherit callLibs; - os = callLibs ./devos; + os = import ./devos { lib = final; }; mkFlake = { __functor = callLibs ./mkFlake; @@ -46,7 +49,10 @@ evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; }; - pkgs-lib = callLibs ./pkgs-lib; + pkgs-lib = import ./pkgs-lib { + lib = final; + inherit nixpkgs deploy devshell; + }; inherit (attrs) mapFilterAttrs genAttrs' safeReadDir pathsToImportedAttrs concatAttrs filterPackages; diff --git a/lib/lists.nix b/lib/lists.nix index 74cf9bd..1862041 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { pathsIn = dir: let diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index d2dde9b..a298d41 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,4 +1,4 @@ -args@{ lib, nixpkgs, ... }: +args@{ lib, nixpkgs, deploy, devshell }: lib.genAttrs lib.defaultSystems (system: lib.makeExtensible (final: let diff --git a/lib/strings.nix b/lib/strings.nix index 56a0861..d411bab 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { # returns matching part of _regex_ _string_; null indicates failure. rgxToString = regex: string: From 40acfd13e319bc51a5109dbadc73d2478897da5f Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 21:45:08 -0500 Subject: [PATCH 039/137] use: makeExtensible --- lib/devos/default.nix | 20 ++++++------ lib/devos/devosSystem.nix | 6 ++-- lib/devos/mkHomeConfigurations.nix | 4 ++- lib/devos/mkHosts.nix | 8 ++--- lib/devos/mkNodes.nix | 2 +- lib/devos/mkPackages.nix | 4 ++- lib/devos/mkPkgs.nix | 6 ++-- lib/devos/mkProfileAttrs.nix | 2 +- lib/devos/mkSuites.nix | 2 +- lib/devos/recImport.nix | 2 +- lib/flake.nix | 52 +++++++++++++++--------------- 11 files changed, 57 insertions(+), 51 deletions(-) diff --git a/lib/devos/default.nix b/lib/devos/default.nix index a8ecd94..cd97181 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, utils }: { # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs pkgImport = nixpkgs: overlays: system: @@ -9,22 +9,22 @@ profileMap = map (profile: profile.default); - mkNodes = lib.callLibs ./mkNodes.nix; + mkNodes = import ./mkNodes.nix { inherit lib; }; - mkHosts = lib.callLibs ./mkHosts.nix; + mkHosts = import ./mkHosts.nix { inherit lib; }; - mkSuites = lib.callLibs ./mkSuites.nix; + mkSuites = import ./mkSuites.nix { inherit lib; }; - mkProfileAttrs = lib.callLibs ./mkProfileAttrs.nix; + mkProfileAttrs = import ./mkProfileAttrs.nix { inherit lib; }; - mkPkgs = lib.callLibs ./mkPkgs.nix; + mkPkgs = import ./mkPkgs.nix { inherit lib utils; }; - recImport = lib.callLibs ./recImport.nix; + recImport = import ./recImport.nix { inherit lib; }; - devosSystem = lib.callLibs ./devosSystem.nix; + devosSystem = import ./devosSystem.nix { inherit lib; }; - mkHomeConfigurations = lib.callLibs ./mkHomeConfigurations.nix; + mkHomeConfigurations = import ./mkHomeConfigurations.nix { inherit lib; }; - mkPackages = lib.callLibs ./mkPackages.nix; + mkPackages = import ./mkPackages.nix { inherit lib; }; } diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 121638c..f9a84d0 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,4 +1,6 @@ -{ lib, nixpkgs, userFlakeSelf, userFlakeInputs, ... }: +{ lib }: + +{ userFlakeNixos, userFlakeSelf, userFlakeInputs }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -13,7 +15,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${nixpkgs}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${userFlakeNixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 34c5e93..6ccfa50 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,4 +1,6 @@ -{ lib, userFlakeSelf, ... }: +{ lib }: + +{ userFlakeSelf }: with lib; let diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index b11bda9..3bb010b 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,6 +1,6 @@ -{ lib, nixpkgs, userFlakeInputs, userFlakeSelf, ... }: +{ lib }: -{ dir, extern, suites, overrides, multiPkgs, ... }: +{ dir, extern, suites, overrides, multiPkgs, userFlakeNixOS, userFlakeInputs, userFlakeSelf }: let defaultSystem = "x86_64-linux"; @@ -36,7 +36,7 @@ let hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixpkgs}" + "nixpkgs=${userFlakeNixOS}" "nixos-config=${userFlakeSelf}/compat/nixos" "home-manager=${userFlakeInputs.home}" ]; @@ -45,7 +45,7 @@ let nix.registry = { devos.flake = userFlakeSelf; - nixos.flake = nixpkgs; + nixos.flake = userFlakeNixOS; override.flake = userFlakeInputs.override; }; diff --git a/lib/devos/mkNodes.nix b/lib/devos/mkNodes.nix index 7892506..83906ce 100644 --- a/lib/devos/mkNodes.nix +++ b/lib/devos/mkNodes.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: /** Synopsis: mkNodes _nixosConfigurations_ diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index 17cba0e..eeac929 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,4 +1,6 @@ -{ lib, userFlakeSelf, ... }: +{ lib }: + +{ userFlakeSelf }: { pkgs }: let diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 7fb2570..8fb2201 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,6 +1,6 @@ -{ lib, nixpkgs, userFlakeSelf, utils, userFlakeInputs, ... }: +{ lib, utils }: -{ extern, overrides }: +{ extern, overrides, userFlakeNixOS, userFlakeSelf, userFlakeInputs }: (utils.lib.eachDefaultSystem (system: let @@ -20,6 +20,6 @@ ++ extern.overlays ++ (lib.attrValues userFlakeSelf.overlays); in - { pkgs = lib.os.pkgImport nixpkgs overlays system; } + { pkgs = lib.os.pkgImport userFlakeNixOS overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index 7168b29..0a96cfb 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: let mkProfileAttrs = /** diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index 0a5950b..cb73679 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { users, profiles, userProfiles, suites } @ args: let diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix index e9e5da6..c96c935 100644 --- a/lib/devos/recImport.nix +++ b/lib/devos/recImport.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib }: { dir, _import ? base: import "${dir}/${base}.nix" }: lib.mapFilterAttrs diff --git a/lib/flake.nix b/lib/flake.nix index 1810b1b..17d4754 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -14,24 +14,19 @@ outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - inherit (nixpkgs) lib; - - # We work with a combined lib, internally ... - combinedLib = lib.extend (final: prev: - let callLibs = file: import file - ({ - lib = final; - userFlakeNixos = {}; - userFlakeSelf = {}; - userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake - } // inputs); - in - with final; + lib = nixpkgs.lib.makeExtensible (self: let + callLibs = file: import file + ({ + lib = self; + userFlakeNixos = {}; + userFlakeSelf = {}; + userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake + } // inputs); - attrs = import ./attrs.nix { lib = prev; }; - lists = import ./lists.nix { lib = prev; }; - strings = import ./strings.nix { lib = prev; }; + attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; + lists = import ./lists.nix { lib = nixpkgs.lib // self; }; + strings = import ./strings.nix { lib = nixpkgs.lib // self; }; in utils.lib @@ -39,9 +34,10 @@ // { - inherit callLibs; - - os = import ./devos { lib = final; }; + os = import ./devos { + lib = nixpkgs.lib // self; + inherit utils; + }; mkFlake = { __functor = callLibs ./mkFlake; @@ -50,12 +46,17 @@ }; pkgs-lib = import ./pkgs-lib { - lib = final; + lib = nixpkgs.lib // self; inherit nixpkgs deploy devshell; }; - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir - pathsToImportedAttrs concatAttrs filterPackages; + inherit (attrs) + mapFilterAttrs + genAttrs' + safeReadDir + pathsToImportedAttrs + concatAttrs + filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; } @@ -65,10 +66,9 @@ { - # ... but don't force that choice onto the user lib = utils.lib // { - mkFlake = combinedLib.mkFlake; - pkgs-lib = combinedLib.pkgs-lib; + inherit (lib) + mkFlake; }; } @@ -83,7 +83,7 @@ checks = { tests = import ./tests { inherit (nixpkgs') pkgs; - lib = combinedLib; + lib = nixpkgs.lib // lib; }; }; } From 6f0392b55e12b86695995e1744221bc27a382998 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:00:49 -0500 Subject: [PATCH 040/137] ref: cave out instances of userFLake dependencies and intject them as if functions where contructors --- lib/devos/mkHosts.nix | 6 +++++- lib/devos/mkPkgs.nix | 4 +++- lib/mkFlake/default.nix | 27 ++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 3bb010b..d86de4e 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,6 +1,8 @@ { lib }: -{ dir, extern, suites, overrides, multiPkgs, userFlakeNixOS, userFlakeInputs, userFlakeSelf }: +{ userFlakeNixOS, userFlakeInputs, userFlakeSelf }: + +{ dir, extern, suites, overrides, multiPkgs }: let defaultSystem = "x86_64-linux"; @@ -91,6 +93,8 @@ let }; in lib.os.devosSystem { + inherit userFlakeNixOS userFlakeInputs userFlakeSelf; + } { inherit specialArgs; system = defaultSystem; modules = modules // { inherit local lib; }; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 8fb2201..be32ddd 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,6 +1,8 @@ { lib, utils }: -{ extern, overrides, userFlakeNixOS, userFlakeSelf, userFlakeInputs }: +{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: + +{ extern, overrides }: (utils.lib.eachDefaultSystem (system: let diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 19dd1cf..8b25706 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -3,23 +3,30 @@ let inherit (dev) os; in -_: { self, ... } @ args: +_: { self, inputs, nixos, ... } @ args: let userFlakeSelf = self; + userFlakeInputs = inputs; + userFlakeNixOS = nixos; cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; - multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; + multiPkgs = os.mkPkgs + { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } + { inherit (cfg) extern overrides; }; outputs = { - nixosConfigurations = os.mkHosts { - inherit userFlakeSelf multiPkgs; - inherit (cfg) extern suites overrides; - dir = cfg.hosts; - }; + nixosConfigurations = os.mkHosts + { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } + { + inherit multiPkgs; + inherit (cfg) extern suites overrides; + dir = cfg.hosts; + }; - homeConfigurations = os.mkHomeConfigurations; + homeConfigurations = os.mkHomeConfigurations + { inherit userFlakeSelf; }; nixosModules = cfg.modules; @@ -36,7 +43,9 @@ let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { inherit pkgs; }; + legacyPackages = os.mkPackages + { inherit userFlakeSelf; } + { inherit pkgs; }; in { checks = pkgs-lib.tests.mkChecks { From dba178dc1fd8d6a4990e7bffaea867a7a774adb4 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:20:36 -0600 Subject: [PATCH 041/137] build docs new location --- .github/workflows/mdbook_docs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mdbook_docs.yml b/.github/workflows/mdbook_docs.yml index 27a1482..842171c 100644 --- a/.github/workflows/mdbook_docs.yml +++ b/.github/workflows/mdbook_docs.yml @@ -16,12 +16,12 @@ jobs: with: mdbook-version: 'latest' - - run: mdbook build + - run: mdbook build doc - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_branch: gh-pages - publish_dir: ./book + publish_dir: ./doc/book cname: devos.divnix.com From 50eaa4d0bab31c26355726c838971611541b6e8d Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:25:21 -0600 Subject: [PATCH 042/137] remove community action The community branch will likely go away soon. This is no longer required. --- .github/workflows/community_sync.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .github/workflows/community_sync.yml diff --git a/.github/workflows/community_sync.yml b/.github/workflows/community_sync.yml deleted file mode 100644 index 949ba05..0000000 --- a/.github/workflows/community_sync.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Sync Community Branch - -on: - workflow_run: - workflows: - - "CI - Changelog" - - "Release" - types: - - completed - branches: - - core - -jobs: - merge-core-to-community: - name: Merge core -> community - runs-on: ubuntu-latest - - steps: - - uses: tukasz/direct-merge-action@master - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - source-branch: core - target-branch: community From 362cc31827d32d9d187808d4f8b66a12d683f6fd Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:29:28 -0500 Subject: [PATCH 043/137] fix: constructors of mkFlake function family --- lib/flake.nix | 17 ++++++----------- lib/mkFlake/default.nix | 10 +++++++--- lib/mkFlake/evalArgs.nix | 8 +++++--- lib/mkFlake/evalOldArgs.nix | 6 ++++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 17d4754..14e2947 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -16,14 +16,6 @@ lib = nixpkgs.lib.makeExtensible (self: let - callLibs = file: import file - ({ - lib = self; - userFlakeNixos = {}; - userFlakeSelf = {}; - userFlakeInputs = {}; # TODO: Erm, theese must become proper arguments to mkFlake - } // inputs); - attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; lists = import ./lists.nix { lib = nixpkgs.lib // self; }; strings = import ./strings.nix { lib = nixpkgs.lib // self; }; @@ -40,9 +32,12 @@ }; mkFlake = { - __functor = callLibs ./mkFlake; - evalArgs = callLibs ./mkFlake/evalArgs.nix; - evalOldArgs = callLibs ./mkFlake/evalOldArgs.nix; + __functor = import ./mkFlake { + lib = nixpkgs.lib // self; + inherit deploy; + }; + evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; + evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; }; pkgs-lib = import ./pkgs-lib { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 8b25706..217baa6 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,6 +1,6 @@ -{ lib, deploy, ... }: +{ lib, deploy }: let - inherit (dev) os; + inherit (lib) os; in _: { self, inputs, nixos, ... } @ args: @@ -10,7 +10,11 @@ let userFlakeInputs = inputs; userFlakeNixOS = nixos; - cfg = (lib.mkFlake.evalOldArgs { inherit args; }).config; + cfg = ( + lib.mkFlake.evalOldArgs + { inherit userFlakeSelf userFlakeInputs; } + { inherit args; } + ).config; multiPkgs = os.mkPkgs { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index b7902b8..166fcf0 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,4 +1,6 @@ -{ userFlakeSelf, lib, nixpkgs, ... }: +{ lib }: + +{ userFlakeSelf, userFlakeNixOS }: { args }: let @@ -54,7 +56,7 @@ let options = with types; { input = mkOption { type = flakeType; - default = nixpkgs; + default = userFlakeNixOS; description = '' nixpkgs flake input to use for this channel ''; @@ -199,7 +201,7 @@ let let default = { nixpkgs = { - input = nixpkgs; + input = userFlakeNixOS; }; }; in diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 25dd7c9..d15fbc9 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,4 +1,6 @@ -{ userFlakeSelf, lib, inputs, ... }: +{ lib }: + +{ userFlakeSelf, userFlakeInputs }: { args }: let @@ -121,7 +123,7 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // userFlakeSelf.inputs; }); + apply = x: defaults // (x { inputs = userFlakeInputs // userFlakeSelf.inputs; }); description = '' Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. The function should return an attribute set with modules, overlays, and From c67877c2ebd9b511fe9e031eb6f1821d2b2be85e Mon Sep 17 00:00:00 2001 From: nrdxp Date: Mon, 19 Apr 2021 03:36:39 +0000 Subject: [PATCH 044/137] Update Changelog for tag --- CHANGELOG.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1bbb678 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,82 @@ +# Changelog + +## [v0.9.0](https://github.com/divnix/devos/tree/v0.9.0) (2021-04-19) + +**Implemented enhancements:** + +- pin inputs into iso live registry [\#190](https://github.com/divnix/devos/issues/190) +- Pass 'self' to lib [\#169](https://github.com/divnix/devos/issues/169) +- doc: quickstart "ISO. What next?" [\#167](https://github.com/divnix/devos/issues/167) +- Integrate Android AOSP putting mobile under control [\#149](https://github.com/divnix/devos/issues/149) +- Inoculate host identity on first use [\#132](https://github.com/divnix/devos/issues/132) +- kubenix support [\#130](https://github.com/divnix/devos/issues/130) +- Improve Home Manager support: profiles/suites, modules, extern, flake outputs [\#119](https://github.com/divnix/devos/issues/119) +- Local CA \(between hosts\) [\#104](https://github.com/divnix/devos/issues/104) +- Q5: git annex for machine state [\#68](https://github.com/divnix/devos/issues/68) +- name space ./pkgs overlays [\#60](https://github.com/divnix/devos/issues/60) +- remap global keys easily [\#57](https://github.com/divnix/devos/issues/57) +- make pass state part of this repo's structure [\#56](https://github.com/divnix/devos/issues/56) +- Incorporate ./shells [\#38](https://github.com/divnix/devos/issues/38) +- Encrypt with \(r\)age [\#37](https://github.com/divnix/devos/issues/37) + +**Fixed bugs:** + +- `pathsToImportedAttrs` does not accept directories [\#221](https://github.com/divnix/devos/issues/221) +- Cachix caches aren't added to the configuration [\#208](https://github.com/divnix/devos/issues/208) +- Issues with current changelog workflow [\#205](https://github.com/divnix/devos/issues/205) +- iso: systemd service startup [\#194](https://github.com/divnix/devos/issues/194) +- Help adding easy-hls-nix to devos [\#174](https://github.com/divnix/devos/issues/174) +- `flk update` fails because of obsolete flag [\#159](https://github.com/divnix/devos/issues/159) +- Expected that not all packages are exported? [\#151](https://github.com/divnix/devos/issues/151) +- Segmentation fault when generating iso [\#150](https://github.com/divnix/devos/issues/150) + +**Documentation:** + +- doc: split iso [\#193](https://github.com/divnix/devos/issues/193) +- lib: can depend on pkgs \(a la nixpkgs\#pkgs/pkgs-lib\) [\#147](https://github.com/divnix/devos/pull/147) + +**Closed issues:** + +- FRRouting router implementation [\#154](https://github.com/divnix/devos/issues/154) +- ARM aarch64 Support [\#72](https://github.com/divnix/devos/issues/72) + +## [v0.8.0](https://github.com/divnix/devos/tree/v0.8.0) (2021-03-02) + +**Implemented enhancements:** + +- semi automatic update for /pkgs [\#118](https://github.com/divnix/devos/issues/118) +- Home-manager external modules from flakes [\#106](https://github.com/divnix/devos/issues/106) + +**Fixed bugs:** + +- My emacsGcc overlay is not working [\#146](https://github.com/divnix/devos/issues/146) +- local flake registry freezes branches [\#142](https://github.com/divnix/devos/issues/142) +- nixos-option no longer works after collect garbage [\#138](https://github.com/divnix/devos/issues/138) +- Profiles imports are brittle, causing failure if imported twice [\#136](https://github.com/divnix/devos/issues/136) + +## [0.7.0](https://github.com/divnix/devos/tree/0.7.0) (2021-02-20) + +**Implemented enhancements:** + +- add zoxide [\#53](https://github.com/divnix/devos/issues/53) +- Multiarch support? [\#17](https://github.com/divnix/devos/issues/17) +- initial multiArch support [\#18](https://github.com/divnix/devos/pull/18) + +**Fixed bugs:** + +- Missing shebang from flk.sh [\#131](https://github.com/divnix/devos/issues/131) +- Rename Meta Issue [\#128](https://github.com/divnix/devos/issues/128) +- specialisations break the `system` argument [\#46](https://github.com/divnix/devos/issues/46) +- Revert "Add extraArgs to lib.nixosSystem call to add system args." [\#47](https://github.com/divnix/devos/pull/47) + +**Documentation:** + +- update home-manager urls [\#62](https://github.com/divnix/devos/pull/62) + +**Closed issues:** + +- add github action for cachix build ci [\#59](https://github.com/divnix/devos/issues/59) + + + +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 8134350545305cc970069ea92fe9dbadbc346840 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 22:40:53 -0500 Subject: [PATCH 045/137] ref: simplify pkgs-lib deps injection --- lib/pkgs-lib/default.nix | 23 ++++++----------------- lib/pkgs-lib/shell/default.nix | 7 +++++-- lib/pkgs-lib/tests/default.nix | 4 +++- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index a298d41..1b7c642 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,20 +1,9 @@ -args@{ lib, nixpkgs, deploy, devshell }: -lib.genAttrs lib.defaultSystems (system: - lib.makeExtensible (final: - let - pkgs = import nixpkgs { inherit system; }; - callLibs = file: import file - (args // { - inherit pkgs system; - pkgs-lib = final; - }); - in - with final; - { - inherit callLibs; +{ lib, nixpkgs, deploy, devshell }: - tests = callLibs ./tests; - shell = callLibs ./shell; +lib.genAttrs + lib.defaultSystems (system: + { + tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; + shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; } ) -) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 71c6c29..e43155b 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,14 +1,17 @@ -{ lib, devshell, deploy, system, nixpkgs, ... }: +{ lib, nixpkgs, devshell, deploy, system }: let overlays = [ + devshell.overlay + (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) + ]; - pkgs = lib.os.pkgImport nixpkgs overlays system; + pkgs = import nixpkgs { inherit system overlays;; config = {}; }; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index a72ade6..6111acd 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,5 +1,7 @@ -{ pkgs, system, deploy, nixpkgs, lib, ... }: +{ lib, nixpkgs, deploy, system }: let + pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; + mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs From 03e28433ce90f84ef0f848f92516ffd5171dde21 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 18 Apr 2021 21:42:54 -0600 Subject: [PATCH 046/137] README.md: fix guide link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b64c51c..ef7ed23 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ are unstable versions (0._x_._x_) to help users keep track of changes and progress. ## Getting Started -Check out the [guide](https://devos.divnix.com/doc/start) to get up and running. +Check out the [guide](https://devos.divnix.com/start) to get up and running. ## In the Wild The author maintains his own branch, so you can take inspiration, direction, or From a714cf466dc6e104fedd616e51bb111e4327766b Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 18 Apr 2021 23:48:19 -0500 Subject: [PATCH 047/137] fix: various left-overs --- extern/default.nix | 4 ---- flake.lock | 2 +- flake.nix | 2 +- lib/devos/devosSystem.nix | 4 ++-- lib/devos/mkHosts.nix | 8 ++++---- lib/mkFlake/evalOldArgs.nix | 8 ++++++++ lib/pkgs-lib/default.nix | 2 +- lib/pkgs-lib/shell/default.nix | 2 +- profiles/core/default.nix | 1 - 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/extern/default.nix b/extern/default.nix index 4ca9df6..19c1bae 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -7,10 +7,6 @@ overlays = [ nur.overlay - devshell.overlay - (final: prev: { - deploy-rs = deploy.packages.${prev.system}.deploy-rs; - }) pkgs.overlay ]; diff --git a/flake.lock b/flake.lock index 531c981..7d108f4 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-/SJJ8u/qBnCtMbMxBmDNBDnLWnmro2ioi35gL45hP9w=", + "narHash": "sha256-Mf67M0twCyNmRQxnhH51f6VroHaCwJKvFDMc1Wc7pt8=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 443c9b9..4bf5bdb 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ outputs = inputs@{ self, devos, nixos, nur, ... }: devos.lib.mkFlake { - inherit self; + inherit self inputs nixos; hosts = ./hosts; packages = import ./pkgs; suites = import ./suites; diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index f9a84d0..6ea50da 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,6 +1,6 @@ { lib }: -{ userFlakeNixos, userFlakeSelf, userFlakeInputs }: +{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: { modules, ... } @ args: lib.nixosSystem (args // { @@ -15,7 +15,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${userFlakeNixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${userFlakeNixOS}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index d86de4e..d4a785f 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -65,7 +65,7 @@ let # Everything in `./modules/list.nix`. flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; - cachix = ../../cachix.nix; + cachix = "${userFlakeSelf}/cachix.nix"; }; specialArgs = extern.specialArgs // { suites = suites.system; }; @@ -84,12 +84,12 @@ let hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; - }; - lib = { + lib = { inherit specialArgs; }; lib.testModule = { imports = builtins.attrValues modules; }; + }; in lib.os.devosSystem { @@ -97,7 +97,7 @@ let } { inherit specialArgs; system = defaultSystem; - modules = modules // { inherit local lib; }; + modules = modules // { inherit local; }; }; hosts = lib.os.recImport diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index d15fbc9..2cf9221 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -22,6 +22,14 @@ let type = addCheck attrs lib.isStorePath; description = "The flake to create the devos outputs for"; }; + nixos = mkOption { + type = addCheck attrs lib.isStorePath; + description = "The default nixpkgs channel of the devos"; + }; + inputs = mkOption { + type = addCheck attrs lib.isStorePath; + description = "All inptus of the devos"; + }; hosts = mkOption { type = path; default = "${userFlakeSelf}/hosts"; diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 1b7c642..40b451c 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -3,7 +3,7 @@ lib.genAttrs lib.defaultSystems (system: { - tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; + tests = import ./tests { inherit lib deploy nixpkgs system; }; shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; } ) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index e43155b..7744f68 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -11,7 +11,7 @@ let ]; - pkgs = import nixpkgs { inherit system overlays;; config = {}; }; + pkgs = import nixpkgs { inherit system overlays; config = {}; }; flk = pkgs.callPackage ./flk.nix { }; diff --git a/profiles/core/default.nix b/profiles/core/default.nix index f5a654c..077ffa2 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -11,7 +11,6 @@ in binutils coreutils curl - deploy-rs direnv dnsutils dosfstools From 24dbb2b3231b5a9f4a9aae57ef90436d59db300b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 11 Apr 2021 22:27:59 -0700 Subject: [PATCH 048/137] add mkFlakeDoc to pkgs-lib to build options doc --- lib/flake.nix | 3 +++ lib/jobs/default.nix | 5 +++++ lib/jobs/mkFlakeDoc.nix | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/jobs/default.nix create mode 100644 lib/jobs/mkFlakeDoc.nix diff --git a/lib/flake.nix b/lib/flake.nix index 14e2947..4120e83 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -57,9 +57,12 @@ } ); + jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; + in { + inherit jobs; lib = utils.lib // { inherit (lib) diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix new file mode 100644 index 0000000..2f108ed --- /dev/null +++ b/lib/jobs/default.nix @@ -0,0 +1,5 @@ +{ nixpkgs, lib, system ? "x86_64-linux" }: let + pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; +in { + mkFlakeDoc = import ./mkFlakeDoc.nix { inherit pkgs lib; }; +} diff --git a/lib/jobs/mkFlakeDoc.nix b/lib/jobs/mkFlakeDoc.nix new file mode 100644 index 0000000..45ddeed --- /dev/null +++ b/lib/jobs/mkFlakeDoc.nix @@ -0,0 +1,35 @@ +{ pkgs, lib, ... }: +let + singleDoc = name: value: '' + ## ${name} + ${value.description} + ${lib.optionalString (value ? type) '' + *_Type_*: + ${value.type} + ''} + ${lib.optionalString (value ? default) '' + *_Default_* + ``` + ${builtins.toJSON value.default} + ``` + ''} + ${lib.optionalString (value ? example) '' + *_Example_* + ``` + ${value.example} + ``` + ''} + ''; + + options = ( + lib.mkFlake.evalArgs + { userFlakeSelf = {}; userFlakeNixOS = {}; } + { args = { }; } + ).options; + + processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; + + fullDoc = lib.concatStringsSep "" (lib.mapAttrsToList singleDoc processedOptions); +in +pkgs.writeText "devosOptions.md" fullDoc + From f3defb486d1e79c62e5188da297743d12e8500da Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 12 Apr 2021 08:42:22 -0700 Subject: [PATCH 049/137] used coercedTo for typing and improve options allow lists, nested lists, and non-lists for list like options drop config..externalModules --- lib/mkFlake/evalArgs.nix | 89 ++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 166fcf0..6560f91 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -18,37 +18,32 @@ let /* Custom types needed for arguments */ - moduleType = with types; anything // { + moduleType = with types; pathTo (anything // { inherit (submodule { }) check; description = "valid module"; - }; - overlayType = types.anything // { + }); + overlayType = pathTo (types.anything // { check = builtins.isFunction; description = "valid Nixpkgs overlay"; - }; + }); systemType = types.enum config.supportedSystems; flakeType = with types; (addCheck attrs lib.isStorePath) // { description = "nix flake"; }; - # Applys maybeImport during merge and before check + # Apply maybeImport during merge and before check # To simplify apply keys and improve type checking - pathTo = elemType: mkOptionType { - name = "pathTo"; - description = "path that evaluates to a(n) ${elemType.name}"; - check = x: elemType.check (maybeImport x); - merge = loc: defs: - (mergeDefinitions loc elemType (map - (x: { - inherit (x) file; - value = maybeImport x.value; - }) - defs)).mergedValue; - getSubOptions = elemType.getSubOptions; - getSubModules = elemType.getSubModules; - substSubModules = m: pathTo (elemType.substSubModules m); - }; + pathTo = elemType: coercedTo path maybeImort elemType; + # Accepts single item or a list + # apply keys end up with a list + # This should not be used if expecting a nested list + # all lists will get flattened by this + coercedListOf = elemType: + let coerceToList = x: flatten (singleton x); in + with types; coercedTo elemType coerceToList (listOf elemType); + + pathToListOf = x: pathTo (coercedListOf x); /* Submodules needed for API containers */ @@ -62,7 +57,7 @@ let ''; }; overlays = mkOption { - type = pathTo (listOf overlayType); + type = pathToListOf overlayType; default = [ ]; description = '' overlays to apply to this channel @@ -70,7 +65,7 @@ let ''; }; externalOverlays = mkOption { - type = pathTo (listOf overlayType); + type = pathToListOf overlayType; default = [ ]; description = '' overlays to apply to the channel that don't get exported to the flake output @@ -104,14 +99,21 @@ let ''; }; modules = mkOption { - type = pathTo moduleType; + type = pathToListOf moduleType; default = [ ]; description = '' The configuration for this config ''; }; + }; + }; + + # This is only needed for configDefaults + # modules in each config don't get exported + externalModulesModule = { + options = { externalModules = mkOption { - type = pathTo moduleType; + type = pathToListOf moduleType; default = [ ]; description = '' The configuration for this config @@ -126,14 +128,17 @@ let includeConfigsModule = { name, ... }: { options = with types; { configDefaults = mkOption { - type = submodule configModule; + type = submodule [ configModule externalModulesModule ]; default = { }; description = '' - defaults for all configs + Defaults for all configs. + the modules passed under configDefault will be exported + to the '${name}Modules' flake output. + They will also be added to all configs. ''; }; configs = mkOption { - type = pathTo (attrsOf (submodule configModule)); + type = attrsOf (submodule configModule); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -142,30 +147,16 @@ let }; }; - # Options to import: modules, profiles, suites - importsModule = { name, ... }: { + # profiles and suites - which are profile collections + profilesModule = { name, ... }: { options = with types; { - modules = mkOption { - type = pathTo (listOf moduleType); - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in '${name}Modules' output - ''; - }; - externalModules = mkOption { - type = pathTo (listOf moduleType); - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confguration but these are not exported to the '${name}Modules' output - ''; - }; profiles = mkOption { - type = path; - default = "${userFlakeSelf}/profiles"; - defaultText = "\${userFlakeSelf}/profiles"; - apply = x: os.mkProfileAttrs (toString x); + type = coercedListOf path; + default = [ ]; + apply = list: + # Merge a list of profiles to one set + let profileList = map (x: os.mkProfileAttrs (toString x)) list; in + foldl (a: b: a // b) { } profileList; description = "path to profiles folder that can be collected into suites"; }; suites = mkOption { From eea4e40d7e0d996bc2d0091fd4be3bedef22cf32 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 21 Apr 2021 21:44:08 -0500 Subject: [PATCH 050/137] ref: config -> hosts | nixos -> os in devos, we differentiate clearly between home and os configuration, reason for which we are more precise by not naming after the (more generic) fup API. --- lib/mkFlake/evalArgs.nix | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 6560f91..6e5c2cf 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -82,63 +82,63 @@ let }; }; - configModule = { + hostModule = { options = with types; { system = mkOption { type = systemType; default = "x86_64-linux"; description = '' - system for this config + system for this host ''; }; channelName = mkOption { type = types.enum (builtins.attrValues config.channels); default = "nixpkgs"; description = '' - Channel this config should follow + Channel this host should follow ''; }; modules = mkOption { type = pathToListOf moduleType; default = [ ]; description = '' - The configuration for this config + The configuration for this host ''; }; }; }; - # This is only needed for configDefaults - # modules in each config don't get exported + # This is only needed for hostDefaults + # modules in each host don't get exported externalModulesModule = { options = { externalModules = mkOption { type = pathToListOf moduleType; default = [ ]; description = '' - The configuration for this config + The configuration for this host ''; }; }; }; # Home-manager's configs get exported automatically from nixos.hosts - # So there is no need for a config options in the home namespace + # So there is no need for a host options in the home namespace # This is only needed for nixos - includeConfigsModule = { name, ... }: { + includeHostsModule = { name, ... }: { options = with types; { - configDefaults = mkOption { - type = submodule [ configModule externalModulesModule ]; + hostDefaults = mkOption { + type = submodule [ hostModule externalModulesModule ]; default = { }; description = '' - Defaults for all configs. - the modules passed under configDefault will be exported + Defaults for all hosts. + the modules passed under hostDefaults will be exported to the '${name}Modules' flake output. - They will also be added to all configs. + They will also be added to all hosts. ''; }; - configs = mkOption { - type = attrsOf (submodule configModule); + hosts = mkOption { + type = attrsOf (submodule hostModule); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -204,8 +204,8 @@ let nixpkgs channels to create ''; }; - nixos = mkOption { - type = submodule [ includeConfigsModule importsModule ]; + os = mkOption { + type = submodule [ includeHostsModule importsModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos From 1240356b37889ade5a6c8c0096257602bbdfb530 Mon Sep 17 00:00:00 2001 From: Raphael Borun Das Gupta Date: Fri, 23 Apr 2021 01:10:02 +0200 Subject: [PATCH 051/137] doc: fix grammar: "your" -> "you're" where it's meant to be a contraction of "you are" rather than a possessive pronoun --- doc/CONTRIBUTING.md | 2 +- doc/integrations/cachix.md | 2 +- doc/start/from-nixos.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 5b75798..bb480ae 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -21,7 +21,7 @@ If you wish to contribute please follow these guidelines: * The commit message follows the same semantics as [nixpkgs][nixpkgs]. * You can use a `#` symbol to specify ambiguities. For example, - `develop#zsh: ` would tell me that your updating the + `develop#zsh: ` would tell me that you're updating the `zsh` subprofile living under the `develop` profile. [nixpkgs-fmt]: https://github.com/nix-community/nixpkgs-fmt diff --git a/doc/integrations/cachix.md b/doc/integrations/cachix.md index 3e4f3b5..b025459 100644 --- a/doc/integrations/cachix.md +++ b/doc/integrations/cachix.md @@ -1,6 +1,6 @@ # Cachix The system will automatically pull a cachix.nix at the root if one exists. -This is usually created automatically by a `sudo cachix use`. If your more +This is usually created automatically by a `sudo cachix use`. If you're more inclined to keep the root clean, you can drop any generated files in the `cachix` directory into the `profiles/cachix` directory without further modification. diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index bbb0e55..3e9a28e 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -1,7 +1,7 @@ # From NixOS ## Generate Configuration -Assuming your happy with your existing partition layout, you can generate a +Assuming you're happy with your existing partition layout, you can generate a basic NixOS configuration for your system using: ```sh flk up @@ -28,7 +28,7 @@ Now might be a good time to read the docs on [suites](../concepts/suites.md) and > them directly into a host module of your own making, and commit that instead. # Installation -Once your ready to deploy `hosts/my-host.nix`: +Once you're ready to deploy `hosts/my-host.nix`: ```sh flk my-host switch ``` From fe9ba26561d42f97bbc77d257cdd2823e98b4b2b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 17:59:01 -0700 Subject: [PATCH 052/137] evalArgs: cleanup module and type references fix pathTo and coercedList types add modulesModule to also include modules option under home --- lib/mkFlake/evalArgs.nix | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 6e5c2cf..b162ad1 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -33,7 +33,7 @@ let # Apply maybeImport during merge and before check # To simplify apply keys and improve type checking - pathTo = elemType: coercedTo path maybeImort elemType; + pathTo = elemType: with types; coercedTo path maybeImport elemType; # Accepts single item or a list # apply keys end up with a list @@ -98,13 +98,7 @@ let Channel this host should follow ''; }; - modules = mkOption { - type = pathToListOf moduleType; - default = [ ]; - description = '' - The configuration for this host - ''; - }; + }; }; @@ -122,13 +116,25 @@ let }; }; + modulesModule = { + options = { + modules = mkOption { + type = pathToListOf moduleType; + default = [ ]; + description = '' + modules to include + ''; + }; + }; + }; + # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a host options in the home namespace # This is only needed for nixos includeHostsModule = { name, ... }: { options = with types; { hostDefaults = mkOption { - type = submodule [ hostModule externalModulesModule ]; + type = submodule [ hostModule externalModulesModule modulesModule ]; default = { }; description = '' Defaults for all hosts. @@ -138,7 +144,7 @@ let ''; }; hosts = mkOption { - type = attrsOf (submodule hostModule); + type = attrsOf (submodule [ hostModule modulesModule ]); default = { }; description = '' configurations to include in the ${name}Configurations output @@ -205,14 +211,14 @@ let ''; }; os = mkOption { - type = submodule [ includeHostsModule importsModule ]; + type = submodule [ includeHostsModule profilesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos ''; }; home = mkOption { - type = submodule importsModule; + type = submodule [ profilesModule modulesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for home-manager From eab0bf074c221a5dcd810aa587dfac5b17d01ae5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 18:13:03 -0700 Subject: [PATCH 053/137] lib: one line for arguments, drop userFlake* Also format all files and add a flake.lock for lib for a folder thats meant to work on other flakes theres never a reason it should need to refer to itself, only other flakes. So "self" and "inputs" are better namings for these variables. The userFlake* is redundant and confusing, when trying to call the functions its hard to figure out how to use them when there are now two lines of arguments to figure out. --- flake.lock | 10 +- lib/devos/default.nix | 2 +- lib/devos/devosSystem.nix | 13 ++- lib/devos/mkHomeConfigurations.nix | 4 +- lib/devos/mkHosts.nix | 32 +++---- lib/devos/mkPackages.nix | 5 +- lib/devos/mkPkgs.nix | 12 +-- lib/devos/mkProfileAttrs.nix | 16 ++-- lib/flake.lock | 147 +++++++++++++++++++++++++++++ lib/flake.nix | 135 +++++++++++++------------- lib/jobs/default.nix | 8 +- lib/jobs/mkFlakeDoc.nix | 4 +- lib/mkFlake/default.nix | 34 +++---- lib/mkFlake/evalArgs.nix | 10 +- lib/mkFlake/evalOldArgs.nix | 28 +++--- lib/pkgs-lib/default.nix | 8 +- lib/pkgs-lib/shell/default.nix | 2 +- lib/pkgs-lib/tests/default.nix | 11 +-- lib/tests/default.nix | 46 ++++----- 19 files changed, 328 insertions(+), 199 deletions(-) create mode 100644 lib/flake.lock diff --git a/flake.lock b/flake.lock index f2b65a3..00b0728 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-aGpcPxOBIPnwj6uLNtpKefZjEbDkZnMHZ2mH12veHnY=", + "narHash": "sha256-LvO5VwFNFzb2xbmgw+fWhkrRY1KMlp5vxqQU/BqS0H8=", "path": "./lib", "type": "path" }, @@ -280,7 +280,7 @@ ] }, "locked": { - "narHash": "sha256-XG4TOZObj2Wd8KiqnHgtlWjjMbJOIJB7+DxUFzMCXw8=", + "narHash": "sha256-Zs7dc0dNNa0Z3//+Gckxj7SKrMqVovY0xZZ1z8xWnEg=", "path": "./pkgs", "type": "path" }, @@ -337,11 +337,11 @@ }, "utils_2": { "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "lastModified": 1618868421, + "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", "owner": "numtide", "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", "type": "github" }, "original": { diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 05ec38f..9a3118f 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -9,7 +9,7 @@ profileMap = list: map (profile: profile.default) (lib.flatten list); - mkNodes = import ./mkNodes.nix { inherit lib; }; + mkNodes = import ./mkNodes.nix { inherit lib; }; mkHosts = import ./mkHosts.nix { inherit lib; }; diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 6ea50da..c27a5a8 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,8 +1,7 @@ { lib }: -{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: - -{ modules, ... } @ args: +{ self, nixos, inputs, modules, ... } @ allArgs: +let args = builtins.removeAttrs allArgs [ "self" "nixos" "inputs" ]; in lib.nixosSystem (args // { modules = let @@ -15,7 +14,7 @@ lib.nixosSystem (args // { (args // { modules = moduleList ++ [ - "${userFlakeNixOS}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" + "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ({ config, suites, ... }: { @@ -25,15 +24,15 @@ lib.nixosSystem (args // { disabledModules = map (x: [ x ]) (lib.remove modules.core suites.allProfiles); - nix.registry = lib.mapAttrs (n: v: { flake = v; }) userFlakeInputs; + nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; isoImage.isoBaseName = "nixos-" + config.networking.hostName; isoImage.contents = [{ - source = userFlakeSelf; + source = self; target = "/devos/"; }]; isoImage.storeContents = [ - userFlakeSelf.devShell.${config.nixpkgs.system} + self.devShell.${config.nixpkgs.system} # include also closures that are "switched off" by the # above profile filter on the local config attribute fullHostConfig.system.build.toplevel diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 6ccfa50..3a07ba8 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -1,6 +1,6 @@ { lib }: -{ userFlakeSelf }: +nixosConfigurations: with lib; let @@ -8,7 +8,7 @@ let mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) config.config.system.build.homes; - hmConfigs = mapAttrs mkHomes userFlakeSelf.nixosConfigurations; + hmConfigs = mapAttrs mkHomes nixosConfigurations; in foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 3dc811e..2316da3 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -1,8 +1,6 @@ -{ lib }: +{ lib }: -{ userFlakeNixOS, userFlakeInputs, userFlakeSelf }: - -{ dir, extern, suites, overrides, multiPkgs }: +{ self, nixos, inputs, dir, extern, suites, overrides, multiPkgs }: let defaultSystem = "x86_64-linux"; @@ -31,24 +29,24 @@ let useUserPackages = true; extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues userFlakeSelf.homeModules); + sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); }; users.mutableUsers = lib.mkDefault false; hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${userFlakeNixOS}" - "nixos-config=${userFlakeSelf}/lib/compat/nixos" - "home-manager=${userFlakeInputs.home}" + "nixpkgs=${nixos}" + "nixos-config=${self}/lib/compat/nixos" + "home-manager=${inputs.home}" ]; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { - devos.flake = userFlakeSelf; - nixos.flake = userFlakeNixOS; - override.flake = userFlakeInputs.override; + devos.flake = self; + nixos.flake = nixos; + override.flake = inputs.override; }; nix.package = pkgs.nixFlakes; @@ -59,13 +57,13 @@ let } ''; - system.configurationRevision = lib.mkIf (userFlakeSelf ? rev) userFlakeSelf.rev; + system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues userFlakeSelf.nixosModules ++ extern.modules; }; + flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - cachix = let rootCachix = "${userFlakeSelf}/cachix.nix"; in + cachix = let rootCachix = "${self}/cachix.nix"; in if builtins.pathExists rootCachix then rootCachix else { } @@ -84,7 +82,7 @@ let networking = { inherit hostName; }; _module.args = { - self = userFlakeSelf; + self = self; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs hosts [ hostName ]); }; @@ -97,9 +95,7 @@ let }; in lib.os.devosSystem { - inherit userFlakeNixOS userFlakeInputs userFlakeSelf; - } { - inherit specialArgs; + inherit self nixos inputs specialArgs; system = defaultSystem; modules = modules // { inherit local; }; }; diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix index eeac929..d899268 100644 --- a/lib/devos/mkPackages.nix +++ b/lib/devos/mkPackages.nix @@ -1,10 +1,7 @@ { lib }: -{ userFlakeSelf }: - -{ pkgs }: +{ overlay, overlays, pkgs }: let - inherit (userFlakeSelf) overlay overlays; packagesNames = lib.attrNames (overlay null null) ++ lib.attrNames (lib.concatAttrs (lib.attrValues diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index be32ddd..a7cf236 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -1,12 +1,10 @@ { lib, utils }: -{ userFlakeNixOS, userFlakeSelf, userFlakeInputs }: - -{ extern, overrides }: +{ self, nixos, inputs, extern, overrides }: (utils.lib.eachDefaultSystem (system: let - overridePkgs = lib.os.pkgImport userFlakeInputs.override [ ] system; + overridePkgs = lib.os.pkgImport inputs.override [ ] system; overridesOverlay = overrides.packages; overlays = [ @@ -17,11 +15,11 @@ }); }) (overridesOverlay overridePkgs) - userFlakeSelf.overlay + self.overlay ] ++ extern.overlays - ++ (lib.attrValues userFlakeSelf.overlays); + ++ (lib.attrValues self.overlays); in - { pkgs = lib.os.pkgImport userFlakeNixOS overlays system; } + { pkgs = lib.os.pkgImport nixos overlays system; } ) ).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix index 0a96cfb..cdfc32e 100644 --- a/lib/devos/mkProfileAttrs.nix +++ b/lib/devos/mkProfileAttrs.nix @@ -2,16 +2,16 @@ let mkProfileAttrs = /** - Synopsis: mkProfileAttrs _path_ + Synopsis: mkProfileAttrs _path_ - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. + Recursively collect the subdirs of _path_ containing a default.nix into attrs. + This sets a contract, eliminating ambiguity for _default.nix_ living under the + profile directory. - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ + Example: + let profiles = mkProfileAttrs ./profiles; in + assert profiles ? core.default; 0 + **/ dir: let imports = diff --git a/lib/flake.lock b/lib/flake.lock new file mode 100644 index 0000000..f70c491 --- /dev/null +++ b/lib/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "deploy": { + "inputs": { + "flake-compat": "flake-compat", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1616406726, + "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", + "owner": "serokell", + "repo": "deploy-rs", + "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "deploy-rs", + "type": "github" + } + }, + "devshell": { + "locked": { + "lastModified": 1618523768, + "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", + "owner": "numtide", + "repo": "devshell", + "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1610392286, + "narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=", + "owner": "nmattia", + "repo": "naersk", + "rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1610942247, + "narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7d71001b796340b219d1bfa8552c81995017544a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1619244632, + "narHash": "sha256-IDcbMRnyKO9WlQ5xzIlM3HfWAUKTy+3xSd+CvDGiLgE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5cecebfb2f76da7b93f19967e99b3ff4fb4d2850", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "nixpkgs": "nixpkgs_2", + "utils": "utils_2" + } + }, + "utils": { + "locked": { + "lastModified": 1610051610, + "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "utils_2": { + "locked": { + "lastModified": 1618868421, + "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/lib/flake.nix b/lib/flake.nix index 4120e83..c9bd99a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -4,87 +4,84 @@ inputs = { deploy.url = "github:serokell/deploy-rs"; - deploy.inputs = { - utils.follows = "utils"; - }; devshell.url = "github:numtide/devshell"; utils.url = "github:numtide/flake-utils"; - }; - outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - - lib = nixpkgs.lib.makeExtensible (self: - let - attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; - lists = import ./lists.nix { lib = nixpkgs.lib // self; }; - strings = import ./strings.nix { lib = nixpkgs.lib // self; }; - in - - utils.lib - - // - - { - os = import ./devos { - lib = nixpkgs.lib // self; - inherit utils; - }; - - mkFlake = { - __functor = import ./mkFlake { - lib = nixpkgs.lib // self; - inherit deploy; - }; - evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; - evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; - }; - - pkgs-lib = import ./pkgs-lib { - lib = nixpkgs.lib // self; - inherit nixpkgs deploy devshell; - }; - - inherit (attrs) - mapFilterAttrs - genAttrs' - safeReadDir - pathsToImportedAttrs - concatAttrs - filterPackages; - inherit (lists) pathsIn; - inherit (strings) rgxToString; - } - ); - - jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; - - in - - { - inherit jobs; - - lib = utils.lib // { - inherit (lib) - mkFlake; - }; - - } - - // - - utils.lib.eachDefaultSystem (system: + outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - nixpkgs' = import nixpkgs { inherit system; overlays = []; config = {}; }; + + lib = nixpkgs.lib.makeExtensible (self: + let + attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; + lists = import ./lists.nix { lib = nixpkgs.lib // self; }; + strings = import ./strings.nix { lib = nixpkgs.lib // self; }; + in + + utils.lib + + // + + { + os = import ./devos { + lib = nixpkgs.lib // self; + inherit utils; + }; + + mkFlake = { + __functor = import ./mkFlake { + lib = nixpkgs.lib // self; + inherit deploy; + }; + evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; + evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; + }; + + pkgs-lib = import ./pkgs-lib { + lib = nixpkgs.lib // self; + inherit nixpkgs deploy devshell; + }; + + inherit (attrs) + mapFilterAttrs + genAttrs' + safeReadDir + pathsToImportedAttrs + concatAttrs + filterPackages; + inherit (lists) pathsIn; + inherit (strings) rgxToString; + } + ); + + jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; + in + + { + inherit jobs; + + lib = utils.lib // { + inherit (lib) + mkFlake; + }; + + } + + // + + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { checks = { tests = import ./tests { - inherit (nixpkgs') pkgs; + inherit pkgs; lib = nixpkgs.lib // lib; }; }; } - ); + ); } diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix index 2f108ed..5e9cff2 100644 --- a/lib/jobs/default.nix +++ b/lib/jobs/default.nix @@ -1,5 +1,7 @@ -{ nixpkgs, lib, system ? "x86_64-linux" }: let - pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; -in { +{ nixpkgs, lib, system ? "x86_64-linux" }: +let + pkgs = import nixpkgs { inherit system; overlays = [ ]; config = { }; }; +in +{ mkFlakeDoc = import ./mkFlakeDoc.nix { inherit pkgs lib; }; } diff --git a/lib/jobs/mkFlakeDoc.nix b/lib/jobs/mkFlakeDoc.nix index 45ddeed..5a13d9f 100644 --- a/lib/jobs/mkFlakeDoc.nix +++ b/lib/jobs/mkFlakeDoc.nix @@ -22,9 +22,7 @@ let ''; options = ( - lib.mkFlake.evalArgs - { userFlakeSelf = {}; userFlakeNixOS = {}; } - { args = { }; } + lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; } ).options; processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 217baa6..d086283 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -6,31 +6,26 @@ in _: { self, inputs, nixos, ... } @ args: let - userFlakeSelf = self; - userFlakeInputs = inputs; - userFlakeNixOS = nixos; - cfg = ( lib.mkFlake.evalOldArgs - { inherit userFlakeSelf userFlakeInputs; } - { inherit args; } + { inherit self inputs args; } ).config; multiPkgs = os.mkPkgs - { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } - { inherit (cfg) extern overrides; }; + { + inherit self inputs nixos; + inherit (cfg) extern overrides; + }; outputs = { nixosConfigurations = os.mkHosts - { inherit userFlakeSelf userFlakeInputs userFlakeNixOS; } { - inherit multiPkgs; + inherit self inputs nixos multiPkgs; inherit (cfg) extern suites overrides; dir = cfg.hosts; }; - homeConfigurations = os.mkHomeConfigurations - { inherit userFlakeSelf; }; + homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; nixosModules = cfg.modules; @@ -39,7 +34,7 @@ let overlay = cfg.packages; inherit (cfg) overlays; - deploy.nodes = os.mkNodes deploy userFlakeSelf.nixosConfigurations; + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; }; systemOutputs = lib.eachDefaultSystem (system: @@ -47,15 +42,16 @@ let pkgs = multiPkgs.${system}; pkgs-lib = lib.pkgs-lib.${system}; # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages - { inherit userFlakeSelf; } - { inherit pkgs; }; + legacyPackages = os.mkPackages { + inherit pkgs; + inherit (self) overlay overlays; + }; in { checks = pkgs-lib.tests.mkChecks { - inherit (userFlakeSelf.deploy) nodes; - hosts = userFlakeSelf.nixosConfigurations; - homes = userFlakeSelf.homeConfigurations; + inherit (self.deploy) nodes; + hosts = self.nixosConfigurations; + homes = self.homeConfigurations; }; inherit legacyPackages; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index b162ad1..cb90f61 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,8 +1,6 @@ { lib }: -{ userFlakeSelf, userFlakeNixOS }: - -{ args }: +{ nixos, args }: let argOpts = with lib; { config, ... }: let @@ -51,10 +49,10 @@ let options = with types; { input = mkOption { type = flakeType; - default = userFlakeNixOS; + default = nixos; description = '' nixpkgs flake input to use for this channel - ''; + ''; }; overlays = mkOption { type = pathToListOf overlayType; @@ -198,7 +196,7 @@ let let default = { nixpkgs = { - input = userFlakeNixOS; + input = nixos; }; }; in diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix index 2cf9221..c319d43 100644 --- a/lib/mkFlake/evalOldArgs.nix +++ b/lib/mkFlake/evalOldArgs.nix @@ -1,8 +1,6 @@ { lib }: -{ userFlakeSelf, userFlakeInputs }: - -{ args }: +{ self, inputs, args }: let argOpts = with lib; { config, options, ... }: let @@ -32,8 +30,8 @@ let }; hosts = mkOption { type = path; - default = "${userFlakeSelf}/hosts"; - defaultText = "\${userFlakeSelf}/hosts"; + default = "${self}/hosts"; + defaultText = "\${self}/hosts"; apply = toString; description = '' Path to directory containing host configurations that will be exported @@ -74,15 +72,15 @@ let }; profiles = mkOption { type = path; - default = "${userFlakeSelf}/profiles"; - defaultText = "\${userFlakeSelf}/profiles"; + default = "${self}/profiles"; + defaultText = "\${self}/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to profiles folder that can be collected into suites"; }; userProfiles = mkOption { type = path; - default = "${userFlakeSelf}/users/profiles"; - defaultText = "\${userFlakeSelf}/users/profiles"; + default = "${self}/users/profiles"; + defaultText = "\${self}/users/profiles"; apply = x: os.mkProfileAttrs (toString x); description = "path to user profiles folder that can be collected into userSuites"; }; @@ -107,8 +105,8 @@ let }; users = mkOption { type = path; - default = "${userFlakeSelf}/users"; - defaultText = "\${userFlakeSelf}/users"; + default = "${self}/users"; + defaultText = "\${self}/users"; apply = x: os.mkProfileAttrs (toString x); description = '' path to folder containing profiles that define system users @@ -131,9 +129,9 @@ let { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } ''; # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = userFlakeInputs // userFlakeSelf.inputs; }); + apply = x: defaults // (x { inputs = inputs // self.inputs; }); description = '' - Function with argument 'inputs' that contains all devos and ''${userFlakeSelf}'s inputs. + Function with argument 'inputs' that contains all devos and ''${self}'s inputs. The function should return an attribute set with modules, overlays, and specialArgs to be included across nixos and home manager configurations. Only attributes that are used should be returned. @@ -141,8 +139,8 @@ let }; overlays = mkOption { type = path; - default = "${userFlakeSelf}/overlays"; - defaultText = "\${userFlakeSelf}/overlays"; + default = "${self}/overlays"; + defaultText = "\${self}/overlays"; apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); description = '' path to folder containing overlays which will be applied to pkgs and exported in diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 40b451c..1cadc2f 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,9 +1,13 @@ { lib, nixpkgs, deploy, devshell }: lib.genAttrs - lib.defaultSystems (system: + lib.defaultSystems + (system: + let + pkgs = import nixpkgs { inherit system; }; + in { - tests = import ./tests { inherit lib deploy nixpkgs system; }; + tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; } ) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 7744f68..0146ca2 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -11,7 +11,7 @@ let ]; - pkgs = import nixpkgs { inherit system overlays; config = {}; }; + pkgs = import nixpkgs { inherit system overlays; config = { }; }; flk = pkgs.callPackage ./flk.nix { }; diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 6111acd..b3e6062 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,7 +1,5 @@ -{ lib, nixpkgs, deploy, system }: +{ lib, nixpkgs, pkgs, deploy, system }: let - pkgs = import nixpkgs { inherit system; overlays = []; config = {}; }; - mkChecks = { hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs @@ -9,9 +7,10 @@ let nodes; deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; tests = - lib.optionalAttrs (deployHosts != { }) { - profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); - } // lib.mapAttrs (n: v: v.activationPackage) homes; + lib.optionalAttrs (deployHosts != { }) + { + profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; diff --git a/lib/tests/default.nix b/lib/tests/default.nix index 4863cdf..ab4d516 100644 --- a/lib/tests/default.nix +++ b/lib/tests/default.nix @@ -1,27 +1,27 @@ { pkgs, lib }: pkgs.runCommandNoCC "devos-lib-tests" - { - buildInputs = [ - pkgs.nix - ( - let tests = import ./lib.nix { inherit pkgs lib; }; in - if tests == [ ] then null - else throw (builtins.toJSON tests) - ) - ]; - } '' - datadir="${pkgs.nix}/share" - export TEST_ROOT=$(pwd)/test-tmp - export NIX_BUILD_HOOK= - export NIX_CONF_DIR=$TEST_ROOT/etc - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix - export NIX_STATE_DIR=$TEST_ROOT/var/nix - export NIX_STORE_DIR=$TEST_ROOT/store - export PAGER=cat - cacheDir=$TEST_ROOT/binary-cache - nix-store --init +{ + buildInputs = [ + pkgs.nix + ( + let tests = import ./lib.nix { inherit pkgs lib; }; in + if tests == [ ] then null + else throw (builtins.toJSON tests) + ) + ]; +} '' + datadir="${pkgs.nix}/share" + export TEST_ROOT=$(pwd)/test-tmp + export NIX_BUILD_HOOK= + export NIX_CONF_DIR=$TEST_ROOT/etc + export NIX_LOCALSTATE_DIR=$TEST_ROOT/var + export NIX_LOG_DIR=$TEST_ROOT/var/log/nix + export NIX_STATE_DIR=$TEST_ROOT/var/nix + export NIX_STORE_DIR=$TEST_ROOT/store + export PAGER=cat + cacheDir=$TEST_ROOT/binary-cache + nix-store --init - touch $out - '' + touch $out +'' From 12b41f24480ff46a2291a2bf1f393a13f19a6cd1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 23:51:51 -0700 Subject: [PATCH 054/137] devosSystem: fix iso build - can't remove core --- lib/devos/devosSystem.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index b0f53fd..f194f3b 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -20,8 +20,7 @@ lib.nixosSystem (args // { # avoid unwanted systemd service startups # all strings in disabledModules get appended to modulesPath # so convert each to list which can be coerced to string - disabledModules = map (x: [ x ]) - (lib.remove modules.core suites.allProfiles); + disabledModules = map lib.singleton suites.allProfiles; nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; From 832d3bd69782015a0f4b6001e050d18d5f8ea9c8 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 00:08:49 -0700 Subject: [PATCH 055/137] profilesTest/mkHosts: include host's configuration --- lib/devos/mkHosts.nix | 2 +- lib/pkgs-lib/tests/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index abb7c4e..cb3c316 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -90,7 +90,7 @@ let lib = { lib = { inherit specialArgs; }; lib.testModule = { - imports = builtins.attrValues modules; + imports = [ local ] ++ builtins.attrValues modules; }; }; in diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 3c28468..d924a80 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -48,7 +48,7 @@ let }; testScript = '' - machine.systemctl("is-system-running --wait") + ${host.config.networking.hostName}.systemctl("is-system-running --wait") ''; }; From 1cd4ed136a76f8c5342168ff86e8af93f7eb5e45 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:14:58 -0700 Subject: [PATCH 056/137] mkFlakeDoc: move to packages output the packages output allows us to do `nix build .#nixosOptionsDoc`. theres also already an instantiated nixpkgs available there. --- flake.lock | 2 +- lib/flake.nix | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 00b0728..23e6089 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-LvO5VwFNFzb2xbmgw+fWhkrRY1KMlp5vxqQU/BqS0H8=", + "narHash": "sha256-eZJ8p2u56dkLPxF7GiQLbQ6YRKHP6DoOM52G/p+M/3w=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index c9bd99a..6c7484a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -81,6 +81,14 @@ lib = nixpkgs.lib // lib; }; }; + packages = { + mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" + ( + pkgs.nixosOptionsDoc { + inherit (lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; }) options; + } + ).optionsMDDoc; + }; } ); From a53aa8b7eb04f87c8dda74cf82282f73230d4c06 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:37:23 -0700 Subject: [PATCH 057/137] lib: drop jobs output, prefer checks and packages With mkFlakeDoc in packages there is no need for jobs. And I think anything that could go in jobs really should go in checks or packages. If something needs to be tested - checks, if something needs to be built - packages. jobs is not multi-arch and is redundant to build/test things with when official flake outputs exist --- flake.lock | 2 +- lib/flake.nix | 4 ---- lib/jobs/default.nix | 7 ------- lib/jobs/mkFlakeDoc.nix | 33 --------------------------------- 4 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 lib/jobs/default.nix delete mode 100644 lib/jobs/mkFlakeDoc.nix diff --git a/flake.lock b/flake.lock index 23e6089..0e3ada8 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-eZJ8p2u56dkLPxF7GiQLbQ6YRKHP6DoOM52G/p+M/3w=", + "narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index 6c7484a..c694169 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -54,13 +54,9 @@ } ); - jobs = import ./jobs { inherit nixpkgs; lib = nixpkgs.lib // lib; }; - in { - inherit jobs; - lib = utils.lib // { inherit (lib) mkFlake; diff --git a/lib/jobs/default.nix b/lib/jobs/default.nix deleted file mode 100644 index 5e9cff2..0000000 --- a/lib/jobs/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ nixpkgs, lib, system ? "x86_64-linux" }: -let - pkgs = import nixpkgs { inherit system; overlays = [ ]; config = { }; }; -in -{ - mkFlakeDoc = import ./mkFlakeDoc.nix { inherit pkgs lib; }; -} diff --git a/lib/jobs/mkFlakeDoc.nix b/lib/jobs/mkFlakeDoc.nix deleted file mode 100644 index 5a13d9f..0000000 --- a/lib/jobs/mkFlakeDoc.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ pkgs, lib, ... }: -let - singleDoc = name: value: '' - ## ${name} - ${value.description} - ${lib.optionalString (value ? type) '' - *_Type_*: - ${value.type} - ''} - ${lib.optionalString (value ? default) '' - *_Default_* - ``` - ${builtins.toJSON value.default} - ``` - ''} - ${lib.optionalString (value ? example) '' - *_Example_* - ``` - ${value.example} - ``` - ''} - ''; - - options = ( - lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; } - ).options; - - processedOptions = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix; - - fullDoc = lib.concatStringsSep "" (lib.mapAttrsToList singleDoc processedOptions); -in -pkgs.writeText "devosOptions.md" fullDoc - From ae357cb098ea2753f3ac6e4a412920762a36a292 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Wed, 21 Apr 2021 23:39:03 -0600 Subject: [PATCH 058/137] Check & Upload to Cache with GitHub Action --- .github/workflows/check.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..e4fc197 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,28 @@ +name: "Check & Cachix" +on: + push: + branches: + - core + - trying + - staging +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + - uses: cachix/install-nix-action@v13 + with: + install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20210415_76980a1/install + extra_nix_config: | + experimental-features = nix-command flakes + system-features = nixos-test benchmark big-parallel kvm recursive-nix + substituters = https://nrdxp.cachix.org https://nix-community.cachix.org https://cache.nixos.org + trusted-public-keys = nrdxp.cachix.org-1:Fc5PSqY2Jm1TrWfm88l6cvGWwz3s93c6IOifQWnhNW4= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + - uses: cachix/cachix-action@v10 + with: + name: nrdxp + signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix -Lv flake check + - run: nix -Lv build ".#nixosConfigurations.NixOS.config.system.build.toplevel" + - run: nix -Lv develop -c echo OK From b03fd1496d118d3413e876021de86725ea5cac5b Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Wed, 21 Apr 2021 23:40:44 -0600 Subject: [PATCH 059/137] pkgs: fix flake hash --- flake.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 3996268..a20aca5 100644 --- a/flake.lock +++ b/flake.lock @@ -216,7 +216,7 @@ ] }, "locked": { - "narHash": "sha256-XG4TOZObj2Wd8KiqnHgtlWjjMbJOIJB7+DxUFzMCXw8=", + "narHash": "sha256-Zs7dc0dNNa0Z3//+Gckxj7SKrMqVovY0xZZ1z8xWnEg=", "path": "./pkgs", "type": "path" }, From 7a825bbeb62261954bf44d7ac5a8f2870e77d8c4 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 22 Apr 2021 00:32:00 -0600 Subject: [PATCH 060/137] ci: update bors.toml for new pipeline --- bors.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bors.toml b/bors.toml index 2d565db..72690c0 100644 --- a/bors.toml +++ b/bors.toml @@ -1,7 +1,4 @@ -status = [ - "ci/hercules/evaluation", - "ci/hercules/derivations" -] +status = [ "check" ] required_approvals = 1 From 2d9ea0d27edebd81fb599d87167548e5365e9b69 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 08:56:51 -0700 Subject: [PATCH 061/137] lib: init modules and move mkHosts modules there This helps to split up the code in mkHosts and creates a place where we can store modules relevent to devos. It will also be easier to remove unecessary parts of each module in the future when they are all compartmentalized. --- flake.lock | 2 +- lib/devos/mkHosts.nix | 74 +++++++------------------------------------ lib/flake.nix | 2 ++ lib/modules.nix | 74 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 lib/modules.nix diff --git a/flake.lock b/flake.lock index 0e3ada8..a9e5e03 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=", + "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix index 2316da3..2fe4ed3 100644 --- a/lib/devos/mkHosts.nix +++ b/lib/devos/mkHosts.nix @@ -4,70 +4,18 @@ let defaultSystem = "x86_64-linux"; - experimentalFeatures = [ - "flakes" - "nix-command" - "ca-references" - "ca-derivations" - ]; - - modules = { - modOverrides = { config, overrideModulesPath, ... }: - let - inherit (overrides) modules disabledModules; - in - { - disabledModules = modules ++ disabledModules; - imports = map - (path: "${overrideModulesPath}/${path}") - modules; - }; - - global = { config, pkgs, ... }: { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - - extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; - sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); - }; - users.mutableUsers = lib.mkDefault false; - - hardware.enableRedistributableFirmware = lib.mkDefault true; - - nix.nixPath = [ - "nixpkgs=${nixos}" - "nixos-config=${self}/lib/compat/nixos" - "home-manager=${inputs.home}" - ]; - - nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; - - nix.registry = { - devos.flake = self; - nixos.flake = nixos; - override.flake = inputs.override; - }; - - nix.package = pkgs.nixFlakes; - - nix.extraOptions = '' - experimental-features = ${lib.concatStringsSep " " - experimentalFeatures - } - ''; - - system.configurationRevision = lib.mkIf (self ? rev) self.rev; + modules = with lib.modules; { + modOverrides = modOverrides { inherit overrides; }; + hmDefaults = hmDefaults { + inherit extern; + inherit (self) homeModules; + userSuites = suites.user; }; - - # Everything in `./modules/list.nix`. - flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - - cachix = let rootCachix = "${self}/cachix.nix"; in - if builtins.pathExists rootCachix - then rootCachix - else { } - ; + globalDefaults = globalDefaults { + inherit self nixos inputs multiPkgs; + }; + cachix = cachix { inherit self; }; + flakeModules = flakeModules { inherit self extern; }; }; specialArgs = extern.specialArgs // { suites = suites.system; }; diff --git a/lib/flake.nix b/lib/flake.nix index c694169..8e6063c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -16,6 +16,7 @@ attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; lists = import ./lists.nix { lib = nixpkgs.lib // self; }; strings = import ./strings.nix { lib = nixpkgs.lib // self; }; + modules = import ./modules.nix { lib = nixpkgs.lib // self; }; in utils.lib @@ -51,6 +52,7 @@ filterPackages; inherit (lists) pathsIn; inherit (strings) rgxToString; + inherit modules; } ); diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100644 index 0000000..1e5b8a8 --- /dev/null +++ b/lib/modules.nix @@ -0,0 +1,74 @@ +{ lib }: +{ + modOverrides = { overrides }: + { config, overrideModulesPath, ... }: + let + inherit (overrides) modules disabledModules; + in + { + disabledModules = modules ++ disabledModules; + imports = map + (path: "${overrideModulesPath}/${path}") + modules; + }; + + hmDefaults = { userSuites, extern, homeModules }: { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + + extraSpecialArgs = extern.userSpecialArgs // { suites = userSuites; }; + sharedModules = extern.userModules ++ (builtins.attrValues homeModules); + }; + }; + + globalDefaults = { self, nixos, inputs, multiPkgs }: + let + experimentalFeatures = [ + "flakes" + "nix-command" + "ca-references" + "ca-derivations" + ]; + in + { config, pkgs, ... }: { + users.mutableUsers = lib.mkDefault false; + + hardware.enableRedistributableFirmware = lib.mkDefault true; + + nix.nixPath = [ + "nixpkgs=${nixos}" + "nixos-config=${self}/lib/compat/nixos" + "home-manager=${inputs.home}" + ]; + + nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; + + nix.registry = { + devos.flake = self; + nixos.flake = nixos; + override.flake = inputs.override; + }; + + nix.package = pkgs.nixFlakes; + + nix.extraOptions = '' + experimental-features = ${lib.concatStringsSep " " + experimentalFeatures + } + ''; + + system.configurationRevision = lib.mkIf (self ? rev) self.rev; + }; + + cachix = { self }: + let rootCachix = "${self}/cachix.nix"; in + if builtins.pathExists rootCachix + then rootCachix + else { }; + + flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + + +} + From 4e28ec2d8ef8125d8b2d99e0c81c3fa4efde2d62 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 23 Apr 2021 23:51:51 -0700 Subject: [PATCH 062/137] devosSystem: fix iso build - can't remove core --- lib/devos/devosSystem.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index c27a5a8..cc03a67 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -21,8 +21,7 @@ lib.nixosSystem (args // { # avoid unwanted systemd service startups # all strings in disabledModules get appended to modulesPath # so convert each to list which can be coerced to string - disabledModules = map (x: [ x ]) - (lib.remove modules.core suites.allProfiles); + disabledModules = map lib.singleton suites.allProfiles; nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; From 58c7d0403649c5f5362c1ea717fe40758a065f0d Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 09:10:10 -0700 Subject: [PATCH 063/137] extract iso/hm config modules to lib.modules --- flake.lock | 2 +- lib/devos/devosSystem.nix | 76 ++------------------------------------- lib/modules.nix | 74 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 75 deletions(-) diff --git a/flake.lock b/flake.lock index a9e5e03..0f3b3eb 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=", + "narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index cc03a67..00c9e3e 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -6,91 +6,19 @@ lib.nixosSystem (args // { modules = let moduleList = builtins.attrValues modules; - modpath = "nixos/modules"; fullHostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config; isoConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - - "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" - - ({ config, suites, ... }: { - - # avoid unwanted systemd service startups - # all strings in disabledModules get appended to modulesPath - # so convert each to list which can be coerced to string - disabledModules = map lib.singleton suites.allProfiles; - - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; - - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - isoImage.contents = [{ - source = self; - target = "/devos/"; - }]; - isoImage.storeContents = [ - self.devShell.${config.nixpkgs.system} - # include also closures that are "switched off" by the - # above profile filter on the local config attribute - fullHostConfig.system.build.toplevel - ]; - # still pull in tools of deactivated profiles - environment.systemPackages = fullHostConfig.environment.systemPackages; - - # confilcts with networking.wireless which might be slightly - # more useful on a stick - networking.networkmanager.enable = lib.mkForce false; - # confilcts with networking.wireless - networking.wireless.iwd.enable = lib.mkForce false; - - # Set up a link-local boostrap network - # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 - networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works - networking.useNetworkd = lib.mkForce true; - networking.useDHCP = lib.mkForce false; - networking.dhcpcd.enable = lib.mkForce false; - systemd.network = { - # https://www.freedesktop.org/software/systemd/man/systemd.network.html - networks."boostrap-link-local" = { - matchConfig = { - Name = "en* wl* ww*"; - }; - networkConfig = { - Description = "Link-local host bootstrap network"; - MulticastDNS = true; - LinkLocalAddressing = "ipv6"; - DHCP = "yes"; - }; - address = [ - # fall back well-known link-local for situations where MulticastDNS is not available - "fe80::47" # 47: n=14 i=9 x=24; n+i+x - ]; - extraConfig = '' - # Unique, yet stable. Based off the MAC address. - IPv6LinkLocalAddressGenerationMode = "eui64" - ''; - }; - }; - }) + (lib.modules.iso { inherit self nixos inputs fullHostConfig; }) ]; })).config; hmConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - ({ config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }) + (lib.modules.hmConfig) ]; })).config; in diff --git a/lib/modules.nix b/lib/modules.nix index 1e5b8a8..7024f13 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -69,6 +69,80 @@ flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + isoConfig = { self, nixos, inputs, fullHostConfig }: + { config, suites, ... }: { + imports = let modpath = "nixos/modules"; in + [ "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; + # avoid unwanted systemd service startups + # all strings in disabledModules get appended to modulesPath + # so convert each to list which can be coerced to string + disabledModules = map lib.singleton suites.allProfiles; + + nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; + + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + isoImage.contents = [{ + source = self; + target = "/devos/"; + }]; + isoImage.storeContents = [ + self.devShell.${config.nixpkgs.system} + # include also closures that are "switched off" by the + # above profile filter on the local config attribute + fullHostConfig.system.build.toplevel + ]; + # still pull in tools of deactivated profiles + environment.systemPackages = fullHostConfig.environment.systemPackages; + + # confilcts with networking.wireless which might be slightly + # more useful on a stick + networking.networkmanager.enable = lib.mkForce false; + # confilcts with networking.wireless + networking.wireless.iwd.enable = lib.mkForce false; + + # Set up a link-local boostrap network + # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 + networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works + networking.useNetworkd = lib.mkForce true; + networking.useDHCP = lib.mkForce false; + networking.dhcpcd.enable = lib.mkForce false; + systemd.network = { + # https://www.freedesktop.org/software/systemd/man/systemd.network.html + networks."boostrap-link-local" = { + matchConfig = { + Name = "en* wl* ww*"; + }; + networkConfig = { + Description = "Link-local host bootstrap network"; + MulticastDNS = true; + LinkLocalAddressing = "ipv6"; + DHCP = "yes"; + }; + address = [ + # fall back well-known link-local for situations where MulticastDNS is not available + "fe80::47" # 47: n=14 i=9 x=24; n+i+x + ]; + extraConfig = '' + # Unique, yet stable. Based off the MAC address. + IPv6LinkLocalAddressGenerationMode = "eui64" + ''; + }; + }; + }; + + hmConfig = + { config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + }; } From 2cab5b5d2b30fba6431a4a2b82f0e83afac19589 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 20:53:16 -0700 Subject: [PATCH 064/137] add and use lib.collectProfiles this function collects profiles recursively --- flake.lock | 2 +- lib/devos/mkSuites.nix | 8 ++------ lib/flake.nix | 2 +- lib/lists.nix | 11 +++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 0f3b3eb..1c95e54 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=", + "narHash": "sha256-t14TKUtw83dZ2mbqjRpeUvdAx4zpe/ySr5KhPhB1JMU=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index cb73679..66a36ea 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -8,13 +8,9 @@ let inherit (args) users profiles userProfiles; }; - allProfiles = - let defaults = lib.collect (x: x ? default) profiles; - in map (x: x.default) defaults; + allProfiles = lib.collectProfiles profiles; - allUsers = - let defaults = lib.collect (x: x ? default) users; - in map (x: x.default) defaults; + allUsers = lib.collectProfiles users; createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // { inherit allProfiles allUsers; diff --git a/lib/flake.nix b/lib/flake.nix index 8e6063c..15d8719 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -50,7 +50,7 @@ pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn; + inherit (lists) pathsIn collectProfiles; inherit (strings) rgxToString; inherit modules; } diff --git a/lib/lists.nix b/lib/lists.nix index 1862041..c20a4d7 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1,5 +1,16 @@ { lib }: { + collectProfiles = set: + let + collectNestedProfiles = set: + lib.mapAttrsToList (n: v: + if builtins.isAttrs v then + [ v.default or null ] ++ collectNestedProfiles v + else null + ) set; + in + builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); + pathsIn = dir: let fullPath = name: "${toString dir}/${name}"; From abd133c244e9c9f9be8a66bd4a2e1a98e4090270 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:21:40 -0700 Subject: [PATCH 065/137] make devosSystem construct a proper nixos builder Get `self` and `inputs` during construction, and rely on specialArgs.channel for nixos flake --- lib/devos/devosSystem.nix | 63 ++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index 00c9e3e..c48f68a 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -1,31 +1,40 @@ { lib }: -{ self, nixos, inputs, modules, ... } @ allArgs: -let args = builtins.removeAttrs allArgs [ "self" "nixos" "inputs" ]; in -lib.nixosSystem (args // { - modules = - let - moduleList = builtins.attrValues modules; +# dependencies to return a builder +{ self, inputs }: - fullHostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config; +{ modules, specialArgs, ... } @ args: +let inherit (specialArgs.channel.input.lib) nixosSystem; in +nixosSystem + (args // { + modules = + let + fullHostConfig = (nixosSystem (args // { inherit modules; })).config; - isoConfig = (lib.nixosSystem - (args // { - modules = moduleList ++ [ - (lib.modules.iso { inherit self nixos inputs fullHostConfig; }) - ]; - })).config; - hmConfig = (lib.nixosSystem - (args // { - modules = moduleList ++ [ - (lib.modules.hmConfig) - ]; - })).config; - in - moduleList ++ [{ - system.build = { - iso = isoConfig.system.build.isoImage; - homes = hmConfig.home-manager.users; - }; - }]; -}) + isoConfig = (nixosSystem + (args // { + modules = modules ++ [ + (lib.modules.iso { inherit self inputs fullHostConfig; }) + ]; + })).config; + + hmConfig = (nixosSystem + (args // { + modules = modules ++ [ + (lib.modules.hmConfig) + ]; + })).config; + in + modules ++ [{ + system.build = { + iso = isoConfig.system.build.isoImage; + homes = hmConfig.home-manager.users; + }; + lib = { + inherit specialArgs; + testModule = { + imports = modules; + }; + }; + }]; + }) From 59383e871f882cb1a72c64392bdb48220db1367c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:22:33 -0700 Subject: [PATCH 066/137] modules: drop any logic already done by fup this includes creating multiPkgs, and dropping options already set by fup --- lib/modules.nix | 46 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 7024f13..2cd965f 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1,28 +1,16 @@ { lib }: { - modOverrides = { overrides }: - { config, overrideModulesPath, ... }: - let - inherit (overrides) modules disabledModules; - in - { - disabledModules = modules ++ disabledModules; - imports = map - (path: "${overrideModulesPath}/${path}") - modules; - }; - - hmDefaults = { userSuites, extern, homeModules }: { + hmDefaults = { suites, modules }: { home-manager = { useGlobalPkgs = true; useUserPackages = true; - extraSpecialArgs = extern.userSpecialArgs // { suites = userSuites; }; - sharedModules = extern.userModules ++ (builtins.attrValues homeModules); + extraSpecialArgs = { inherit suites; }; + sharedModules = modules; }; }; - globalDefaults = { self, nixos, inputs, multiPkgs }: + globalDefaults = { self, inputs }: let experimentalFeatures = [ "flakes" @@ -31,27 +19,22 @@ "ca-derivations" ]; in - { config, pkgs, ... }: { + { channel, config, pkgs, ... }: { users.mutableUsers = lib.mkDefault false; hardware.enableRedistributableFirmware = lib.mkDefault true; nix.nixPath = [ - "nixpkgs=${nixos}" + "nixpkgs=${channel.input}" "nixos-config=${self}/lib/compat/nixos" "home-manager=${inputs.home}" ]; - nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; - nix.registry = { devos.flake = self; - nixos.flake = nixos; - override.flake = inputs.override; + nixos.flake = channel.input; }; - nix.package = pkgs.nixFlakes; - nix.extraOptions = '' experimental-features = ${lib.concatStringsSep " " experimentalFeatures @@ -61,19 +44,10 @@ system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; - cachix = { self }: - let rootCachix = "${self}/cachix.nix"; in - if builtins.pathExists rootCachix - then rootCachix - else { }; + isoConfig = { self, inputs, fullHostConfig }: + { config, modulesPath, suites, ... }: { - flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; - - isoConfig = { self, nixos, inputs, fullHostConfig }: - { config, suites, ... }: { - - imports = let modpath = "nixos/modules"; in - [ "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; + imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; # avoid unwanted systemd service startups # all strings in disabledModules get appended to modulesPath # so convert each to list which can be coerced to string From ba01aa7db7419a3e301f5f9251eff358d88c7e17 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 10:52:26 -0700 Subject: [PATCH 067/137] mkSuites: generalize for one profile/suite pair --- lib/devos/mkSuites.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix index 66a36ea..45d8a10 100644 --- a/lib/devos/mkSuites.nix +++ b/lib/devos/mkSuites.nix @@ -1,20 +1,20 @@ { lib }: -{ users, profiles, userProfiles, suites } @ args: +{ suites, profiles } @ args: let inherit (lib) os; - definedSuites = suites { - inherit (args) users profiles userProfiles; - }; + profileSet = lib.genAttrs' profiles (path: { + name = baseNameOf path; + value = os.mkProfileAttrs (toString path); + }); - allProfiles = lib.collectProfiles profiles; - - allUsers = lib.collectProfiles users; - - createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // { - inherit allProfiles allUsers; - }; + definedSuites = suites profileSet; + allProfiles = lib.collectProfiles profileSet; in -lib.mapAttrs createSuites definedSuites +lib.mapAttrs (_: v: os.profileMap v) definedSuites // { + inherit allProfiles; +} + + From 3986cc441b86cb7873c99eb2252df4b080976f76 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:36:48 -0700 Subject: [PATCH 068/137] pkgs-lib: don't system space functions have each function take pkgs as an argument, so a nixpkgs isn't created just for pkgs-lib and they support more systems --- lib/flake.nix | 2 +- lib/pkgs-lib/default.nix | 17 +++++------------ lib/pkgs-lib/shell/default.nix | 25 ++++++++++++++----------- lib/pkgs-lib/tests/default.nix | 25 ++++++++++++++----------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 15d8719..393c9d6 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -40,7 +40,7 @@ pkgs-lib = import ./pkgs-lib { lib = nixpkgs.lib // self; - inherit nixpkgs deploy devshell; + inherit deploy devshell; }; inherit (attrs) diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 1cadc2f..bcaee77 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,13 +1,6 @@ -{ lib, nixpkgs, deploy, devshell }: +{ lib, deploy, devshell }: +{ + tests = import ./tests { inherit lib deploy; }; + shell = import ./shell { inherit lib devshell deploy; }; +} -lib.genAttrs - lib.defaultSystems - (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; - shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; - } - ) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 0146ca2..5b73b54 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,27 +1,30 @@ -{ lib, nixpkgs, devshell, deploy, system }: +{ lib, devshell, deploy }: + +{ pkgs }: let overlays = [ - devshell.overlay (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) - ]; - pkgs = import nixpkgs { inherit system overlays; config = { }; }; + pkgs' = import pkgs.path { + inherit (pkgs) system; + inherit overlays; + }; - flk = pkgs.callPackage ./flk.nix { }; + flk = pkgs'.callPackage ./flk.nix { }; installPkgs = (lib.nixosSystem { - inherit system; + inherit (pkgs') system; modules = [ ]; }).config.system.build; in -pkgs.devshell.mkShell { - imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; +pkgs'.devshell.mkShell { + imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]; packages = with installPkgs; [ nixos-install @@ -33,13 +36,13 @@ pkgs.devshell.mkShell { pre-commit.text = lib.fileContents ./pre-commit.sh; }; - commands = with pkgs; [ + commands = with pkgs'; [ { package = flk; } { name = "nix"; - help = pkgs.nixFlakes.meta.description; + help = pkgs'.nixFlakes.meta.description; command = '' - ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" + ${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" ''; } ] diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index b3e6062..854332f 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,25 +1,28 @@ -{ lib, nixpkgs, pkgs, deploy, system }: +{ lib, deploy }: let - mkChecks = { hosts, nodes, homes ? { } }: + mkChecks = { pkgs, hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs - (n: _: hosts.${n}.config.nixpkgs.system == system) + (n: _: hosts.${n}.config.nixpkgs.system == pkgs.system) nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + deployChecks = deploy.lib.${pkgs.system}.deployChecks { nodes = deployHosts; }; tests = lib.optionalAttrs (deployHosts != { }) { - profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + profilesTest = profilesTest { + inherit pkgs; + host = hosts.${(builtins.head (builtins.attrNames deployHosts))}; + }; } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; - mkTest = host: + mkTest = { pkgs, host }: let nixosTesting = - (import "${nixpkgs}/nixos/lib/testing-python.nix" { - inherit system; + (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { + inherit (pkgs) system; inherit (host.config.lib) specialArgs; inherit pkgs; extraConfigurations = [ @@ -40,15 +43,15 @@ let in nixosTesting.makeTest calledTest; - profilesTest = host: mkTest host { + profilesTest = args@{ host, ... }: mkTest args { name = "profiles"; machine = { suites, ... }: { - imports = suites.allProfiles ++ suites.allUsers; + imports = suites.allProfiles; }; testScript = '' - machine.systemctl("is-system-running --wait") + ${host.config.networking.hostName}.systemctl("is-system-running --wait") ''; }; in From ceef51425e222c85eab4c4053426f08ba880ebe3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:46:02 -0700 Subject: [PATCH 069/137] init unifyOverlays: to pass channels to overlays Only to those with three arguments --- lib/flake.nix | 2 +- lib/lists.nix | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/flake.nix b/lib/flake.nix index 393c9d6..862570c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -50,7 +50,7 @@ pathsToImportedAttrs concatAttrs filterPackages; - inherit (lists) pathsIn collectProfiles; + inherit (lists) pathsIn collectProfiles unifyOverlays; inherit (strings) rgxToString; inherit modules; } diff --git a/lib/lists.nix b/lib/lists.nix index c20a4d7..5e9c57b 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -16,4 +16,6 @@ fullPath = name: "${toString dir}/${name}"; in map fullPath (lib.attrNames (lib.safeReadDir dir)); + + unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); } From 377381de51b4dcbf5aea1ee7f80abd12abd63d47 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 11:34:24 -0700 Subject: [PATCH 070/137] export pathsIn in lib and update devos input --- flake.lock | 2 +- lib/flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 1c95e54..014caf8 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-t14TKUtw83dZ2mbqjRpeUvdAx4zpe/ySr5KhPhB1JMU=", + "narHash": "sha256-JBTc4NiKuJ99+u8ey+1gQezW5pihAnfnyupBmdj4zUk=", "path": "./lib", "type": "path" }, diff --git a/lib/flake.nix b/lib/flake.nix index 862570c..65c0e20 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -61,7 +61,7 @@ { lib = utils.lib // { inherit (lib) - mkFlake; + mkFlake pathsIn; }; } From 3bb26330b457c32aee5249c8c114517466044a5b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:46:59 -0700 Subject: [PATCH 071/137] switch to flake-utils-plus staging for rebase --- flake.lock | 35 +++++++++++++++++++++++++++-------- lib/flake.lock | 33 ++++++++++++++++++++++++++------- lib/flake.nix | 2 +- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/flake.lock b/flake.lock index 014caf8..b862c3f 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-JBTc4NiKuJ99+u8ey+1gQezW5pihAnfnyupBmdj4zUk=", + "narHash": "sha256-y0IZEAqpQpdGhxfc6REAT2PY2nEbikusUlXCRv264vI=", "path": "./lib", "type": "path" }, @@ -138,6 +138,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home": { "inputs": { "nixpkgs": [ @@ -336,17 +351,21 @@ } }, "utils_2": { + "inputs": { + "flake-utils": "flake-utils" + }, "locked": { - "lastModified": 1618868421, - "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "lastModified": 1619438935, + "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "gytis-ivaskevicius", + "ref": "staging", + "repo": "flake-utils-plus", "type": "github" } } diff --git a/lib/flake.lock b/lib/flake.lock index f70c491..6942e2a 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -52,6 +52,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "naersk": { "inputs": { "nixpkgs": [ @@ -127,17 +142,21 @@ } }, "utils_2": { + "inputs": { + "flake-utils": "flake-utils" + }, "locked": { - "lastModified": 1618868421, - "narHash": "sha256-vyoJhLV6cJ8/tWz+l9HZLIkb9Rd9esE7p+0RL6zDR6Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "eed214942bcfb3a8cc09eb3b28ca7d7221e44a94", + "lastModified": 1619438935, + "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "gytis-ivaskevicius", + "ref": "staging", + "repo": "flake-utils-plus", "type": "github" } } diff --git a/lib/flake.nix b/lib/flake.nix index 65c0e20..9025477 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -5,7 +5,7 @@ { deploy.url = "github:serokell/deploy-rs"; devshell.url = "github:numtide/devshell"; - utils.url = "github:numtide/flake-utils"; + utils.url = "github:gytis-ivaskevicius/flake-utils-plus/staging"; }; outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: From f8315a293c4585f89aef4f5815f94ceac7f28fd9 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:52:02 -0700 Subject: [PATCH 072/137] evalArgs: general api improvements drop default channel, it is confusing and complicates api don't take nixos input, using channels is better manually pass names for outputs to improve documentation --- lib/mkFlake/evalArgs.nix | 124 ++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index cb90f61..5884dcf 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -1,11 +1,12 @@ { lib }: -{ nixos, args }: +{ args }: let argOpts = with lib; { config, ... }: let inherit (lib) os; + cfg = config; inherit (config) self; maybeImport = obj: @@ -33,23 +34,19 @@ let # To simplify apply keys and improve type checking pathTo = elemType: with types; coercedTo path maybeImport elemType; - # Accepts single item or a list - # apply keys end up with a list - # This should not be used if expecting a nested list - # all lists will get flattened by this - coercedListOf = elemType: - let coerceToList = x: flatten (singleton x); in - with types; coercedTo elemType coerceToList (listOf elemType); + pathToListOf = elemType: with types; pathTo (listOf elemType); - pathToListOf = x: pathTo (coercedListOf x); + coercedListOf = elemType: with types; + coercedTo elemType (x: flatten (singleton x)) (listOf elemType); /* Submodules needed for API containers */ - channelsModule = { + channelsModule = { name, ... }: { options = with types; { input = mkOption { type = flakeType; - default = nixos; + default = cfg.inputs.${name}; + defaultText = escape [ "<" ">" ] "inputs."; description = '' nixpkgs flake input to use for this channel ''; @@ -57,22 +54,15 @@ let overlays = mkOption { type = pathToListOf overlayType; default = [ ]; - description = '' + description = escape [ "<" ">" ] '' overlays to apply to this channel these will get exported under the 'overlays' flake output as / ''; }; - externalOverlays = mkOption { - type = pathToListOf overlayType; - default = [ ]; - description = '' - overlays to apply to the channel that don't get exported to the flake output - useful to include overlays from inputs - ''; - }; config = mkOption { type = pathTo attrs; default = { }; + apply = lib.recursiveUpdate cfg.channelsConfig; description = '' nixpkgs config for this channel ''; @@ -82,21 +72,21 @@ let hostModule = { options = with types; { + # anything null in hosts gets filtered out by mkFlake system = mkOption { - type = systemType; - default = "x86_64-linux"; + type = nullOr systemType; + default = null; description = '' system for this host ''; }; channelName = mkOption { - type = types.enum (builtins.attrValues config.channels); - default = "nixpkgs"; + type = nullOr (types.enum (builtins.attrNames config.channels)); + default = null; description = '' Channel this host should follow ''; }; - }; }; @@ -105,7 +95,7 @@ let externalModulesModule = { options = { externalModules = mkOption { - type = pathToListOf moduleType; + type = with types; listOf moduleType; default = [ ]; description = '' The configuration for this host @@ -117,7 +107,7 @@ let modulesModule = { options = { modules = mkOption { - type = pathToListOf moduleType; + type = with types; coercedListOf moduleType; default = [ ]; description = '' modules to include @@ -126,13 +116,34 @@ let }; }; + exportModulesModule = name: { + options = { + modules = mkOption { + type = with types; pathToListOf + # check if the path evaluates to a proper module + # but this must be a path for the export to work + (addCheck path (x: moduleType.check (import x))); + default = [ ]; + description = '' + modules to include in all hosts and export to ${name}Modules output + ''; + }; + }; + }; + + + # Home-manager's configs get exported automatically from nixos.hosts # So there is no need for a host options in the home namespace # This is only needed for nixos - includeHostsModule = { name, ... }: { + includeHostsModule = name: { options = with types; { hostDefaults = mkOption { - type = submodule [ hostModule externalModulesModule modulesModule ]; + type = submodule [ + hostModule + externalModulesModule + (exportModulesModule name) + ]; default = { }; description = '' Defaults for all hosts. @@ -152,15 +163,11 @@ let }; # profiles and suites - which are profile collections - profilesModule = { name, ... }: { + profilesModule = { config, ... }: { options = with types; { profiles = mkOption { - type = coercedListOf path; + type = listOf path; default = [ ]; - apply = list: - # Merge a list of profiles to one set - let profileList = map (x: os.mkProfileAttrs (toString x)) list; in - foldl (a: b: a // b) { } profileList; description = "path to profiles folder that can be collected into suites"; }; suites = mkOption { @@ -185,6 +192,13 @@ let type = flakeType; description = "The flake to create the devos outputs for"; }; + inputs = mkOption { + type = attrsOf flakeType; + description = '' + inputs for this flake + used to set channel defaults and create registry + ''; + }; supportedSystems = mkOption { type = listOf str; default = lib.defaultSystems; @@ -192,31 +206,33 @@ let The systems supported by this flake ''; }; - channels = - let - default = { - nixpkgs = { - input = nixos; - }; - }; - in - mkOption { - type = attrsOf (submodule channelsModule); - inherit default; - apply = x: default // x; - description = '' - nixpkgs channels to create - ''; - }; - os = mkOption { - type = submodule [ includeHostsModule profilesModule ]; + channelsConfig = mkOption { + type = pathTo attrs; + default = { }; + description = '' + nixpkgs config for all channels + ''; + }; + channels = mkOption { + type = attrsOf (submodule channelsModule); + default = { }; + description = '' + nixpkgs channels to create + ''; + }; + nixos = mkOption { + type = submodule [ (includeHostsModule "nixos") profilesModule ]; default = { }; description = '' hosts, modules, suites, and profiles for nixos ''; }; home = mkOption { - type = submodule [ profilesModule modulesModule ]; + type = submodule [ + profilesModule + (exportModulesModule "home") + externalModulesModule + ]; default = { }; description = '' hosts, modules, suites, and profiles for home-manager From dceac02b36f418bc91f09760b3861dbee1c03848 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:50:01 -0700 Subject: [PATCH 073/137] implement mkFlake for new api and rebase on fup --- lib/flake.nix | 3 +- lib/mkFlake/default.nix | 121 ++++++++++++++++----------- lib/mkFlake/evalOldArgs.nix | 162 ------------------------------------ 3 files changed, 72 insertions(+), 214 deletions(-) delete mode 100644 lib/mkFlake/evalOldArgs.nix diff --git a/lib/flake.nix b/lib/flake.nix index 9025477..17e069c 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -35,7 +35,6 @@ inherit deploy; }; evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; - evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; }; pkgs-lib = import ./pkgs-lib { @@ -83,7 +82,7 @@ mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" ( pkgs.nixosOptionsDoc { - inherit (lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; }) options; + inherit (lib.mkFlake.evalArgs { args = { }; }) options; } ).optionsMDDoc; }; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index d086283..3d285c7 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,64 +1,85 @@ { lib, deploy }: let inherit (lib) os; + inherit (builtins) mapAttrs attrNames attrValues head isFunction; in -_: { self, inputs, nixos, ... } @ args: +_: { self, inputs, ... } @ args: let - cfg = ( - lib.mkFlake.evalOldArgs - { inherit self inputs args; } - ).config; - - multiPkgs = os.mkPkgs - { - inherit self inputs nixos; - inherit (cfg) extern overrides; - }; - - outputs = { - nixosConfigurations = os.mkHosts - { - inherit self inputs nixos multiPkgs; - inherit (cfg) extern suites overrides; - dir = cfg.hosts; - }; - - homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; - - nixosModules = cfg.modules; - - homeModules = cfg.userModules; - - overlay = cfg.packages; - inherit (cfg) overlays; - - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + config = lib.mkFlake.evalArgs { + args = lib.mkMerge [ args { _module.check = false; } ]; }; - systemOutputs = lib.eachDefaultSystem (system: - let - pkgs = multiPkgs.${system}; - pkgs-lib = lib.pkgs-lib.${system}; - # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { - inherit pkgs; - inherit (self) overlay overlays; - }; - in - { - checks = pkgs-lib.tests.mkChecks { + cfg = config.config; + + otherArguments = removeAttrs args (attrNames config.options); + + defaultModules = with lib.modules; [ + (hmDefaults { + inherit (cfg.home) suites; + modules = cfg.home.modules ++ cfg.home.externalModules; + }) + (globalDefaults { + inherit self inputs; + }) + ]; + + getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; +in +lib.systemFlake (lib.recursiveUpdate + otherArguments + { + inherit self inputs; + inherit (cfg) channelsConfig supportedSystems; + + mkFlakeConfig = config; + + channels = mapAttrs + (name: channel: + channel // { + # pass channels if "overlay" has three arguments + overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; + } + ) cfg.channels; + + # the host arguments cannot exist for fup hostDefaults to work + # so evalArgs sets them to null by default and the null args are filtered out here + hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts; + + hostDefaults = { + specialArgs.suites = cfg.nixos.suites; + modules = cfg.nixos.hostDefaults.modules + ++ cfg.nixos.hostDefaults.externalModules + ++ defaultModules; + builder = os.devosSystem { inherit self inputs; }; + inherit (cfg.nixos.hostDefaults) + channelName + system; + }; + + nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; + + homeModules = lib.exporter.modulesFromList cfg.home.modules; + homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; + + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + + overlays = lib.exporter.overlaysFromChannelsExporter { inherit (self) pkgs inputs; }; + + packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; + + checksBuilder = channels: + lib.pkgs-lib.tests.mkChecks { + pkgs = getDefaultChannel channels; inherit (self.deploy) nodes; hosts = self.nixosConfigurations; homes = self.homeConfigurations; }; - inherit legacyPackages; - packages = lib.filterPackages system legacyPackages; - - devShell = pkgs-lib.shell; - }); -in -outputs // systemOutputs - + devShellBuilder = channels: + lib.pkgs-lib.shell { + pkgs = getDefaultChannel channels; + }; + } +) diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix deleted file mode 100644 index c319d43..0000000 --- a/lib/mkFlake/evalOldArgs.nix +++ /dev/null @@ -1,162 +0,0 @@ -{ lib }: - -{ self, inputs, args }: -let - argOpts = with lib; { config, options, ... }: - let - inherit (lib) os; - - inherit (config) self; - - inputAttrs = with types; functionTo attrs; - moduleType = with types; anything // { - inherit (submodule { }) check; - description = "valid module"; - }; - in - { - options = with types; { - self = mkOption { - type = addCheck attrs lib.isStorePath; - description = "The flake to create the devos outputs for"; - }; - nixos = mkOption { - type = addCheck attrs lib.isStorePath; - description = "The default nixpkgs channel of the devos"; - }; - inputs = mkOption { - type = addCheck attrs lib.isStorePath; - description = "All inptus of the devos"; - }; - hosts = mkOption { - type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; - apply = toString; - description = '' - Path to directory containing host configurations that will be exported - to the 'nixosConfigurations' output. - ''; - }; - packages = mkOption { - # functionTo changes arg names which breaks flake check - type = types.anything // { - check = builtins.isFunction; - description = "Nixpkgs overlay"; - }; - default = (final: prev: { }); - defaultText = "(final: prev: {})"; - description = '' - Overlay for custom packages that will be included in treewide 'pkgs'. - This should follow the standard nixpkgs overlay format - two argument function - that returns an attrset. - These packages will be exported to the 'packages' and 'legacyPackages' outputs. - ''; - }; - modules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in 'nixosModules' output - ''; - }; - userModules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in home-manager configurations and export in - 'homeModules' output - ''; - }; - profiles = mkOption { - type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to profiles folder that can be collected into suites"; - }; - userProfiles = mkOption { - type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to user profiles folder that can be collected into userSuites"; - }; - suites = - let - defaults = { user = { }; system = { }; }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = "{ user = {}; system = {}; }"; - apply = suites: defaults // os.mkSuites { - inherit suites; - inherit (config) profiles users userProfiles; - }; - description = '' - Function with inputs 'users' and 'profiles' that returns attribute set - with user and system suites. The former for Home Manager and the latter - for nixos configurations. - These can be accessed through the 'suites' specialArg in each config system. - ''; - }; - users = mkOption { - type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; - apply = x: os.mkProfileAttrs (toString x); - description = '' - path to folder containing profiles that define system users - ''; - }; - extern = - let - defaults = { - modules = [ ]; - overlays = [ ]; - specialArgs = { }; - userModules = [ ]; - userSpecialArgs = { }; - }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = '' - { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } - ''; - # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); - description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. - The function should return an attribute set with modules, overlays, and - specialArgs to be included across nixos and home manager configurations. - Only attributes that are used should be returned. - ''; - }; - overlays = mkOption { - type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; - apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); - description = '' - path to folder containing overlays which will be applied to pkgs and exported in - the 'overlays' output - ''; - }; - overrides = mkOption rec { - type = attrs; - default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; - defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; - apply = x: default // x; - description = "attrset of packages and modules that will be pulled from nixpkgs master"; - }; - }; - }; -in -lib.evalModules { - modules = [ argOpts args ]; -} From c3d8805ad607935f033c737391978100d772bca0 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 21 Apr 2021 22:44:15 -0500 Subject: [PATCH 074/137] update devos template to use new api --- extern/default.nix | 25 -------------- extern/overrides.nix | 33 ------------------- flake.lock | 40 +++++++++++------------ flake.nix | 78 ++++++++++++++++++++++++++++++++------------ overrides.nix | 26 +++++++++++++++ 5 files changed, 103 insertions(+), 99 deletions(-) delete mode 100644 extern/default.nix delete mode 100644 extern/overrides.nix create mode 100644 overrides.nix diff --git a/extern/default.nix b/extern/default.nix deleted file mode 100644 index 19c1bae..0000000 --- a/extern/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ inputs }: with inputs; -{ - modules = [ - home.nixosModules.home-manager - ci-agent.nixosModules.agent-profile - ]; - - overlays = [ - nur.overlay - pkgs.overlay - ]; - - # passed to all nixos modules - specialArgs = { - overrideModulesPath = "${override}/nixos/modules"; - hardware = nixos-hardware.nixosModules; - }; - - # added to home-manager - userModules = [ - ]; - - # passed to all home-manager modules - userSpecialArgs = { }; -} diff --git a/extern/overrides.nix b/extern/overrides.nix deleted file mode 100644 index 78e6ee8..0000000 --- a/extern/overrides.nix +++ /dev/null @@ -1,33 +0,0 @@ -# override defaults to nixpkgs/master -{ - # modules to pull from override, stable version is automatically disabled - modules = [ ]; - - # if a modules name changed in override, add the old name here - disabledModules = [ ]; - - # packages pulled from override - packages = pkgs: final: prev: { - inherit (pkgs) - cachix - dhall - discord - element-desktop - manix - nixpkgs-fmt - qutebrowser - signal-desktop - starship; - - haskellPackages = prev.haskellPackages.override { - overrides = hfinal: hprev: - let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; - in - { - # same for haskell packages, matching ghc versions - inherit (pkgs.haskell.packages."ghc${version}") - haskell-language-server; - }; - }; - }; -} diff --git a/flake.lock b/flake.lock index b862c3f..90ffa98 100644 --- a/flake.lock +++ b/flake.lock @@ -12,7 +12,7 @@ "nixos" ], "nixos-unstable": [ - "override" + "latest" ], "pre-commit-hooks-nix": "pre-commit-hooks-nix" }, @@ -33,7 +33,7 @@ "darwin": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-y0IZEAqpQpdGhxfc6REAT2PY2nEbikusUlXCRv264vI=", + "narHash": "sha256-MvrBYZG6sZqpa8mTg4RYeD9aezYbVppBnslRyH7qZys=", "path": "./lib", "type": "path" }, @@ -173,10 +173,24 @@ "type": "github" } }, + "latest": { + "locked": { + "lastModified": 1619400530, + "narHash": "sha256-7ZO7B+b9i1wFbHw62EFT+iwuBBpXeA/fcHlR63Z4J0w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e8dc8adab655eb27957859c62bef11484b53f639", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "naersk": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -197,7 +211,7 @@ "naersk_2": { "inputs": { "nixpkgs": [ - "override" + "latest" ] }, "locked": { @@ -274,20 +288,6 @@ "type": "indirect" } }, - "override": { - "locked": { - "lastModified": 1615926763, - "narHash": "sha256-yeq8A3EPNuQVlsxlEQrIRsklfJwJK0Us6jtcG/u8wNs=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "b702a56d417647de4090ac56c0f18bdc7e646610", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, "pkgs": { "inputs": { "nixpkgs": [ @@ -327,11 +327,11 @@ "devos": "devos", "flake-compat": "flake-compat_2", "home": "home", + "latest": "latest", "naersk": "naersk_2", "nixos": "nixos", "nixos-hardware": "nixos-hardware", "nur": "nur", - "override": "override", "pkgs": "pkgs" } }, diff --git a/flake.nix b/flake.nix index bad78f1..5591fb0 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixos.url = "nixpkgs/nixos-unstable"; - override.url = "nixpkgs"; + latest.url = "nixpkgs"; devos.url = "path:./lib"; # TODO: outfactor into separate repo devos.inputs = { nixpkgs.follows = "nixos"; @@ -17,38 +17,74 @@ ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; - inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "override"; }; + inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "latest"; }; }; darwin.url = "github:LnL7/nix-darwin"; - darwin.inputs.nixpkgs.follows = "override"; + darwin.inputs.nixpkgs.follows = "latest"; flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; home.url = "github:nix-community/home-manager"; home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; - naersk.inputs.nixpkgs.follows = "override"; + naersk.inputs.nixpkgs.follows = "latest"; nixos-hardware.url = "github:nixos/nixos-hardware"; pkgs.url = "path:./pkgs"; pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, devos, nixos, nur, ... }: + outputs = inputs@{ self, pkgs, devos, nixos, ci-agent, home, nixos-hardware, nur, ... }: devos.lib.mkFlake { - inherit self inputs nixos; - hosts = ./hosts; - packages = import ./pkgs; - suites = import ./profiles/suites.nix; - extern = import ./extern; - overrides = import ./extern/overrides.nix; - overlays = ./overlays; - profiles = ./profiles; - userProfiles = ./users/profiles; - modules = import ./modules/module-list.nix; - userModules = import ./users/modules/module-list.nix; - } // { - defaultTemplate = self.templates.flk; - templates.flk.path = ./.; - templates.flk.description = "flk template"; - }; + inherit self inputs; + + channelsConfig = { allowUnfree = true; }; + + channels = { + nixos = { + overlays = nixos.lib.flatten [ + (devos.lib.pathsIn ./overlays) + pkgs.overlay + ./overrides.nix # from "latest" channel + nur.overlay + ]; + }; + latest = { }; + }; + + nixos = { + hostDefaults = { + system = "x86_64-linux"; + channelName = "nixos"; + modules = ./modules/module-list.nix; + externalModules = [ + ci-agent.nixosModules.agent-profile + home.nixosModules.home-manager + ]; + }; + hosts = { + NixOS = { + modules = ./hosts/NixOS.nix; + }; + }; + profiles = [ ./profiles ./users ]; + suites = { profiles, users, ... }: with profiles; { + base = [ core users.nixos users.root ]; + }; + }; + + home = { + modules = ./users/modules/module-list.nix; + externalModules = [ ]; + profiles = [ ./users/profiles ]; + suites = { profiles, ... }: with profiles; { + base = [ direnv git ]; + }; + }; + + #defaultTemplate = self.templates.flk; + templates.flk.path = ./.; + templates.flk.description = "flk template"; + + } + ; } diff --git a/overrides.nix b/overrides.nix new file mode 100644 index 0000000..bb3cf68 --- /dev/null +++ b/overrides.nix @@ -0,0 +1,26 @@ +channels: final: prev: { + + inherit (channels.latest) + cachix + dhall + discord + element-desktop + manix + nixpkgs-fmt + qutebrowser + signal-desktop + starship; + + + haskellPackages = prev.haskellPackages.override { + overrides = hfinal: hprev: + let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; + in + { + # same for haskell packages, matching ghc versions + inherit (channels.latest.haskell.packages."ghc${version}") + haskell-language-server; + }; + }; + +} From 9f31d5d6d1e5c204fcf5ce938a8ae95528dddf4f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 12:20:16 -0700 Subject: [PATCH 075/137] mkFlake: use inputs argument not self.inputs --- lib/mkFlake/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 3d285c7..ebeb86c 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -65,7 +65,10 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; - overlays = lib.exporter.overlaysFromChannelsExporter { inherit (self) pkgs inputs; }; + overlays = lib.exporter.overlaysFromChannelsExporter { + inherit inputs; + inherit (self) pkgs; + }; packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; From 37820fc2148051117feaa684fb52238cde71d25f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 12:29:18 -0700 Subject: [PATCH 076/137] explain overlay exporting inputs workaround --- lib/mkFlake/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index ebeb86c..cd8d037 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -66,6 +66,10 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { + /* since we can't detect overlays owned by self + we have to filter out ones exported by the inputs + optimally we would want a solution for NixOS/nix#4740 + */ inherit inputs; inherit (self) pkgs; }; From b766c693abd5530c1dc4fd16cd229addca7c3219 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 13:21:40 -0700 Subject: [PATCH 077/137] add pkgs overlay, pkgs.overlay is just for srcs --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5591fb0..1e23ced 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,8 @@ nixos = { overlays = nixos.lib.flatten [ (devos.lib.pathsIn ./overlays) - pkgs.overlay + ./pkgs/default.nix + pkgs.overlay # for `srcs` ./overrides.nix # from "latest" channel nur.overlay ]; From 2a7d9e71096746cd19b56cdbf61ba1c910fb6013 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 13:30:10 -0700 Subject: [PATCH 078/137] fix suites test to match new mkSuites --- lib/tests/lib.nix | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index 6626478..e992df6 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -71,23 +71,19 @@ lib.runTests { }; }; - testSuites = - let - profiles = os.mkProfileAttrs (toString ./profiles); - users = ""; - userProfiles = ""; - suites = { profiles, ... }: { - system.bar = [ profiles.foo ]; - }; - in - { - expr = os.mkSuites { inherit profiles users userProfiles suites; }; - expected = { - system = { - bar = [ profiles.foo.default ]; - allProfiles = [ profiles.foo.default profiles.t.default ]; - allUsers = [ ]; - }; + testSuites = { + expr = os.mkSuites { + suites = { profiles, ... }: with profiles; { + bar = [ foo ]; }; + profiles = [ (./profiles) ]; }; + expected = { + bar = [ (toString ./profiles/foo) ]; + allProfiles = [ + (toString ./profiles/foo) + (toString ./profiles/t) + ]; + }; + }; } From ffe4836e35e8b4a1ef2d99292c1ea4a3df6ad821 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 18:29:05 -0700 Subject: [PATCH 079/137] update doc to match new template format and logic --- doc/concepts/extern.md | 47 ++++++++++++++++++--------------------- doc/concepts/hosts.md | 38 ++++++++++++++++++------------- doc/concepts/overrides.md | 42 ++++++++++++++-------------------- doc/concepts/suites.md | 8 ++++++- doc/outputs/overlays.md | 2 +- doc/start/from-nixos.md | 12 ++++++++-- doc/tests.md | 2 +- 7 files changed, 80 insertions(+), 71 deletions(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index 3b26912..171d8c5 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -1,45 +1,42 @@ # External Art When you need to use a module, overlay, or pass a value from one of your inputs -to the rest of your NixOS configuration, [extern][extern] is where you do it. +to the rest of your NixOS configuration, you can make use of a couple arguments. +It is encouraged to add external art directly in your `flake.nix` so the file +represents a complete dependency overview of your flake. -Modules and overlays are self explanatory, and the `specialArgs` attribute is -used to extend the arguments passed to all NixOS modules, allowing for -arbitrary values to be passed from flake inputs to the rest of your -configuration. +## Overlays +External overlays can directly be added to a channel's `overlays` list. -## Home Manager -There is also an `hmModules` attribute set for pulling home-manager modules in -from the outside world: - -### Declare: flake.nix: ```nix { - inputs.doom-emacs.url = "github:vlaci/nix-doom-emacs"; + channels.nixos.overlays = [ inputs.agenix.overlay ]; } ``` +These overlays will be automatically filtered by inspecting the `inputs` argument. -extern/default.nix: +## Modules +There is a dedicated `nixos.hostDefaults.externalModules` argument for external +modules. + +flake.nix: ```nix -with inputs; { - hmModules = { - doom-emacs = doom-emacs.hmModule; - }; + nixos.hostDefaults.externalModules = [ inputs.agenix.nixosModules.age ]; } ``` -### Use: -users/nixos/default.nix: +## Home Manager +Since there isn't a `hosts` concept for home-manager, externalModules is just a +top-level argument in the `home` namespace. + +flake.nix: ```nix -{ hmModules, ... }: { - home-manager.users.nixos = { - imports = [ hmModules.doom-emacs ] ; - - programs.doom-emacs.enable = true; - }; + home.externalModules = [ doom-emacs = doom-emacs.hmModule ]; } ``` -[extern]: https://github.com/divnix/devos/tree/core/extern/default.nix +> ##### Note: +> The optimal solution would be to automatically export modules that were created in +> your flake. But this is not possible due to NixOS/nix#4740. diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index 0a74dd1..770fa51 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -1,19 +1,18 @@ # Hosts Nix flakes contain an output called `nixosConfigurations` declaring an -attribute set of valid NixOS systems. To simplify the management and creation -of these hosts, devos automatically imports every _.nix_ file inside this -directory to the mentioned attribute set, applying the projects defaults to -each. The only hard requirement is that the file contain a valid NixOS module. +attribute set of valid NixOS systems. To create hosts, you can use the +`nixos.hosts` argument and pass `modules` to each host. Host-specific modules +typically go in the `hosts` folder of the template. -As an example, a file `hosts/system.nix` will be available via the flake -output `nixosConfigurations.system`. You can have as many hosts as you want -and all of them will be automatically imported based on their name. +Each host should follow a certain channel to define the `pkgs` of that host. +You can use the `nixos.hostDefaults` to set defaults and global modules for all +hosts. For each host, the configuration automatically sets the `networking.hostName` -attribute to the name of the file minus the _.nix_ extension. This is for -convenience, since `nixos-rebuild` automatically searches for a configuration -matching the current systems hostname if one is not specified explicitly. +attribute to the name of the host. This is for convenience, since `nixos-rebuild` +automatically searches for a configuration matching the current systems hostname +if one is not specified explicitly. It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines @@ -22,12 +21,8 @@ is best saved for [profile modules](./profiles.md). This is a good place to import sets of profiles, called [suites](./suites.md), that you intend to use on your machine. -Additionally, this is the perfect place to import anything you might need from -the [nixos-hardware][nixos-hardware] repository. - -> ##### _Note:_ -> Set `nixpkgs.system` to the architecture of this host, default is "x86_64-linux". -> Keep in mind that not all packages are available for all architectures. +Additionally, you can pass modules from [nixos-hardware][nixos-hardware] in the +`modules` argument for relevant hosts. ## Example @@ -44,4 +39,15 @@ hosts/librem.nix: } ``` +flake.nix +```nix +{ + nixos.hosts.librem = { + system = "aarch64-linux"; + modules = ./hosts/librem.nix; + }; +} +``` + + [nixos-hardware]: https://github.com/NixOS/nixos-hardware diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 28194cd..78b50fd 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -1,47 +1,39 @@ # Overrides -By default, the NixOS systems are based on unstable. While it is trivial to -change this to a stable release, or any other branch of nixpkgs by -changing the flake url, sometimes all we want is a single package from another -branch. +Each NixOS host follows one channel. But many times it is useful to get packages +or modules from different channels. -This is what the overrides are for. By default, they are pulled directly from -nixpkgs/master, but you can change the `override` flake input url to -nixos-unstable, or even a specific sha revision. - -They are defined in the `extern/overrides.nix` file. +This is what the overrides are for. You can make use of the `overrides.nix` to +override specific packages to be pulled from other channels. Any overlay may get +`channels` as their first argument. ## Example ### Packages The override packages are defined as a regular overlay with an extra arguement -`pkgs`. This refers to the packages built from the `override` flake. +`channels`. This refers to all channels defined in `flake.nix`. -Pulling the manix package from the override flake: +Pulling the manix package from the latest flake: ```nix -{ - packages = pkgs: final: prev: { - inherit (pkgs) manix; - }; +channels: final: prev: { + inherit (pkgs.latest) manix; } ``` ### Modules -You can also pull modules from override. Simply specify their path relative to -the nixpkgs [modules][nixpkgs-modules] directory. The old version will be added -to `disabledModules` and the new version imported into the configuration. +You can also pull modules from other channels. All modules have access to the +`modulesPath` for each channel as `ModulesPath`. And you can use +`disabledModules` to remove modules from the current channel. -Pulling the zsh module from the override flake: +Pulling the zsh module from the latest flake: ```nix -{ - modules = [ "programs/zsh/zsh.nix" ]; +{ latestModulesPath }: { + modules = [ "${latestModulesPath}/programs/zsh/zsh.nix" ]; + disabledModules = [ "programs/zsh/zsh.nix" ]; } ``` > ##### _Note:_ -> Sometimes a modules name will change from one branch to another. This is what -> the `disabledModules` list is for. If the module name changes, the old -> version will not automatically be disabled, so simply put it's old name in -> this list to disable it. +> Sometimes a modules name will change from one branch to another. [nixpkgs-modules]: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules diff --git a/doc/concepts/suites.md b/doc/concepts/suites.md index e6a8bff..5c0d590 100644 --- a/doc/concepts/suites.md +++ b/doc/concepts/suites.md @@ -6,7 +6,13 @@ profiles. For good examples, check out the suites defined in the community In the future, we will use suites as a mechanism for deploying various machine types which don't depend on hardware, such as vm's and containers. -They are defined in `profiles/suites.nix`. +They are defined with the `suites` argument in either `home` or `nixos` namespace. +Suites should be passed as a function that take profiles as an argument. + +The profiles are passed based on the folder names and list passed to the relevant +`profiles` argument. In the template's flake.nix `profiles` is set as +`[ ./profiles ./users ]` and that corresponds to the `{ profiles, users }` argument +pattern. ## Definition ```nix diff --git a/doc/outputs/overlays.md b/doc/outputs/overlays.md index d71b459..f463d1a 100644 --- a/doc/outputs/overlays.md +++ b/doc/outputs/overlays.md @@ -4,7 +4,7 @@ we want to keep the process as simple and straightforward as possible. Any _.nix_ files declared in this directory will be assumed to be a valid overlay, and will be automatically imported into all [hosts](../concepts/hosts.md), and -exported via `overlays.` _as well as_ +exported via `overlays./` _as well as_ `packages..` (for valid systems), so all you have to do is write it. diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index bbb0e55..9b0b3f5 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -10,10 +10,18 @@ flk up This will make a new file `hosts/up-$(hostname).nix`, which you can edit to your liking. +You must then add a host to `nixos.hosts` in flake.nix: +```nix +{ + nixos.hosts = { + modules = hosts/NixOS.nix; + }; +} +``` + Make sure your `i18n.defaultLocale` and `time.timeZone` are set properly for your region. Keep in mind that `networking.hostName` with be automatically -set to the filename of your hosts file, so `hosts/my-host.nix` will have the -hostname `my-host`. +set to the name of your host; Now might be a good time to read the docs on [suites](../concepts/suites.md) and [profiles](../concepts/profiles.md) and add or create any that you need. diff --git a/doc/tests.md b/doc/tests.md index 033d75a..f6fd7fe 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -7,7 +7,7 @@ configuration, and, optionally, run them in ## Lib Tests You can easily write tests for your own library functions in the -___tests/lib.nix___ file and they will be run on every `nix flake check` or +lib/___tests/lib.nix___ file and they will be run on every `nix flake check` or during a CI run. ## Unit Tests From a6344faa9afd17efb8b2069c2332ac302d98944e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:30:55 -0700 Subject: [PATCH 080/137] update fup to fix infinite recursion error --- flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 90ffa98..13482c4 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-MvrBYZG6sZqpa8mTg4RYeD9aezYbVppBnslRyH7qZys=", + "narHash": "sha256-clwJnNLVOASak2CfkWu3Yztb1uWwtndY4VLDWEa9R3s=", "path": "./lib", "type": "path" }, @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619438935, - "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "lastModified": 1619480667, + "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", + "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index 6942e2a..eda785b 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619438935, - "narHash": "sha256-B8OGqX9QBMW5G8DYTRdY0cb62ETaV0YxBayCZMiaVqQ=", + "lastModified": 1619480667, + "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "80b53eeda3102bb5aed31ec818c6485e35caffc3", + "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", "type": "github" }, "original": { From b6c00e74e7c6e574ee72d40141a36adff2ebeccc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:33:31 -0700 Subject: [PATCH 081/137] set add self and hosts module arguments --- lib/modules.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/modules.nix b/lib/modules.nix index 2cd965f..6e2a352 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -41,6 +41,12 @@ } ''; + _module.args = { + inherit self; + hosts = builtins.mapAttrs (_: host: host.config) + (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); + }; + system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; From e9675330a7b3717cf6abf090a34b5bf1ac23201a Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 19:34:18 -0700 Subject: [PATCH 082/137] add cachix to base suite to follow the new api --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 1e23ced..aca677b 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,7 @@ }; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { - base = [ core users.nixos users.root ]; + base = [ cachix core users.nixos users.root ]; }; }; From 278ae0e108633b70214d1176ed38883910f46e68 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:32:26 -0700 Subject: [PATCH 083/137] set _module.check in evalArgs instead of mkFlake this makes more sense since evalArgs is the module and it makes the code cleaner --- lib/mkFlake/default.nix | 2 +- lib/mkFlake/evalArgs.nix | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index cd8d037..45d99bd 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -8,7 +8,7 @@ _: { self, inputs, ... } @ args: let config = lib.mkFlake.evalArgs { - args = lib.mkMerge [ args { _module.check = false; } ]; + inherit args; }; cfg = config.config; diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 5884dcf..1a15dc8 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -187,6 +187,10 @@ let }; in { + # this does not get propagated to submodules + # to allow passing flake outputs directly to mkFlake + config._module.check = false; + options = with types; { self = mkOption { type = flakeType; From c41d3eed0662956c4ad3afd958ebea0be29fcd89 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:32:57 -0700 Subject: [PATCH 084/137] drop debugging related mkFlakeConfig output was only meant for debugging, not meant to be commited --- lib/mkFlake/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 45d99bd..bcab7a1 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -33,8 +33,6 @@ lib.systemFlake (lib.recursiveUpdate inherit self inputs; inherit (cfg) channelsConfig supportedSystems; - mkFlakeConfig = config; - channels = mapAttrs (name: channel: channel // { From 064ba88cdf6ce391cdbe3e4df72363276dbb5ebd Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 26 Apr 2021 21:38:27 -0700 Subject: [PATCH 085/137] improve, build, and add mkFlake options doc --- doc/mkFlakeOptions.md | 407 +++++++++++++++++++++++++++++++++++++++ lib/mkFlake/evalArgs.nix | 25 ++- 2 files changed, 425 insertions(+), 7 deletions(-) create mode 100644 doc/mkFlakeOptions.md diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md new file mode 100644 index 0000000..42b1f60 --- /dev/null +++ b/doc/mkFlakeOptions.md @@ -0,0 +1,407 @@ +## channels +nixpkgs channels to create + + +*_Type_*: +attribute set of submodules + + +*_Default_* +``` +{} +``` + + + + +## channels.\.config +nixpkgs config for this channel + + +*_Type_*: +attribute set or path convertible to it + + +*_Default_* +``` +{} +``` + + + + +## channels.\.input +nixpkgs flake input to use for this channel + + +*_Type_*: +nix flake + + +*_Default_* +``` +"inputs.\\" +``` + + + + +## channels.\.overlays +overlays to apply to this channel +these will get exported under the 'overlays' flake output +as \/\ and any overlay pulled from ${inputs} +will be filtered out + + +*_Type_*: +list of valid Nixpkgs overlay or path convertible to its or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## channelsConfig +nixpkgs config for all channels + + +*_Type_*: +attribute set or path convertible to it + + +*_Default_* +``` +{} +``` + + + + +## home +hosts, modules, suites, and profiles for home-manager + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## home.externalModules +modules to include that won't be exported +meant importing modules from external flakes + + +*_Type_*: +list of valid module or path convertible to its + + +*_Default_* +``` +[] +``` + + + + +## home.modules +modules to include in all hosts and export to homeModules output + + +*_Type_*: +list of paths or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## home.profiles +profile folders that can be collected into suites +the name of the argument passed to suites is based +on the folder name. +[ ./profiles ] => { profiles }: + + +*_Type_*: +list of paths + + +*_Default_* +``` +[] +``` + + + + +## home.suites +Function that takes profiles and returns suites for this config system +These can be accessed through the 'suites' special argument. + + +*_Type_*: +function that evaluates to a(n) attrs or path convertible to it + + +*_Default_* +``` +"" +``` + + + + +## inputs +inputs for this flake +used to set channel defaults and create registry + + +*_Type_*: +attribute set of nix flakes + + + + + + +## nixos +hosts, modules, suites, and profiles for nixos + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## nixos.hostDefaults +Defaults for all hosts. +the modules passed under hostDefaults will be exported +to the 'nixosModules' flake output. +They will also be added to all hosts. + + +*_Type_*: +submodule + + +*_Default_* +``` +{} +``` + + + + +## nixos.hostDefaults.channelName +Channel this host should follow + + +*_Type_*: +a channel defined in `channels` + + +*_Default_* +``` +null +``` + + + + +## nixos.hostDefaults.externalModules +modules to include that won't be exported +meant importing modules from external flakes + + +*_Type_*: +list of valid module or path convertible to its + + +*_Default_* +``` +[] +``` + + + + +## nixos.hostDefaults.modules +modules to include in all hosts and export to nixosModules output + + +*_Type_*: +list of paths or path convertible to it + + +*_Default_* +``` +[] +``` + + + + +## nixos.hostDefaults.system +system for this host + + +*_Type_*: +system defined in `supportedSystems` + + +*_Default_* +``` +null +``` + + + + +## nixos.hosts +configurations to include in the nixosConfigurations output + + +*_Type_*: +attribute set of submodules + + +*_Default_* +``` +{} +``` + + + + +## nixos.hosts.\.channelName +Channel this host should follow + + +*_Type_*: +a channel defined in `channels` + + +*_Default_* +``` +null +``` + + + + +## nixos.hosts.\.modules +modules to include + + +*_Type_*: +list of valid module or path convertible to its or valid module or path convertible to it convertible to it + + +*_Default_* +``` +[] +``` + + + + +## nixos.hosts.\.system +system for this host + + +*_Type_*: +system defined in `supportedSystems` + + +*_Default_* +``` +null +``` + + + + +## nixos.profiles +profile folders that can be collected into suites +the name of the argument passed to suites is based +on the folder name. +[ ./profiles ] => { profiles }: + + +*_Type_*: +list of paths + + +*_Default_* +``` +[] +``` + + + + +## nixos.suites +Function that takes profiles and returns suites for this config system +These can be accessed through the 'suites' special argument. + + +*_Type_*: +function that evaluates to a(n) attrs or path convertible to it + + +*_Default_* +``` +"" +``` + + + + +## self +The flake to create the devos outputs for + +*_Type_*: +nix flake + + + + + + +## supportedSystems +The systems supported by this flake + + +*_Type_*: +list of strings + + +*_Default_* +``` +["aarch64-linux","i686-linux","x86_64-darwin","x86_64-linux"] +``` + + + diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 1a15dc8..55b3795 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -56,7 +56,9 @@ let default = [ ]; description = escape [ "<" ">" ] '' overlays to apply to this channel - these will get exported under the 'overlays' flake output as / + these will get exported under the 'overlays' flake output + as / and any overlay pulled from ''\${inputs} + will be filtered out ''; }; config = mkOption { @@ -74,14 +76,18 @@ let options = with types; { # anything null in hosts gets filtered out by mkFlake system = mkOption { - type = nullOr systemType; + type = (nullOr systemType) // { + description = "system defined in `supportedSystems`"; + }; default = null; description = '' system for this host ''; }; channelName = mkOption { - type = nullOr (types.enum (builtins.attrNames config.channels)); + type = (nullOr (types.enum (builtins.attrNames config.channels))) // { + description = "a channel defined in `channels`"; + }; default = null; description = '' Channel this host should follow @@ -98,7 +104,8 @@ let type = with types; listOf moduleType; default = [ ]; description = '' - The configuration for this host + modules to include that won't be exported + meant importing modules from external flakes ''; }; }; @@ -168,7 +175,12 @@ let profiles = mkOption { type = listOf path; default = [ ]; - description = "path to profiles folder that can be collected into suites"; + description = '' + profile folders that can be collected into suites + the name of the argument passed to suites is based + on the folder name. + [ ./profiles ] => { profiles }: + ''; }; suites = mkOption { type = pathTo (functionTo attrs); @@ -178,8 +190,7 @@ let inherit (config) profiles; }; description = '' - Function with the input of 'profiles' that returns an attribute set - with the suites for this config system. + Function that takes profiles and returns suites for this config system These can be accessed through the 'suites' special argument. ''; }; From 466304c8cd6d45a62b0e0c82638ce13fc9badaa7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 08:01:46 -0700 Subject: [PATCH 086/137] improve passing host and channel arguments to fup we need to filter out arguments that are added in the devos api also anything thats null in either hostDefaults and hosts has to be removed --- flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- lib/mkFlake/default.nix | 32 ++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/flake.lock b/flake.lock index 13482c4..6d239fa 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-clwJnNLVOASak2CfkWu3Yztb1uWwtndY4VLDWEa9R3s=", + "narHash": "sha256-TOrVXGFk5rt1Wn14ja2spg44NuZnFM/V6qguQfO+8Kc=", "path": "./lib", "type": "path" }, @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619480667, - "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", + "lastModified": 1619532520, + "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", + "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index eda785b..ebf5e6d 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619480667, - "narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=", + "lastModified": 1619532520, + "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c", + "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", "type": "github" }, "original": { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index bcab7a1..7b12cf4 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -25,35 +25,39 @@ let }) ]; + stripChannel = channel: removeAttrs channel [ + # arguments in our channels api that shouldn't be passed to fup + "overlays" + ]; getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; + + # 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) [ + # arguments in our hosts/hostDefaults api that shouldn't be passed to fup + "externalModules" + ]; + hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; + hostDefaults = stripHost cfg.nixos.hostDefaults; in lib.systemFlake (lib.recursiveUpdate otherArguments { - inherit self inputs; + inherit self inputs hosts; inherit (cfg) channelsConfig supportedSystems; channels = mapAttrs (name: channel: - channel // { + stripChannel (channel // { # pass channels if "overlay" has three arguments overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; - } + }) ) cfg.channels; - # the host arguments cannot exist for fup hostDefaults to work - # so evalArgs sets them to null by default and the null args are filtered out here - hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts; - - hostDefaults = { + hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; - modules = cfg.nixos.hostDefaults.modules - ++ cfg.nixos.hostDefaults.externalModules - ++ defaultModules; + modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; builder = os.devosSystem { inherit self inputs; }; - inherit (cfg.nixos.hostDefaults) - channelName - system; }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; From 7f3116c1ccb2aa4f6375fa4b45c9863a62656d4f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:30:28 -0700 Subject: [PATCH 087/137] safeReadDir: conver path to string for reliability --- lib/attrs.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/attrs.nix b/lib/attrs.nix index 1ecc254..d1bc764 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -41,5 +41,6 @@ rec { in lib.filterAttrs filter packages; - safeReadDir = path: lib.optionalAttrs (builtins.pathExists path) (builtins.readDir path); + safeReadDir = path: + lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); } From f57840d723785bc22ad93f0ba17725a620ee9481 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:32:12 -0700 Subject: [PATCH 088/137] mkFlake/default.nix: formatting --- lib/mkFlake/default.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 7b12cf4..bf571ec 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -52,7 +52,8 @@ lib.systemFlake (lib.recursiveUpdate # pass channels if "overlay" has three arguments overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; }) - ) cfg.channels; + ) + cfg.channels; hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; @@ -68,10 +69,9 @@ lib.systemFlake (lib.recursiveUpdate deploy.nodes = os.mkNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { - /* since we can't detect overlays owned by self - we have to filter out ones exported by the inputs - optimally we would want a solution for NixOS/nix#4740 - */ + # since we can't detect overlays owned by self + # we have to filter out ones exported by the inputs + # optimally we would want a solution for NixOS/nix#4740 inherit inputs; inherit (self) pkgs; }; From e67b49c2804902b7b4a3c3e74a59aa1667663f1e Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:35:44 -0700 Subject: [PATCH 089/137] auto-flatten coercedListOf and type fixes --- flake.nix | 2 +- lib/mkFlake/evalArgs.nix | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index aca677b..c2a87ad 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ channels = { nixos = { - overlays = nixos.lib.flatten [ + overlays = [ (devos.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index 55b3795..fe49bc3 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -21,6 +21,12 @@ let inherit (submodule { }) check; description = "valid module"; }); + + # to export modules we need paths to get the name + exportModuleType = with types; + (addCheck path (x: moduleType.check (import x))) // { + description = "path to a module"; + }; overlayType = pathTo (types.anything // { check = builtins.isFunction; description = "valid Nixpkgs overlay"; @@ -37,7 +43,7 @@ let pathToListOf = elemType: with types; pathTo (listOf elemType); coercedListOf = elemType: with types; - coercedTo elemType (x: flatten (singleton x)) (listOf elemType); + coercedTo anything (x: flatten (singleton x)) (listOf elemType); /* Submodules needed for API containers */ @@ -52,7 +58,7 @@ let ''; }; overlays = mkOption { - type = pathToListOf overlayType; + type = coercedListOf overlayType; default = [ ]; description = escape [ "<" ">" ] '' overlays to apply to this channel @@ -126,10 +132,7 @@ let exportModulesModule = name: { options = { modules = mkOption { - type = with types; pathToListOf - # check if the path evaluates to a proper module - # but this must be a path for the export to work - (addCheck path (x: moduleType.check (import x))); + type = with types; pathTo (coercedListOf exportModuleType); default = [ ]; description = '' modules to include in all hosts and export to ${name}Modules output From d5276195f77d1a821454a267bd8b774a8cf896b3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:38:20 -0700 Subject: [PATCH 090/137] move overrides.nix to overlays also update overrides docs it is a pure devos overlay now, it makes sense to go in overlays --- doc/concepts/overrides.md | 19 ++++++++----------- flake.nix | 1 - overrides.nix => overlays/overrides.nix | 0 3 files changed, 8 insertions(+), 12 deletions(-) rename overrides.nix => overlays/overrides.nix (100%) diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 78b50fd..0eb1002 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -2,30 +2,27 @@ Each NixOS host follows one channel. But many times it is useful to get packages or modules from different channels. -This is what the overrides are for. You can make use of the `overrides.nix` to -override specific packages to be pulled from other channels. Any overlay may get -`channels` as their first argument. +## Packages +You can make use of `overlays/overrides.nix` to override specific packages in the +default channel to be pulled from other channels. That file is simply an example +of how any overlay can get `channels` as their first argument. -## Example +You can add overlays to any channel to override packages from other channels. -### Packages -The override packages are defined as a regular overlay with an extra arguement -`channels`. This refers to all channels defined in `flake.nix`. - -Pulling the manix package from the latest flake: +Pulling the manix package from the `latest` channel: ```nix channels: final: prev: { inherit (pkgs.latest) manix; } ``` -### Modules +## Modules You can also pull modules from other channels. All modules have access to the `modulesPath` for each channel as `ModulesPath`. And you can use `disabledModules` to remove modules from the current channel. -Pulling the zsh module from the latest flake: +Pulling the zsh module from the `latest` channel: ```nix { latestModulesPath }: { modules = [ "${latestModulesPath}/programs/zsh/zsh.nix" ]; diff --git a/flake.nix b/flake.nix index c2a87ad..5468f5a 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,6 @@ (devos.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` - ./overrides.nix # from "latest" channel nur.overlay ]; }; diff --git a/overrides.nix b/overlays/overrides.nix similarity index 100% rename from overrides.nix rename to overlays/overrides.nix From a7cd35e433c566c5961db1a0b35a775b0dd3d73f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:47:31 -0700 Subject: [PATCH 091/137] update lib subflake lock --- flake.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index 6d239fa..7841db5 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-TOrVXGFk5rt1Wn14ja2spg44NuZnFM/V6qguQfO+8Kc=", + "narHash": "sha256-r+OPJF65PToVQK1ll2INAYmIV3zmnDzWBpGLx8m4aVo=", "path": "./lib", "type": "path" }, From df39cb692e7df07a8b7f6531303620888eadeca3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 09:52:56 -0700 Subject: [PATCH 092/137] rebuild and update mkFlakeOptions.md --- doc/mkFlakeOptions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md index 42b1f60..9b0e726 100644 --- a/doc/mkFlakeOptions.md +++ b/doc/mkFlakeOptions.md @@ -54,7 +54,7 @@ will be filtered out *_Type_*: -list of valid Nixpkgs overlay or path convertible to its or path convertible to it +list of valid Nixpkgs overlay or path convertible to its or anything convertible to it *_Default_* @@ -119,7 +119,7 @@ modules to include in all hosts and export to homeModules output *_Type_*: -list of paths or path convertible to it +list of path to a modules or anything convertible to it or path convertible to it *_Default_* @@ -252,7 +252,7 @@ modules to include in all hosts and export to nixosModules output *_Type_*: -list of paths or path convertible to it +list of path to a modules or anything convertible to it or path convertible to it *_Default_* @@ -316,7 +316,7 @@ modules to include *_Type_*: -list of valid module or path convertible to its or valid module or path convertible to it convertible to it +list of valid module or path convertible to its or anything convertible to it *_Default_* From aa825b87a6a16a8a663e14f52155bc924d28bad1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 10:26:45 -0700 Subject: [PATCH 093/137] auto import hosts in flake.nix this allows host-specific settings to be overriden with mkMerge --- doc/concepts/hosts.md | 56 ++++++++++++++++++++++++------------------- flake.lock | 2 +- flake.nix | 9 ++++--- lib/attrs.nix | 8 +++++++ lib/flake.nix | 5 ++-- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index 770fa51..1fa9028 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -1,18 +1,24 @@ # Hosts Nix flakes contain an output called `nixosConfigurations` declaring an -attribute set of valid NixOS systems. To create hosts, you can use the -`nixos.hosts` argument and pass `modules` to each host. Host-specific modules -typically go in the `hosts` folder of the template. +attribute set of valid NixOS systems. To simplify the management and creation +of these hosts, devos automatically imports every _.nix_ file inside this +directory to the mentioned attribute set, applying the projects defaults to +each. The only hard requirement is that the file contain a valid NixOS module. -Each host should follow a certain channel to define the `pkgs` of that host. -You can use the `nixos.hostDefaults` to set defaults and global modules for all -hosts. +As an example, a file `hosts/system.nix` will be available via the flake +output `nixosConfigurations.system`. You can have as many hosts as you want +and all of them will be automatically imported based on their name. For each host, the configuration automatically sets the `networking.hostName` -attribute to the name of the host. This is for convenience, since `nixos-rebuild` -automatically searches for a configuration matching the current systems hostname -if one is not specified explicitly. +attribute to the name of the file minus the _.nix_ extension. This is for +convenience, since `nixos-rebuild` automatically searches for a configuration +matching the current systems hostname if one is not specified explicitly. + +You can set channels, systems, and add extra modules to each host by editing the +`nixos.hosts` argument in flake.nix. This is the perfect place to import +host specific modules from external sources, such as the +[nixos-hardware][nixos-hardware] repository. It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines @@ -21,16 +27,29 @@ is best saved for [profile modules](./profiles.md). This is a good place to import sets of profiles, called [suites](./suites.md), that you intend to use on your machine. -Additionally, you can pass modules from [nixos-hardware][nixos-hardware] in the -`modules` argument for relevant hosts. ## Example +flake.nix: +```nix +{ + nixos.hosts = mkMerge [ + (devos.lib.importHosts ./hosts) + { + librem = { + channelName = "latest"; + modules = [ hardware.purism-librem-13v3 ]; + }; + } + ]; +} +``` + hosts/librem.nix: ```nix -{ suites, hardware, ... }: +{ suites, ... }: { - imports = suites.laptop ++ [ hardware.purism-librem-13v3 ]; + imports = suites.laptop; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -39,15 +58,4 @@ hosts/librem.nix: } ``` -flake.nix -```nix -{ - nixos.hosts.librem = { - system = "aarch64-linux"; - modules = ./hosts/librem.nix; - }; -} -``` - - [nixos-hardware]: https://github.com/NixOS/nixos-hardware diff --git a/flake.lock b/flake.lock index 7841db5..91c20fd 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-r+OPJF65PToVQK1ll2INAYmIV3zmnDzWBpGLx8m4aVo=", + "narHash": "sha256-hpvEXcpq85cDKi0F5UUsuMVISKlk8hgVJiz5FF29RwA=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 5468f5a..d30cc3a 100644 --- a/flake.nix +++ b/flake.nix @@ -61,11 +61,10 @@ home.nixosModules.home-manager ]; }; - hosts = { - NixOS = { - modules = ./hosts/NixOS.nix; - }; - }; + hosts = nixos.lib.mkMerge [ + (devos.lib.importHosts ./hosts) + { /* set host specific properties here */ } + ]; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { base = [ cachix core users.nixos users.root ]; diff --git a/lib/attrs.nix b/lib/attrs.nix index d1bc764..93f7958 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -30,6 +30,14 @@ rec { value = import path; }); + importHosts = dir: + lib.os.recImport { + inherit dir; + _import = base: { + modules = import "${toString dir}/${base}.nix"; + }; + }; + concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; # Filter out packages that support given system and follow flake check requirements diff --git a/lib/flake.nix b/lib/flake.nix index 17e069c..2513311 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -48,7 +48,8 @@ safeReadDir pathsToImportedAttrs concatAttrs - filterPackages; + filterPackages + importHosts; inherit (lists) pathsIn collectProfiles unifyOverlays; inherit (strings) rgxToString; inherit modules; @@ -60,7 +61,7 @@ { lib = utils.lib // { inherit (lib) - mkFlake pathsIn; + mkFlake pathsIn importHosts; }; } From bb9bc02478a197b28faaac35fa97e9d21fabb16a Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 12:52:16 -0700 Subject: [PATCH 094/137] fix channels.*.input defaultText formatting --- doc/mkFlakeOptions.md | 2 +- lib/mkFlake/evalArgs.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/mkFlakeOptions.md b/doc/mkFlakeOptions.md index 9b0e726..90719ba 100644 --- a/doc/mkFlakeOptions.md +++ b/doc/mkFlakeOptions.md @@ -40,7 +40,7 @@ nix flake *_Default_* ``` -"inputs.\\" +"inputs." ``` diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index fe49bc3..ee42e22 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -52,7 +52,7 @@ let input = mkOption { type = flakeType; default = cfg.inputs.${name}; - defaultText = escape [ "<" ">" ] "inputs."; + defaultText = "inputs."; description = '' nixpkgs flake input to use for this channel ''; From 5bc88ad2c21d1872ccb15eddb7da6945824ceccc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 16:36:07 -0700 Subject: [PATCH 095/137] don't use lockfile to get flake-compat lock file format isn't very reliable with naming inputs --- flake.nix | 2 -- lib/compat/default.nix | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index d30cc3a..1b469f4 100644 --- a/flake.nix +++ b/flake.nix @@ -21,8 +21,6 @@ }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "latest"; - flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; - flake-compat.flake = false; home.url = "github:nix-community/home-manager"; home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; diff --git a/lib/compat/default.nix b/lib/compat/default.nix index 0a63b0b..9d0c283 100644 --- a/lib/compat/default.nix +++ b/lib/compat/default.nix @@ -1,12 +1,10 @@ let - inherit (lock.nodes.flake-compat.locked) rev narHash; - - lock = builtins.fromJSON (builtins.readFile "${../..}/flake.lock"); + rev = "e7e5d481a0e15dcd459396e55327749989e04ce0"; flake = (import ( fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; - sha256 = narHash; + sha256 = "0zd3x46fswh5n6faq4x2kkpy6p3c6j593xbdlbsl40ppkclwc80x"; } ) { From a5dcb5fae9d6afbc75488b4c5136aa599868574b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 27 Apr 2021 18:41:51 -0700 Subject: [PATCH 096/137] fix flake by removing flake-compat follows --- flake.lock | 30 +++++++++++++----------------- flake.nix | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 91c20fd..f7770ee 100644 --- a/flake.lock +++ b/flake.lock @@ -2,9 +2,7 @@ "nodes": { "ci-agent": { "inputs": { - "flake-compat": [ - "flake-compat" - ], + "flake-compat": "flake-compat", "nix-darwin": [ "darwin" ], @@ -17,11 +15,11 @@ "pre-commit-hooks-nix": "pre-commit-hooks-nix" }, "locked": { - "lastModified": 1615131736, - "narHash": "sha256-z4Er9Cj3WpBDO/saLxqb7IypEvVP0/1AnO6rY5NB03Y=", + "lastModified": 1619088868, + "narHash": "sha256-l9db+HpNIkY41MonGE8z4pbkjBa5BdzJTG5AxV7V7Lw=", "owner": "hercules-ci", "repo": "hercules-ci-agent", - "rev": "a1513a51e8efb96e990a562e6e724e17f2789978", + "rev": "08f953a263518a3af0ca28cd887020ff3465bdf5", "type": "github" }, "original": { @@ -52,7 +50,7 @@ }, "deploy": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_2", "naersk": "naersk", "nixpkgs": "nixpkgs", "utils": "utils" @@ -124,16 +122,15 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1611461076, - "narHash": "sha256-ad++dTtMNeitUIKi1c66aTrVJOSf+mdZTrGrXzjDr6Q=", - "owner": "BBBSnowball", + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", "repo": "flake-compat", - "rev": "a565cb46bee9fa856a6c15bc9c3bb947fbb784ec", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", "type": "github" }, "original": { - "owner": "BBBSnowball", - "ref": "pr-1", + "owner": "edolstra", "repo": "flake-compat", "type": "github" } @@ -307,11 +304,11 @@ "pre-commit-hooks-nix": { "flake": false, "locked": { - "lastModified": 1603721622, - "narHash": "sha256-tUgyf5eYK5+0A/dvLzbbm4W7icxbpORuFMXiFe5yz+I=", + "lastModified": 1617783930, + "narHash": "sha256-SigoU2LWM1fMggqfM9H8XEIvjOjBVQ/wj/zrn02J28c=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "efdbd6d28f7f44db3d9f8cf0e0b4cb9db0d259e1", + "rev": "2d169bb1b23f3b71a894a66ea81f45c788943248", "type": "github" }, "original": { @@ -325,7 +322,6 @@ "ci-agent": "ci-agent", "darwin": "darwin", "devos": "devos", - "flake-compat": "flake-compat_2", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index 1b469f4..386bd32 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; - inputs = { nix-darwin.follows = "darwin"; flake-compat.follows = "flake-compat"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "latest"; }; + inputs = { nix-darwin.follows = "darwin"; nixos-20_09.follows = "nixos"; nixos-unstable.follows = "latest"; }; }; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "latest"; From 23ee58d2d0a26124ec16f54653e58f485c167e01 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 29 Apr 2021 11:53:45 -0700 Subject: [PATCH 097/137] use __dontExport property for lib and overrides --- doc/concepts/overrides.md | 5 +++++ flake.lock | 8 ++++---- lib/flake.lock | 6 +++--- lib/mkFlake/default.nix | 8 +++++++- overlays/overrides.nix | 2 ++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/doc/concepts/overrides.md b/doc/concepts/overrides.md index 0eb1002..303108c 100644 --- a/doc/concepts/overrides.md +++ b/doc/concepts/overrides.md @@ -12,10 +12,15 @@ You can add overlays to any channel to override packages from other channels. Pulling the manix package from the `latest` channel: ```nix channels: final: prev: { + __dontExport = true; inherit (pkgs.latest) manix; } ``` +It is recommended to set the `__dontExport` property for override specific +overlays. `overlays/overrides.nix` is the best place to consolidate all package +overrides and the property is already set for you. + ## Modules You can also pull modules from other channels. All modules have access to the diff --git a/flake.lock b/flake.lock index f7770ee..27fecfb 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-hpvEXcpq85cDKi0F5UUsuMVISKlk8hgVJiz5FF29RwA=", + "narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", "path": "./lib", "type": "path" }, @@ -351,11 +351,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619532520, - "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", + "lastModified": 1619714004, + "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", + "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", "type": "github" }, "original": { diff --git a/lib/flake.lock b/lib/flake.lock index ebf5e6d..8156254 100644 --- a/lib/flake.lock +++ b/lib/flake.lock @@ -146,11 +146,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619532520, - "narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=", + "lastModified": 1619714004, + "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1", + "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", "type": "github" }, "original": { diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index bf571ec..e5862d3 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -40,7 +40,7 @@ let hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; hostDefaults = stripHost cfg.nixos.hostDefaults; in -lib.systemFlake (lib.recursiveUpdate +lib.systemFlake (lib.mergeAny otherArguments { inherit self inputs hosts; @@ -55,6 +55,12 @@ lib.systemFlake (lib.recursiveUpdate ) cfg.channels; + sharedOverlays = [ + (final: prev: { + __dontExport = true; + devlib = lib; + }) + ]; hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; diff --git a/overlays/overrides.nix b/overlays/overrides.nix index bb3cf68..59516b3 100644 --- a/overlays/overrides.nix +++ b/overlays/overrides.nix @@ -1,5 +1,7 @@ channels: final: prev: { + __dontExport = true; # overrides clutter up actual creations + inherit (channels.latest) cachix dhall From e98e595704f2635f2b0fc9ffc999ae603ddaad24 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 28 Apr 2021 11:30:04 -0700 Subject: [PATCH 098/137] pass builderArgs to config and extract builds have mkHomeConfiguration create its own custom build within the function create a externalModule for customBuilds so its easy to add more --- flake.lock | 2 +- flake.nix | 1 + lib/devos/mkHomeConfigurations.nix | 7 ++++--- lib/mkFlake/default.nix | 5 ++++- lib/modules.nix | 14 +------------- lib/pkgs-lib/tests/default.nix | 6 ++---- modules/customBuilds.nix | 29 +++++++++++++++++++++++++++++ 7 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 modules/customBuilds.nix diff --git a/flake.lock b/flake.lock index 27fecfb..484e301 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", + "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 386bd32..41a83a9 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ externalModules = [ ci-agent.nixosModules.agent-profile home.nixosModules.home-manager + ./modules/customBuilds.nix ]; }; hosts = nixos.lib.mkMerge [ diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 3a07ba8..95affc2 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -4,9 +4,10 @@ nixosConfigurations: with lib; let - mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) - config.config.system.build.homes; + mkHomes = hostName: host: + mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home) + # So this function is useful for non-devos hosts + (host.config.system.build.homes or host.config.home-manager.users); hmConfigs = mapAttrs mkHomes nixosConfigurations; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index e5862d3..ed99db0 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -64,7 +64,10 @@ lib.systemFlake (lib.mergeAny hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; - builder = os.devosSystem { inherit self inputs; }; + builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { + # So modules and functions can create their own version of the build + modules = [ { lib.builderArgs = args; } ]; + }); }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; diff --git a/lib/modules.nix b/lib/modules.nix index 6e2a352..60e2971 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -43,6 +43,7 @@ _module.args = { inherit self; + devlib = lib; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); }; @@ -111,18 +112,5 @@ }; }; - hmConfig = - { config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }; } diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 854332f..e08702a 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -23,11 +23,9 @@ let nixosTesting = (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { inherit (pkgs) system; - inherit (host.config.lib) specialArgs; + inherit (host.config.lib.builderArgs) specialArgs; inherit pkgs; - extraConfigurations = [ - host.config.lib.testModule - ]; + extraConfigurations = host._module.args.modules; }); in test: diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix new file mode 100644 index 0000000..b9648dc --- /dev/null +++ b/modules/customBuilds.nix @@ -0,0 +1,29 @@ +{ lib, self, devlib, config, modules, channel, ... }: +let + mkBuild = buildModule: + channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { + modules = [ buildModule ]; + }); +in +{ + system.build = { + iso = (mkBuild (devlib.modules.isoConfig { + inherit self; + inherit (self) inputs; + fullHostConfig = config; + })).config.system.build.isoImage; + + homes = (mkBuild ({ config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + })).config.home-manager.users; + }; +} From e97e916521b2bbd3605350fe1a1e50dbbc8902b5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:46:30 -0700 Subject: [PATCH 099/137] lib: init generators section --- lib/generators.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/generators.nix diff --git a/lib/generators.nix b/lib/generators.nix new file mode 100644 index 0000000..86f9d4d --- /dev/null +++ b/lib/generators.nix @@ -0,0 +1,46 @@ +{ lib }: +{ + mkHomeConfigurations = nixosConfigurations: + with lib; + let + mkHomes = host: config: + mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) + config.config.system.build.homes; + + hmConfigs = mapAttrs mkHomes nixosConfigurations; + + in + foldl recursiveUpdate { } (attrValues hmConfigs); + + mkDeployNodes = + /** + Synopsis: mkNodes _nixosConfigurations_ + + Generate the `nodes` attribute expected by deploy-rs + where _nixosConfigurations_ are `nodes`. + **/ + + deploy: lib.mapAttrs (_: config: { + hostname = config.config.networking.hostName; + + profiles.system = { + user = "root"; + path = deploy.lib.x86_64-linux.activate.nixos config; + }; + }); + + mkSuites = { suites, profiles }: + let + profileSet = lib.genAttrs' profiles (path: { + name = baseNameOf path; + value = lib.mkProfileAttrs (toString path); + }); + + definedSuites = suites profileSet; + + allProfiles = lib.collectProfiles profileSet; + in + lib.mapAttrs (_: v: lib.profileMap v) definedSuites // { + inherit allProfiles; + }; +} From c93e9fda0fada3e4a48f416d1f38c5a57852e492 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:46:54 -0700 Subject: [PATCH 100/137] lib: init importers section --- lib/importers.nix | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/importers.nix diff --git a/lib/importers.nix b/lib/importers.nix new file mode 100644 index 0000000..ea07373 --- /dev/null +++ b/lib/importers.nix @@ -0,0 +1,64 @@ +{ lib }: +let + recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: + lib.mapFilterAttrs + (_: v: v != null) + (n: v: + if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" + then + let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) + else + lib.nameValuePair ("") (null)) + (lib.safeReadDir dir); + + mkProfileAttrs = + /** + Synopsis: mkProfileAttrs _path_ + + Recursively collect the subdirs of _path_ containing a default.nix into attrs. + This sets a contract, eliminating ambiguity for _default.nix_ living under the + profile directory. + + Example: + let profiles = mkProfileAttrs ./profiles; in + assert profiles ? core.default; 0 + **/ + dir: + let + imports = + let + files = lib.safeReadDir dir; + + p = n: v: + v == "directory" + && n != "profiles"; + in + lib.filterAttrs p files; + + f = n: _: + lib.optionalAttrs + (lib.pathExists "${dir}/${n}/default.nix") + { default = "${dir}/${n}"; } + // mkProfileAttrs "${dir}/${n}"; + in + lib.mapAttrs f imports; + +in +{ + inherit recImport mkProfileAttrs; + + pathsIn = dir: + let + fullPath = name: "${toString dir}/${name}"; + in + map fullPath (lib.attrNames (lib.safeReadDir dir)); + + importHosts = dir: + recImport { + inherit dir; + _import = base: { + modules = import "${toString dir}/${base}.nix"; + }; + }; +} + From e837aaa8755d45028ba48b12bbac3231e86bf39b Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:47:43 -0700 Subject: [PATCH 101/137] lib: remove devos section --- lib/devos/default.nix | 30 ------------------- lib/devos/devosSystem.nix | 40 ------------------------- lib/devos/mkHosts.nix | 57 ------------------------------------ lib/devos/mkNodes.nix | 16 ---------- lib/devos/mkPackages.nix | 17 ----------- lib/devos/mkPkgs.nix | 25 ---------------- lib/devos/mkProfileAttrs.nix | 35 ---------------------- lib/devos/mkSuites.nix | 20 ------------- lib/devos/recImport.nix | 12 -------- 9 files changed, 252 deletions(-) delete mode 100644 lib/devos/default.nix delete mode 100644 lib/devos/devosSystem.nix delete mode 100644 lib/devos/mkHosts.nix delete mode 100644 lib/devos/mkNodes.nix delete mode 100644 lib/devos/mkPackages.nix delete mode 100644 lib/devos/mkPkgs.nix delete mode 100644 lib/devos/mkProfileAttrs.nix delete mode 100644 lib/devos/mkSuites.nix delete mode 100644 lib/devos/recImport.nix diff --git a/lib/devos/default.nix b/lib/devos/default.nix deleted file mode 100644 index 9a3118f..0000000 --- a/lib/devos/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib, utils }: -{ - # pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs - pkgImport = nixpkgs: overlays: system: - import nixpkgs { - inherit system overlays; - config = { allowUnfree = true; }; - }; - - profileMap = list: map (profile: profile.default) (lib.flatten list); - - mkNodes = import ./mkNodes.nix { inherit lib; }; - - mkHosts = import ./mkHosts.nix { inherit lib; }; - - mkSuites = import ./mkSuites.nix { inherit lib; }; - - mkProfileAttrs = import ./mkProfileAttrs.nix { inherit lib; }; - - mkPkgs = import ./mkPkgs.nix { inherit lib utils; }; - - recImport = import ./recImport.nix { inherit lib; }; - - devosSystem = import ./devosSystem.nix { inherit lib; }; - - mkHomeConfigurations = import ./mkHomeConfigurations.nix { inherit lib; }; - - mkPackages = import ./mkPackages.nix { inherit lib; }; -} - diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix deleted file mode 100644 index c48f68a..0000000 --- a/lib/devos/devosSystem.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ lib }: - -# dependencies to return a builder -{ self, inputs }: - -{ modules, specialArgs, ... } @ args: -let inherit (specialArgs.channel.input.lib) nixosSystem; in -nixosSystem - (args // { - modules = - let - fullHostConfig = (nixosSystem (args // { inherit modules; })).config; - - isoConfig = (nixosSystem - (args // { - modules = modules ++ [ - (lib.modules.iso { inherit self inputs fullHostConfig; }) - ]; - })).config; - - hmConfig = (nixosSystem - (args // { - modules = modules ++ [ - (lib.modules.hmConfig) - ]; - })).config; - in - modules ++ [{ - system.build = { - iso = isoConfig.system.build.isoImage; - homes = hmConfig.home-manager.users; - }; - lib = { - inherit specialArgs; - testModule = { - imports = modules; - }; - }; - }]; - }) diff --git a/lib/devos/mkHosts.nix b/lib/devos/mkHosts.nix deleted file mode 100644 index 2fe4ed3..0000000 --- a/lib/devos/mkHosts.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ lib }: - -{ self, nixos, inputs, dir, extern, suites, overrides, multiPkgs }: -let - defaultSystem = "x86_64-linux"; - - modules = with lib.modules; { - modOverrides = modOverrides { inherit overrides; }; - hmDefaults = hmDefaults { - inherit extern; - inherit (self) homeModules; - userSuites = suites.user; - }; - globalDefaults = globalDefaults { - inherit self nixos inputs multiPkgs; - }; - cachix = cachix { inherit self; }; - flakeModules = flakeModules { inherit self extern; }; - }; - - specialArgs = extern.specialArgs // { suites = suites.system; }; - - mkHostConfig = hostName: - let - local = { - require = [ - "${dir}/${hostName}.nix" - ]; - - networking = { inherit hostName; }; - - _module.args = { - self = self; - hosts = builtins.mapAttrs (_: host: host.config) - (removeAttrs hosts [ hostName ]); - }; - - lib = { inherit specialArgs; }; - lib.testModule = { - imports = builtins.attrValues modules; - }; - - }; - in - lib.os.devosSystem { - inherit self nixos inputs specialArgs; - system = defaultSystem; - modules = modules // { inherit local; }; - }; - - hosts = lib.os.recImport - { - inherit dir; - _import = mkHostConfig; - }; -in -hosts diff --git a/lib/devos/mkNodes.nix b/lib/devos/mkNodes.nix deleted file mode 100644 index 83906ce..0000000 --- a/lib/devos/mkNodes.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib }: - -/** - Synopsis: mkNodes _nixosConfigurations_ - - Generate the `nodes` attribute expected by deploy-rs - where _nixosConfigurations_ are `nodes`. - **/ -deploy: lib.mapAttrs (_: config: { - hostname = config.config.networking.hostName; - - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; -}) diff --git a/lib/devos/mkPackages.nix b/lib/devos/mkPackages.nix deleted file mode 100644 index d899268..0000000 --- a/lib/devos/mkPackages.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ lib }: - -{ overlay, overlays, pkgs }: -let - packagesNames = lib.attrNames (overlay null null) - ++ lib.attrNames (lib.concatAttrs - (lib.attrValues - (lib.mapAttrs (_: v: v null null) overlays) - ) - ); -in -lib.fold - (key: sum: lib.recursiveUpdate sum { - ${key} = pkgs.${key}; - }) -{ } - packagesNames diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix deleted file mode 100644 index a7cf236..0000000 --- a/lib/devos/mkPkgs.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ lib, utils }: - -{ self, nixos, inputs, extern, overrides }: -(utils.lib.eachDefaultSystem - (system: - let - overridePkgs = lib.os.pkgImport inputs.override [ ] system; - overridesOverlay = overrides.packages; - - overlays = [ - (final: prev: { - lib = prev.lib.extend (lfinal: lprev: { - inherit lib; - inherit (lib) nixosSystem; - }); - }) - (overridesOverlay overridePkgs) - self.overlay - ] - ++ extern.overlays - ++ (lib.attrValues self.overlays); - in - { pkgs = lib.os.pkgImport nixos overlays system; } - ) -).pkgs diff --git a/lib/devos/mkProfileAttrs.nix b/lib/devos/mkProfileAttrs.nix deleted file mode 100644 index cdfc32e..0000000 --- a/lib/devos/mkProfileAttrs.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ lib }: - -let mkProfileAttrs = - /** - Synopsis: mkProfileAttrs _path_ - - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. - - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ - dir: - let - imports = - let - files = lib.safeReadDir dir; - - p = n: v: - v == "directory" - && n != "profiles"; - in - lib.filterAttrs p files; - - f = n: _: - lib.optionalAttrs - (lib.pathExists "${dir}/${n}/default.nix") - { default = "${dir}/${n}"; } - // mkProfileAttrs "${dir}/${n}"; - in - lib.mapAttrs f imports; -in mkProfileAttrs - diff --git a/lib/devos/mkSuites.nix b/lib/devos/mkSuites.nix deleted file mode 100644 index 45d8a10..0000000 --- a/lib/devos/mkSuites.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib }: - -{ suites, profiles } @ args: -let - inherit (lib) os; - - profileSet = lib.genAttrs' profiles (path: { - name = baseNameOf path; - value = os.mkProfileAttrs (toString path); - }); - - definedSuites = suites profileSet; - - allProfiles = lib.collectProfiles profileSet; -in -lib.mapAttrs (_: v: os.profileMap v) definedSuites // { - inherit allProfiles; -} - - diff --git a/lib/devos/recImport.nix b/lib/devos/recImport.nix deleted file mode 100644 index c96c935..0000000 --- a/lib/devos/recImport.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ lib }: - -{ dir, _import ? base: import "${dir}/${base}.nix" }: -lib.mapFilterAttrs - (_: v: v != null) - (n: v: - if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" - then - let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) - else - lib.nameValuePair ("") (null)) - (lib.safeReadDir dir) From 496348b8afa4fea898d5c21147d56b9314c11a25 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 01:12:29 -0700 Subject: [PATCH 102/137] lib: update namespaces and cleanup exports --- lib/flake.nix | 54 +++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 2513311..fba02a8 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -10,31 +10,23 @@ outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: let - lib = nixpkgs.lib.makeExtensible (self: - let - attrs = import ./attrs.nix { lib = nixpkgs.lib // self; }; - lists = import ./lists.nix { lib = nixpkgs.lib // self; }; - strings = import ./strings.nix { lib = nixpkgs.lib // self; }; - modules = import ./modules.nix { lib = nixpkgs.lib // self; }; - in - - utils.lib - - // - - { - os = import ./devos { - lib = nixpkgs.lib // self; - inherit utils; - }; + let combinedLib = nixpkgs.lib // self; in + with self; + utils.lib // { + attrs = import ./attrs.nix { lib = combinedLib; }; + lists = import ./lists.nix { lib = combinedLib; }; + strings = import ./strings.nix { lib = combinedLib; }; + modules = import ./modules.nix { lib = combinedLib; }; + importers = import ./importers.nix { lib = combinedLib; }; + generators = import ./generators.nix { lib = combinedLib; }; mkFlake = { __functor = import ./mkFlake { - lib = nixpkgs.lib // self; + lib = combinedLib; inherit deploy; }; - evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; + evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; }; pkgs-lib = import ./pkgs-lib { @@ -42,28 +34,26 @@ inherit deploy devshell; }; - inherit (attrs) - mapFilterAttrs - genAttrs' - safeReadDir - pathsToImportedAttrs - concatAttrs - filterPackages - importHosts; - inherit (lists) pathsIn collectProfiles unifyOverlays; + inherit (attrs) mapFilterAttrs genAttrs' safeReadDir concatAttrs; + inherit (lists) profileMap collectProfiles unifyOverlays; inherit (strings) rgxToString; - inherit modules; + inherit (importers) mkProfileAttrs pathsIn importHosts; + inherit (generators) mkSuites mkDeployNodes mkHomeConfigurations; } ); in { - lib = utils.lib // { + lib = with lib; utils.lib // { + inherit attrs lists modules importers generators; inherit (lib) - mkFlake pathsIn importHosts; + mkFlake + pathsIn + importHosts + mkDeployNodes + mkHomeConfigurations; }; - } // From 197d7929464757dbfcbbacbc1aef0586e9e20add Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:49:04 -0700 Subject: [PATCH 103/137] update to new lib format --- flake.lock | 2 +- lib/attrs.nix | 35 ----------------------------------- lib/lists.nix | 20 +++++++++----------- lib/mkFlake/default.nix | 7 +++---- lib/mkFlake/evalArgs.nix | 4 +--- lib/tests/lib.nix | 21 +-------------------- 6 files changed, 15 insertions(+), 74 deletions(-) diff --git a/flake.lock b/flake.lock index 484e301..795e0de 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=", + "narHash": "sha256-9JsKDtgLSmAkcaKRD4Ycttip1jpO9dVVaRwclWH0V8E=", "path": "./lib", "type": "path" }, diff --git a/lib/attrs.nix b/lib/attrs.nix index 93f7958..1061c0e 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -12,43 +12,8 @@ rec { # Generate an attribute set by mapping a function over a list of values. genAttrs' = values: f: lib.listToAttrs (map f values); - # Convert a list of file paths to attribute set where - # the key is the folder or filename stripped of nix - # extension and imported content of the file as value. - # - pathsToImportedAttrs = paths: - let - paths' = lib.filter - (path: lib.hasSuffix ".nix" path - || lib.pathExists "${path}/default.nix") - paths; - in - genAttrs' paths' (path: { - name = lib.removeSuffix ".nix" - # Safe as long this is just used as a name - (builtins.unsafeDiscardStringContext (baseNameOf path)); - value = import path; - }); - - importHosts = dir: - lib.os.recImport { - inherit dir; - _import = base: { - modules = import "${toString dir}/${base}.nix"; - }; - }; - concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; - # Filter out packages that support given system and follow flake check requirements - filterPackages = system: packages: - let - # Everything that nix flake check requires for the packages output - filter = (n: v: with v; let platforms = meta.hydraPlatforms or meta.platforms or [ ]; in - lib.isDerivation v && !meta.broken && builtins.elem system platforms); - in - lib.filterAttrs filter packages; - safeReadDir = path: lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); } diff --git a/lib/lists.nix b/lib/lists.nix index 5e9c57b..4bef865 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -3,19 +3,17 @@ collectProfiles = set: let collectNestedProfiles = set: - lib.mapAttrsToList (n: v: - if builtins.isAttrs v then - [ v.default or null ] ++ collectNestedProfiles v - else null - ) set; + lib.mapAttrsToList + (n: v: + if builtins.isAttrs v then + [ v.default or null ] ++ collectNestedProfiles v + else null + ) + set; in - builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); + builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); - pathsIn = dir: - let - fullPath = name: "${toString dir}/${name}"; - in - map fullPath (lib.attrNames (lib.safeReadDir dir)); + profileMap = list: map (profile: profile.default) (lib.flatten list); unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); } diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index ed99db0..5bd6419 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,6 +1,5 @@ { lib, deploy }: let - inherit (lib) os; inherit (builtins) mapAttrs attrNames attrValues head isFunction; in @@ -66,16 +65,16 @@ lib.systemFlake (lib.mergeAny modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { # So modules and functions can create their own version of the build - modules = [ { lib.builderArgs = args; } ]; + modules = [{ lib.builderArgs = args; }]; }); }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; homeModules = lib.exporter.modulesFromList cfg.home.modules; - homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + deploy.nodes = lib.mkDeployNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { # since we can't detect overlays owned by self diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix index ee42e22..bf36627 100644 --- a/lib/mkFlake/evalArgs.nix +++ b/lib/mkFlake/evalArgs.nix @@ -4,8 +4,6 @@ let argOpts = with lib; { config, ... }: let - inherit (lib) os; - cfg = config; inherit (config) self; @@ -188,7 +186,7 @@ let suites = mkOption { type = pathTo (functionTo attrs); default = _: { }; - apply = suites: os.mkSuites { + apply = suites: lib.mkSuites { inherit suites; inherit (config) profiles; }; diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix index e992df6..78536e7 100644 --- a/lib/tests/lib.nix +++ b/lib/tests/lib.nix @@ -37,25 +37,6 @@ lib.runTests { ]; }; - testPathsToImportedAttrs = { - expr = - pathsToImportedAttrs [ - (toString ./testPathsToImportedAttrs/dir) - ./testPathsToImportedAttrs/foo.nix - ./testPathsToImportedAttrs/bar.nix - ./testPathsToImportedAttrs/t.nix - ./testPathsToImportedAttrs/f.nix - ]; - - expected = { - dir = { a = 5; }; - foo = { bar = 1; }; - bar = { foo = 2; }; - t = true; - f = false; - }; - }; - testRgxToString = lib.testAllTrue [ (rgxToString ".+x" "vxk" == "vx") (rgxToString "^fo" "foo" == "fo") @@ -72,7 +53,7 @@ lib.runTests { }; testSuites = { - expr = os.mkSuites { + expr = mkSuites { suites = { profiles, ... }: with profiles; { bar = [ foo ]; }; From deb47dbfae5f7ca93a7f7c0a08cddf6e352060a1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 11:15:44 -0700 Subject: [PATCH 104/137] move otherArguments to right side of merge for overlay list ordering, otherArguments should have priority --- flake.lock | 2 +- lib/mkFlake/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 795e0de..6ee3c39 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-9JsKDtgLSmAkcaKRD4Ycttip1jpO9dVVaRwclWH0V8E=", + "narHash": "sha256-AnasH9JbhPD+sR30YP+1IvNoO0S4hUcSraJwvXIaIpo=", "path": "./lib", "type": "path" }, diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 5bd6419..3fecd61 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -40,7 +40,6 @@ let hostDefaults = stripHost cfg.nixos.hostDefaults; in lib.systemFlake (lib.mergeAny - otherArguments { inherit self inputs hosts; inherit (cfg) channelsConfig supportedSystems; @@ -99,4 +98,5 @@ lib.systemFlake (lib.mergeAny pkgs = getDefaultChannel channels; }; } + otherArguments # for overlays list order ) From 7bf605d08c0cb6a0534b39823ac30a5a7b0976c5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 21:05:21 -0700 Subject: [PATCH 105/137] lib/modules: pull devlib module arg from pkgs So any overlays affecting devlib also affect the module argument --- flake.lock | 2 +- lib/modules.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 6ee3c39..e516cd4 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-AnasH9JbhPD+sR30YP+1IvNoO0S4hUcSraJwvXIaIpo=", + "narHash": "sha256-jG9Y7IiZkB+xKuqsVr2wr0zfV2TNziIIRmv0MHqzis0=", "path": "./lib", "type": "path" }, diff --git a/lib/modules.nix b/lib/modules.nix index 60e2971..6deb7f3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -43,7 +43,7 @@ _module.args = { inherit self; - devlib = lib; + devlib = pkgs.devlib; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); }; From b8f7cdbe638699b95278e8bec56add4e63777e74 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 2 May 2021 10:35:29 -0700 Subject: [PATCH 106/137] improve home-manager and deploy-rs integration move both to be setup in template only set home-manager options if they exist --- flake.lock | 2 +- flake.nix | 4 ++++ lib/flake.nix | 13 +++++++------ lib/generators.nix | 22 +++++++++++++--------- lib/mkFlake/default.nix | 5 +---- lib/modules.nix | 17 ++++++++++------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/flake.lock b/flake.lock index e516cd4..3a70180 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-jG9Y7IiZkB+xKuqsVr2wr0zfV2TNziIIRmv0MHqzis0=", + "narHash": "sha256-/htTDxf3/n8lcL7Gnoi3+uamuY/KnlSMWDQ76dzQpac=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 41a83a9..a781199 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,10 @@ }; }; + homeConfigurations = devos.lib.mkHomeConfigurations self.nixosConfigurations; + + deploy.nodes = devos.lib.mkDeployNodes self.nixosConfigurations { }; + #defaultTemplate = self.templates.flk; templates.flk.path = ./.; templates.flk.description = "flk template"; diff --git a/lib/flake.nix b/lib/flake.nix index fba02a8..5fd7936 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -19,18 +19,19 @@ strings = import ./strings.nix { lib = combinedLib; }; modules = import ./modules.nix { lib = combinedLib; }; importers = import ./importers.nix { lib = combinedLib; }; - generators = import ./generators.nix { lib = combinedLib; }; + + generators = import ./generators.nix { + lib = combinedLib; + inherit deploy; + }; mkFlake = { - __functor = import ./mkFlake { - lib = combinedLib; - inherit deploy; - }; + __functor = import ./mkFlake { lib = combinedLib; }; evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; }; pkgs-lib = import ./pkgs-lib { - lib = nixpkgs.lib // self; + lib = combinedLib; inherit deploy devshell; }; diff --git a/lib/generators.nix b/lib/generators.nix index 86f9d4d..f403fbc 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, deploy }: { mkHomeConfigurations = nixosConfigurations: with lib; @@ -12,7 +12,7 @@ in foldl recursiveUpdate { } (attrValues hmConfigs); - mkDeployNodes = + mkDeployNodes = hosts: extraConfig: /** Synopsis: mkNodes _nixosConfigurations_ @@ -20,14 +20,18 @@ where _nixosConfigurations_ are `nodes`. **/ - deploy: lib.mapAttrs (_: config: { - hostname = config.config.networking.hostName; + lib.mapAttrs + (_: config: lib.recursiveUpdate + { + hostname = config.config.networking.hostName; - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; - }); + profiles.system = { + user = "root"; + path = deploy.lib.x86_64-linux.activate.nixos config; + }; + } + extraConfig) + hosts; mkSuites = { suites, profiles }: let diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index 3fecd61..e2d0b73 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,4 +1,4 @@ -{ lib, deploy }: +{ lib }: let inherit (builtins) mapAttrs attrNames attrValues head isFunction; in @@ -71,9 +71,6 @@ lib.systemFlake (lib.mergeAny nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; homeModules = lib.exporter.modulesFromList cfg.home.modules; - homeConfigurations = lib.mkHomeConfigurations self.nixosConfigurations; - - deploy.nodes = lib.mkDeployNodes deploy self.nixosConfigurations; overlays = lib.exporter.overlaysFromChannelsExporter { # since we can't detect overlays owned by self diff --git a/lib/modules.nix b/lib/modules.nix index 6deb7f3..d564196 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1,14 +1,17 @@ { lib }: { - hmDefaults = { suites, modules }: { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; + hmDefaults = { suites, modules }: + { options, ... }: { + config = lib.optionalAttrs (options ? home-manager) { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; - extraSpecialArgs = { inherit suites; }; - sharedModules = modules; + extraSpecialArgs = { inherit suites; }; + sharedModules = modules; + }; + }; }; - }; globalDefaults = { self, inputs }: let From 8dabd0f56919eea94d8c034805bb562e97da0021 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 4 May 2021 21:48:49 -0700 Subject: [PATCH 107/137] switch to devlib repo and remove in-tree lib --- flake.lock | 18 +- flake.nix | 27 +- lib/attrs.nix | 19 -- lib/default.nix | 2 + lib/devos/mkHomeConfigurations.nix | 15 - lib/flake.lock | 166 ----------- lib/flake.nix | 84 ------ lib/generators.nix | 50 ---- lib/importers.nix | 64 ----- lib/lists.nix | 19 -- lib/mkFlake/default.nix | 99 ------- lib/mkFlake/evalArgs.nix | 262 ------------------ lib/modules.nix | 119 -------- lib/pkgs-lib/default.nix | 6 - lib/pkgs-lib/shell/default.nix | 55 ---- lib/pkgs-lib/shell/devshell.toml | 29 -- lib/pkgs-lib/shell/flk.nix | 23 -- lib/pkgs-lib/shell/flk.sh | 98 ------- lib/pkgs-lib/shell/pre-commit.sh | 29 -- lib/pkgs-lib/tests/default.nix | 56 ---- lib/pkgs-lib/tests/lib.nix | 93 ------- lib/strings.nix | 20 -- lib/tests/default.nix | 27 -- lib/tests/lib.nix | 70 ----- lib/tests/profiles/foo/default.nix | 3 - lib/tests/profiles/t/default.nix | 1 - lib/tests/testPathsIn/bar | 0 lib/tests/testPathsIn/baz | 0 lib/tests/testPathsIn/foo | 0 lib/tests/testPathsToImportedAttrs/bar.nix | 1 - .../testPathsToImportedAttrs/dir/default.nix | 1 - lib/tests/testPathsToImportedAttrs/f.nix | 1 - lib/tests/testPathsToImportedAttrs/foo.nix | 1 - lib/tests/testPathsToImportedAttrs/t.nix | 1 - 34 files changed, 27 insertions(+), 1432 deletions(-) delete mode 100644 lib/attrs.nix create mode 100644 lib/default.nix delete mode 100644 lib/devos/mkHomeConfigurations.nix delete mode 100644 lib/flake.lock delete mode 100644 lib/flake.nix delete mode 100644 lib/generators.nix delete mode 100644 lib/importers.nix delete mode 100644 lib/lists.nix delete mode 100644 lib/mkFlake/default.nix delete mode 100644 lib/mkFlake/evalArgs.nix delete mode 100644 lib/modules.nix delete mode 100644 lib/pkgs-lib/default.nix delete mode 100644 lib/pkgs-lib/shell/default.nix delete mode 100644 lib/pkgs-lib/shell/devshell.toml delete mode 100644 lib/pkgs-lib/shell/flk.nix delete mode 100755 lib/pkgs-lib/shell/flk.sh delete mode 100755 lib/pkgs-lib/shell/pre-commit.sh delete mode 100644 lib/pkgs-lib/tests/default.nix delete mode 100644 lib/pkgs-lib/tests/lib.nix delete mode 100644 lib/strings.nix delete mode 100644 lib/tests/default.nix delete mode 100644 lib/tests/lib.nix delete mode 100644 lib/tests/profiles/foo/default.nix delete mode 100644 lib/tests/profiles/t/default.nix delete mode 100644 lib/tests/testPathsIn/bar delete mode 100644 lib/tests/testPathsIn/baz delete mode 100644 lib/tests/testPathsIn/foo delete mode 100644 lib/tests/testPathsToImportedAttrs/bar.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/dir/default.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/f.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/foo.nix delete mode 100644 lib/tests/testPathsToImportedAttrs/t.nix diff --git a/flake.lock b/flake.lock index 3a70180..db2f914 100644 --- a/flake.lock +++ b/flake.lock @@ -69,7 +69,7 @@ "type": "github" } }, - "devos": { + "devlib": { "inputs": { "deploy": "deploy", "devshell": "devshell", @@ -79,13 +79,17 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-/htTDxf3/n8lcL7Gnoi3+uamuY/KnlSMWDQ76dzQpac=", - "path": "./lib", - "type": "path" + "lastModified": 1620188794, + "narHash": "sha256-BDwtrbUkrSnBQJBXuaJg9QBu3MYL0iuJPE8P30o0x7I=", + "owner": "divnix", + "repo": "devlib", + "rev": "ffda6add9eb984d986cf5b6a838a52334317302f", + "type": "github" }, "original": { - "path": "./lib", - "type": "path" + "owner": "divnix", + "repo": "devlib", + "type": "github" } }, "devshell": { @@ -321,7 +325,7 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "devos": "devos", + "devlib": "devlib", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index a781199..8dc8e7e 100644 --- a/flake.nix +++ b/flake.nix @@ -5,14 +5,9 @@ { nixos.url = "nixpkgs/nixos-unstable"; latest.url = "nixpkgs"; - devos.url = "path:./lib"; # TODO: outfactor into separate repo - devos.inputs = { + devlib.url = "github:divnix/devlib"; + devlib.inputs = { nixpkgs.follows = "nixos"; - # deploy.inputs = { - # flake-compat.follows = "flake-compat"; - # naersk.follows = "naersk"; - # nixpkgs.follows = "nixos"; - # }; }; ci-agent = { @@ -31,8 +26,8 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, pkgs, devos, nixos, ci-agent, home, nixos-hardware, nur, ... }: - devos.lib.mkFlake { + outputs = inputs@{ self, pkgs, devlib, nixos, ci-agent, home, nixos-hardware, nur, ... }: + devlib.lib.mkFlake { inherit self inputs; channelsConfig = { allowUnfree = true; }; @@ -40,7 +35,7 @@ channels = { nixos = { overlays = [ - (devos.lib.pathsIn ./overlays) + (devlib.lib.pathsIn ./overlays) ./pkgs/default.nix pkgs.overlay # for `srcs` nur.overlay @@ -49,6 +44,12 @@ latest = { }; }; + sharedOverlays = [ + (final: prev: { + ourlib = prev.devlib.extend (import ./lib); + }) + ]; + nixos = { hostDefaults = { system = "x86_64-linux"; @@ -61,7 +62,7 @@ ]; }; hosts = nixos.lib.mkMerge [ - (devos.lib.importHosts ./hosts) + (devlib.lib.importHosts ./hosts) { /* set host specific properties here */ } ]; profiles = [ ./profiles ./users ]; @@ -79,9 +80,9 @@ }; }; - homeConfigurations = devos.lib.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = devlib.lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = devos.lib.mkDeployNodes self.nixosConfigurations { }; + deploy.nodes = devlib.lib.mkDeployNodes self.nixosConfigurations { }; #defaultTemplate = self.templates.flk; templates.flk.path = ./.; diff --git a/lib/attrs.nix b/lib/attrs.nix deleted file mode 100644 index 1061c0e..0000000 --- a/lib/attrs.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ lib }: -rec { - # mapFilterAttrs :: - # (name -> value -> bool ) - # (name -> value -> { name = any; value = any; }) - # attrs - mapFilterAttrs = seive: f: attrs: - lib.filterAttrs - seive - (lib.mapAttrs' f attrs); - - # Generate an attribute set by mapping a function over a list of values. - genAttrs' = values: f: lib.listToAttrs (map f values); - - concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { }; - - safeReadDir = path: - lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path)); -} diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..c4da46c --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,2 @@ +lfinal: lprev: { +} diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix deleted file mode 100644 index 95affc2..0000000 --- a/lib/devos/mkHomeConfigurations.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ lib }: - -nixosConfigurations: - -with lib; -let - mkHomes = hostName: host: - mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home) - # So this function is useful for non-devos hosts - (host.config.system.build.homes or host.config.home-manager.users); - - hmConfigs = mapAttrs mkHomes nixosConfigurations; - -in -foldl recursiveUpdate { } (attrValues hmConfigs) diff --git a/lib/flake.lock b/lib/flake.lock deleted file mode 100644 index 8156254..0000000 --- a/lib/flake.lock +++ /dev/null @@ -1,166 +0,0 @@ -{ - "nodes": { - "deploy": { - "inputs": { - "flake-compat": "flake-compat", - "naersk": "naersk", - "nixpkgs": "nixpkgs", - "utils": "utils" - }, - "locked": { - "lastModified": 1616406726, - "narHash": "sha256-n9zmgxR03QNrvs9/fHewqE0j3SjL7Y+cglBCFu3U3rg=", - "owner": "serokell", - "repo": "deploy-rs", - "rev": "9e405fbc5ab5bacbd271fd78c6b6b6877c4d9f8d", - "type": "github" - }, - "original": { - "owner": "serokell", - "repo": "deploy-rs", - "type": "github" - } - }, - "devshell": { - "locked": { - "lastModified": 1618523768, - "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", - "owner": "numtide", - "repo": "devshell", - "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1606424373, - "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1619345332, - "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "naersk": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1610392286, - "narHash": "sha256-3wFl5y+4YZO4SgRYK8WE7JIS3p0sxbgrGaQ6RMw+d98=", - "owner": "nmattia", - "repo": "naersk", - "rev": "d7bfbad3304fd768c0f93a4c3b50976275e6d4be", - "type": "github" - }, - "original": { - "owner": "nmattia", - "ref": "master", - "repo": "naersk", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1610942247, - "narHash": "sha256-PKo1ATAlC6BmfYSRmX0TVmNoFbrec+A5OKcabGEu2yU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7d71001b796340b219d1bfa8552c81995017544a", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1619244632, - "narHash": "sha256-IDcbMRnyKO9WlQ5xzIlM3HfWAUKTy+3xSd+CvDGiLgE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5cecebfb2f76da7b93f19967e99b3ff4fb4d2850", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "deploy": "deploy", - "devshell": "devshell", - "nixpkgs": "nixpkgs_2", - "utils": "utils_2" - } - }, - "utils": { - "locked": { - "lastModified": 1610051610, - "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "utils_2": { - "inputs": { - "flake-utils": "flake-utils" - }, - "locked": { - "lastModified": 1619714004, - "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", - "owner": "gytis-ivaskevicius", - "repo": "flake-utils-plus", - "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", - "type": "github" - }, - "original": { - "owner": "gytis-ivaskevicius", - "ref": "staging", - "repo": "flake-utils-plus", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/lib/flake.nix b/lib/flake.nix deleted file mode 100644 index 5fd7936..0000000 --- a/lib/flake.nix +++ /dev/null @@ -1,84 +0,0 @@ -{ - description = "DevOS environment configuriguration library."; - - inputs = - { - deploy.url = "github:serokell/deploy-rs"; - devshell.url = "github:numtide/devshell"; - utils.url = "github:gytis-ivaskevicius/flake-utils-plus/staging"; - }; - - outputs = inputs@{ self, nixpkgs, deploy, devshell, utils, ... }: - let - lib = nixpkgs.lib.makeExtensible (self: - let combinedLib = nixpkgs.lib // self; in - with self; - utils.lib // { - attrs = import ./attrs.nix { lib = combinedLib; }; - lists = import ./lists.nix { lib = combinedLib; }; - strings = import ./strings.nix { lib = combinedLib; }; - modules = import ./modules.nix { lib = combinedLib; }; - importers = import ./importers.nix { lib = combinedLib; }; - - generators = import ./generators.nix { - lib = combinedLib; - inherit deploy; - }; - - mkFlake = { - __functor = import ./mkFlake { lib = combinedLib; }; - evalArgs = import ./mkFlake/evalArgs.nix { lib = combinedLib; }; - }; - - pkgs-lib = import ./pkgs-lib { - lib = combinedLib; - inherit deploy devshell; - }; - - inherit (attrs) mapFilterAttrs genAttrs' safeReadDir concatAttrs; - inherit (lists) profileMap collectProfiles unifyOverlays; - inherit (strings) rgxToString; - inherit (importers) mkProfileAttrs pathsIn importHosts; - inherit (generators) mkSuites mkDeployNodes mkHomeConfigurations; - } - ); - - in - - { - lib = with lib; utils.lib // { - inherit attrs lists modules importers generators; - inherit (lib) - mkFlake - pathsIn - importHosts - mkDeployNodes - mkHomeConfigurations; - }; - } - - // - - utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - checks = { - tests = import ./tests { - inherit pkgs; - lib = nixpkgs.lib // lib; - }; - }; - packages = { - mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" - ( - pkgs.nixosOptionsDoc { - inherit (lib.mkFlake.evalArgs { args = { }; }) options; - } - ).optionsMDDoc; - }; - } - ); - -} diff --git a/lib/generators.nix b/lib/generators.nix deleted file mode 100644 index f403fbc..0000000 --- a/lib/generators.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ lib, deploy }: -{ - mkHomeConfigurations = nixosConfigurations: - with lib; - let - mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) - config.config.system.build.homes; - - hmConfigs = mapAttrs mkHomes nixosConfigurations; - - in - foldl recursiveUpdate { } (attrValues hmConfigs); - - mkDeployNodes = hosts: extraConfig: - /** - Synopsis: mkNodes _nixosConfigurations_ - - Generate the `nodes` attribute expected by deploy-rs - where _nixosConfigurations_ are `nodes`. - **/ - - lib.mapAttrs - (_: config: lib.recursiveUpdate - { - hostname = config.config.networking.hostName; - - profiles.system = { - user = "root"; - path = deploy.lib.x86_64-linux.activate.nixos config; - }; - } - extraConfig) - hosts; - - mkSuites = { suites, profiles }: - let - profileSet = lib.genAttrs' profiles (path: { - name = baseNameOf path; - value = lib.mkProfileAttrs (toString path); - }); - - definedSuites = suites profileSet; - - allProfiles = lib.collectProfiles profileSet; - in - lib.mapAttrs (_: v: lib.profileMap v) definedSuites // { - inherit allProfiles; - }; -} diff --git a/lib/importers.nix b/lib/importers.nix deleted file mode 100644 index ea07373..0000000 --- a/lib/importers.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ lib }: -let - recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: - lib.mapFilterAttrs - (_: v: v != null) - (n: v: - if n != "default.nix" && lib.hasSuffix ".nix" n && v == "regular" - then - let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name) - else - lib.nameValuePair ("") (null)) - (lib.safeReadDir dir); - - mkProfileAttrs = - /** - Synopsis: mkProfileAttrs _path_ - - Recursively collect the subdirs of _path_ containing a default.nix into attrs. - This sets a contract, eliminating ambiguity for _default.nix_ living under the - profile directory. - - Example: - let profiles = mkProfileAttrs ./profiles; in - assert profiles ? core.default; 0 - **/ - dir: - let - imports = - let - files = lib.safeReadDir dir; - - p = n: v: - v == "directory" - && n != "profiles"; - in - lib.filterAttrs p files; - - f = n: _: - lib.optionalAttrs - (lib.pathExists "${dir}/${n}/default.nix") - { default = "${dir}/${n}"; } - // mkProfileAttrs "${dir}/${n}"; - in - lib.mapAttrs f imports; - -in -{ - inherit recImport mkProfileAttrs; - - pathsIn = dir: - let - fullPath = name: "${toString dir}/${name}"; - in - map fullPath (lib.attrNames (lib.safeReadDir dir)); - - importHosts = dir: - recImport { - inherit dir; - _import = base: { - modules = import "${toString dir}/${base}.nix"; - }; - }; -} - diff --git a/lib/lists.nix b/lib/lists.nix deleted file mode 100644 index 4bef865..0000000 --- a/lib/lists.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ lib }: -{ - collectProfiles = set: - let - collectNestedProfiles = set: - lib.mapAttrsToList - (n: v: - if builtins.isAttrs v then - [ v.default or null ] ++ collectNestedProfiles v - else null - ) - set; - in - builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set)); - - profileMap = list: map (profile: profile.default) (lib.flatten list); - - unifyOverlays = channels: map (o: if builtins.isFunction (o null null) then o channels else o); -} diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix deleted file mode 100644 index e2d0b73..0000000 --- a/lib/mkFlake/default.nix +++ /dev/null @@ -1,99 +0,0 @@ -{ lib }: -let - inherit (builtins) mapAttrs attrNames attrValues head isFunction; -in - -_: { self, inputs, ... } @ args: -let - - config = lib.mkFlake.evalArgs { - inherit args; - }; - - cfg = config.config; - - otherArguments = removeAttrs args (attrNames config.options); - - defaultModules = with lib.modules; [ - (hmDefaults { - inherit (cfg.home) suites; - modules = cfg.home.modules ++ cfg.home.externalModules; - }) - (globalDefaults { - inherit self inputs; - }) - ]; - - stripChannel = channel: removeAttrs channel [ - # arguments in our channels api that shouldn't be passed to fup - "overlays" - ]; - getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; - - # 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) [ - # arguments in our hosts/hostDefaults api that shouldn't be passed to fup - "externalModules" - ]; - hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts; - hostDefaults = stripHost cfg.nixos.hostDefaults; -in -lib.systemFlake (lib.mergeAny - { - inherit self inputs hosts; - inherit (cfg) channelsConfig supportedSystems; - - channels = mapAttrs - (name: channel: - stripChannel (channel // { - # pass channels if "overlay" has three arguments - overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; - }) - ) - cfg.channels; - - sharedOverlays = [ - (final: prev: { - __dontExport = true; - devlib = lib; - }) - ]; - hostDefaults = lib.mergeAny hostDefaults { - specialArgs.suites = cfg.nixos.suites; - modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; - builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { - # So modules and functions can create their own version of the build - modules = [{ lib.builderArgs = args; }]; - }); - }; - - nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; - - homeModules = lib.exporter.modulesFromList cfg.home.modules; - - overlays = lib.exporter.overlaysFromChannelsExporter { - # since we can't detect overlays owned by self - # we have to filter out ones exported by the inputs - # optimally we would want a solution for NixOS/nix#4740 - inherit inputs; - inherit (self) pkgs; - }; - - packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; - - checksBuilder = channels: - lib.pkgs-lib.tests.mkChecks { - pkgs = getDefaultChannel channels; - inherit (self.deploy) nodes; - hosts = self.nixosConfigurations; - homes = self.homeConfigurations; - }; - - devShellBuilder = channels: - lib.pkgs-lib.shell { - pkgs = getDefaultChannel channels; - }; - } - otherArguments # for overlays list order -) diff --git a/lib/mkFlake/evalArgs.nix b/lib/mkFlake/evalArgs.nix deleted file mode 100644 index bf36627..0000000 --- a/lib/mkFlake/evalArgs.nix +++ /dev/null @@ -1,262 +0,0 @@ -{ lib }: - -{ args }: -let - argOpts = with lib; { config, ... }: - let - cfg = config; - inherit (config) self; - - maybeImport = obj: - if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then - import obj - else - obj; - - /* Custom types needed for arguments */ - - moduleType = with types; pathTo (anything // { - inherit (submodule { }) check; - description = "valid module"; - }); - - # to export modules we need paths to get the name - exportModuleType = with types; - (addCheck path (x: moduleType.check (import x))) // { - description = "path to a module"; - }; - overlayType = pathTo (types.anything // { - check = builtins.isFunction; - description = "valid Nixpkgs overlay"; - }); - systemType = types.enum config.supportedSystems; - flakeType = with types; (addCheck attrs lib.isStorePath) // { - description = "nix flake"; - }; - - # Apply maybeImport during merge and before check - # To simplify apply keys and improve type checking - pathTo = elemType: with types; coercedTo path maybeImport elemType; - - pathToListOf = elemType: with types; pathTo (listOf elemType); - - coercedListOf = elemType: with types; - coercedTo anything (x: flatten (singleton x)) (listOf elemType); - - /* Submodules needed for API containers */ - - channelsModule = { name, ... }: { - options = with types; { - input = mkOption { - type = flakeType; - default = cfg.inputs.${name}; - defaultText = "inputs."; - description = '' - nixpkgs flake input to use for this channel - ''; - }; - overlays = mkOption { - type = coercedListOf overlayType; - default = [ ]; - description = escape [ "<" ">" ] '' - overlays to apply to this channel - these will get exported under the 'overlays' flake output - as / and any overlay pulled from ''\${inputs} - will be filtered out - ''; - }; - config = mkOption { - type = pathTo attrs; - default = { }; - apply = lib.recursiveUpdate cfg.channelsConfig; - description = '' - nixpkgs config for this channel - ''; - }; - }; - }; - - hostModule = { - options = with types; { - # anything null in hosts gets filtered out by mkFlake - system = mkOption { - type = (nullOr systemType) // { - description = "system defined in `supportedSystems`"; - }; - default = null; - description = '' - system for this host - ''; - }; - channelName = mkOption { - type = (nullOr (types.enum (builtins.attrNames config.channels))) // { - description = "a channel defined in `channels`"; - }; - default = null; - description = '' - Channel this host should follow - ''; - }; - }; - }; - - # This is only needed for hostDefaults - # modules in each host don't get exported - externalModulesModule = { - options = { - externalModules = mkOption { - type = with types; listOf moduleType; - default = [ ]; - description = '' - modules to include that won't be exported - meant importing modules from external flakes - ''; - }; - }; - }; - - modulesModule = { - options = { - modules = mkOption { - type = with types; coercedListOf moduleType; - default = [ ]; - description = '' - modules to include - ''; - }; - }; - }; - - exportModulesModule = name: { - options = { - modules = mkOption { - type = with types; pathTo (coercedListOf exportModuleType); - default = [ ]; - description = '' - modules to include in all hosts and export to ${name}Modules output - ''; - }; - }; - }; - - - - # Home-manager's configs get exported automatically from nixos.hosts - # So there is no need for a host options in the home namespace - # This is only needed for nixos - includeHostsModule = name: { - options = with types; { - hostDefaults = mkOption { - type = submodule [ - hostModule - externalModulesModule - (exportModulesModule name) - ]; - default = { }; - description = '' - Defaults for all hosts. - the modules passed under hostDefaults will be exported - to the '${name}Modules' flake output. - They will also be added to all hosts. - ''; - }; - hosts = mkOption { - type = attrsOf (submodule [ hostModule modulesModule ]); - default = { }; - description = '' - configurations to include in the ${name}Configurations output - ''; - }; - }; - }; - - # profiles and suites - which are profile collections - profilesModule = { config, ... }: { - options = with types; { - profiles = mkOption { - type = listOf path; - default = [ ]; - description = '' - profile folders that can be collected into suites - the name of the argument passed to suites is based - on the folder name. - [ ./profiles ] => { profiles }: - ''; - }; - suites = mkOption { - type = pathTo (functionTo attrs); - default = _: { }; - apply = suites: lib.mkSuites { - inherit suites; - inherit (config) profiles; - }; - description = '' - Function that takes profiles and returns suites for this config system - These can be accessed through the 'suites' special argument. - ''; - }; - }; - }; - in - { - # this does not get propagated to submodules - # to allow passing flake outputs directly to mkFlake - config._module.check = false; - - options = with types; { - self = mkOption { - type = flakeType; - description = "The flake to create the devos outputs for"; - }; - inputs = mkOption { - type = attrsOf flakeType; - description = '' - inputs for this flake - used to set channel defaults and create registry - ''; - }; - supportedSystems = mkOption { - type = listOf str; - default = lib.defaultSystems; - description = '' - The systems supported by this flake - ''; - }; - channelsConfig = mkOption { - type = pathTo attrs; - default = { }; - description = '' - nixpkgs config for all channels - ''; - }; - channels = mkOption { - type = attrsOf (submodule channelsModule); - default = { }; - description = '' - nixpkgs channels to create - ''; - }; - nixos = mkOption { - type = submodule [ (includeHostsModule "nixos") profilesModule ]; - default = { }; - description = '' - hosts, modules, suites, and profiles for nixos - ''; - }; - home = mkOption { - type = submodule [ - profilesModule - (exportModulesModule "home") - externalModulesModule - ]; - default = { }; - description = '' - hosts, modules, suites, and profiles for home-manager - ''; - }; - }; - }; -in -lib.evalModules { - modules = [ argOpts args ]; -} diff --git a/lib/modules.nix b/lib/modules.nix deleted file mode 100644 index d564196..0000000 --- a/lib/modules.nix +++ /dev/null @@ -1,119 +0,0 @@ -{ lib }: -{ - hmDefaults = { suites, modules }: - { options, ... }: { - config = lib.optionalAttrs (options ? home-manager) { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - - extraSpecialArgs = { inherit suites; }; - sharedModules = modules; - }; - }; - }; - - globalDefaults = { self, inputs }: - let - experimentalFeatures = [ - "flakes" - "nix-command" - "ca-references" - "ca-derivations" - ]; - in - { channel, config, pkgs, ... }: { - users.mutableUsers = lib.mkDefault false; - - hardware.enableRedistributableFirmware = lib.mkDefault true; - - nix.nixPath = [ - "nixpkgs=${channel.input}" - "nixos-config=${self}/lib/compat/nixos" - "home-manager=${inputs.home}" - ]; - - nix.registry = { - devos.flake = self; - nixos.flake = channel.input; - }; - - nix.extraOptions = '' - experimental-features = ${lib.concatStringsSep " " - experimentalFeatures - } - ''; - - _module.args = { - inherit self; - devlib = pkgs.devlib; - hosts = builtins.mapAttrs (_: host: host.config) - (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); - }; - - system.configurationRevision = lib.mkIf (self ? rev) self.rev; - }; - - isoConfig = { self, inputs, fullHostConfig }: - { config, modulesPath, suites, ... }: { - - imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; - # avoid unwanted systemd service startups - # all strings in disabledModules get appended to modulesPath - # so convert each to list which can be coerced to string - disabledModules = map lib.singleton suites.allProfiles; - - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; - - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - isoImage.contents = [{ - source = self; - target = "/devos/"; - }]; - isoImage.storeContents = [ - self.devShell.${config.nixpkgs.system} - # include also closures that are "switched off" by the - # above profile filter on the local config attribute - fullHostConfig.system.build.toplevel - ]; - # still pull in tools of deactivated profiles - environment.systemPackages = fullHostConfig.environment.systemPackages; - - # confilcts with networking.wireless which might be slightly - # more useful on a stick - networking.networkmanager.enable = lib.mkForce false; - # confilcts with networking.wireless - networking.wireless.iwd.enable = lib.mkForce false; - - # Set up a link-local boostrap network - # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 - networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works - networking.useNetworkd = lib.mkForce true; - networking.useDHCP = lib.mkForce false; - networking.dhcpcd.enable = lib.mkForce false; - systemd.network = { - # https://www.freedesktop.org/software/systemd/man/systemd.network.html - networks."boostrap-link-local" = { - matchConfig = { - Name = "en* wl* ww*"; - }; - networkConfig = { - Description = "Link-local host bootstrap network"; - MulticastDNS = true; - LinkLocalAddressing = "ipv6"; - DHCP = "yes"; - }; - address = [ - # fall back well-known link-local for situations where MulticastDNS is not available - "fe80::47" # 47: n=14 i=9 x=24; n+i+x - ]; - extraConfig = '' - # Unique, yet stable. Based off the MAC address. - IPv6LinkLocalAddressGenerationMode = "eui64" - ''; - }; - }; - }; - -} - diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix deleted file mode 100644 index bcaee77..0000000 --- a/lib/pkgs-lib/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ lib, deploy, devshell }: -{ - tests = import ./tests { inherit lib deploy; }; - shell = import ./shell { inherit lib devshell deploy; }; -} - diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix deleted file mode 100644 index 5b73b54..0000000 --- a/lib/pkgs-lib/shell/default.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ lib, devshell, deploy }: - -{ pkgs }: -let - overlays = [ - devshell.overlay - - (final: prev: { - deploy-rs = - deploy.packages.${prev.system}.deploy-rs; - }) - ]; - - pkgs' = import pkgs.path { - inherit (pkgs) system; - inherit overlays; - }; - - flk = pkgs'.callPackage ./flk.nix { }; - - installPkgs = (lib.nixosSystem { - inherit (pkgs') system; - modules = [ ]; - }).config.system.build; -in -pkgs'.devshell.mkShell { - imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]; - - packages = with installPkgs; [ - nixos-install - nixos-generate-config - nixos-enter - ]; - - git.hooks = { - pre-commit.text = lib.fileContents ./pre-commit.sh; - }; - - commands = with pkgs'; [ - { package = flk; } - { - name = "nix"; - help = pkgs'.nixFlakes.meta.description; - command = '' - ${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" - ''; - } - ] - ++ lib.optional (system != "i686-linux") { package = cachix; } - ++ lib.optional (system == "x86_64-linux") { - name = "deploy"; - package = deploy-rs; - help = "A simple multi-profile Nix-flake deploy tool."; - }; -} diff --git a/lib/pkgs-lib/shell/devshell.toml b/lib/pkgs-lib/shell/devshell.toml deleted file mode 100644 index f261fdc..0000000 --- a/lib/pkgs-lib/shell/devshell.toml +++ /dev/null @@ -1,29 +0,0 @@ -imports = [ "git.hooks" ] - -[devshell] -packages = [ - "git-crypt" -] - -[[commands]] -package = "git" -category = "vcs" - -[[commands]] -package = "nixpkgs-fmt" -category = "linters" - -[[commands]] -package = "editorconfig-checker" -category = "linters" - -[[commands]] -package = "python3Packages.grip" -category = "documentation" - -[[commands]] -package = "mdbook" -category = "documentation" - -[git.hooks] -enable = true diff --git a/lib/pkgs-lib/shell/flk.nix b/lib/pkgs-lib/shell/flk.nix deleted file mode 100644 index ff9c59e..0000000 --- a/lib/pkgs-lib/shell/flk.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ stdenv }: -let - name = "flk"; -in -stdenv.mkDerivation { - inherit name; - - src = ./flk.sh; - - dontUnpack = true; - dontBuild = true; - - installPhase = '' - mkdir -p $out/bin - install $src $out/bin/${name} - ''; - - checkPhase = '' - ${stdenv.shell} -n -O extglob $out/bin/${name} - ''; - - meta.description = "Build, deploy, and install NixOS"; -} diff --git a/lib/pkgs-lib/shell/flk.sh b/lib/pkgs-lib/shell/flk.sh deleted file mode 100755 index 2d46045..0000000 --- a/lib/pkgs-lib/shell/flk.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bash - -[[ -d "$DEVSHELL_ROOT" ]] || - { - echo "This script must be run from devos's devshell" >&2 - exit 1 - } - -shopt -s extglob - -HOSTNAME="$(hostname)" - -usage () { - printf "%b\n" \ - "\e[4mUsage\e[0m: $(basename $0) COMMAND [ARGS]\n" \ - "\e[4mCommands\e[0m:" - - printf " %-30s %s\n\n" \ - "up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \ - "update [INPUT]" "Update and commit the lock file, or specific input" \ - "get (core|community) [DEST]" "Copy the desired template to DEST" \ - "iso HOST" "Generate an ISO image of HOST" \ - "install HOST [ARGS]" "Shortcut for nixos-install" \ - "home HOST USER [switch]" "Home-manager config of USER from HOST" \ - "HOST (switch|boot|test)" "Shortcut for nixos-rebuild" -} - -case "$1" in - ""|"-h"|"help"|*(-)"help") - usage - ;; - - "up") - mkdir -p "$DEVSHELL_ROOT/up" - - nixos-generate-config --dir "$DEVSHELL_ROOT/up/$HOSTNAME" - - printf "%s\n" \ - "{ suites, ... }:" \ - "{" \ - " imports = [" \ - " ../up/$HOSTNAME/configuration.nix" \ - " ] ++ suites.core;" \ - "}" > "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" - - git add -f \ - "$DEVSHELL_ROOT/up/$HOSTNAME" \ - "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" - ;; - - "update") - if [[ -n "$2" ]]; then - if [[ -n "$3" ]]; then - (cd $2; nix flake list-inputs --update-input "$3") - else - (cd $2; nix flake update) - fi - nix flake list-inputs --update-input "$2" "$DEVSHELL_ROOT" - else - nix flake update "$DEVSHELL_ROOT" - fi - ;; - - "get") - if [[ "$2" == "core" || "$2" == "community" ]]; then - nix flake new -t "github:divnix/devos/$2" "${3:-flk}" - else - echo "flk get (core|community) [DEST]" - exit 1 - fi - ;; - - "iso") - nix build \ - "$DEVSHELL_ROOT#nixosConfigurations.$2.config.system.build.iso" \ - "${@:3}" - ;; - - "install") - sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${@:3}" - ;; - - "home") - ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.activationPackage" - - if [[ "$4" == "switch" ]]; then - nix build "$ref" && result/activate && - unlink result - - else - nix build "$ref" "${@:4}" - fi - ;; - - *) - sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${@:2}" - ;; -esac diff --git a/lib/pkgs-lib/shell/pre-commit.sh b/lib/pkgs-lib/shell/pre-commit.sh deleted file mode 100755 index 985d3b4..0000000 --- a/lib/pkgs-lib/shell/pre-commit.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=$(${git}/bin/git hash-object -t tree /dev/null) -fi - -diff="git diff-index --name-only --cached $against --diff-filter d" - -nix_files=($($diff -- '*.nix')) -all_files=($($diff)) - -# Format staged nix files. -if [[ -n "${nix_files[@]}" ]]; then - nixpkgs-fmt "${nix_files[@]}" \ - && git add "${nix_files[@]}" -fi - -# check editorconfig -editorconfig-checker -- "${all_files[@]}" -if [[ $? != '0' ]]; then - printf "%b\n" \ - "\nCode is not aligned with .editorconfig" \ - "Review the output and commit your fixes" >&2 - exit 1 -fi diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix deleted file mode 100644 index e08702a..0000000 --- a/lib/pkgs-lib/tests/default.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ lib, deploy }: -let - mkChecks = { pkgs, hosts, nodes, homes ? { } }: - let - deployHosts = lib.filterAttrs - (n: _: hosts.${n}.config.nixpkgs.system == pkgs.system) - nodes; - deployChecks = deploy.lib.${pkgs.system}.deployChecks { nodes = deployHosts; }; - tests = - lib.optionalAttrs (deployHosts != { }) - { - profilesTest = profilesTest { - inherit pkgs; - host = hosts.${(builtins.head (builtins.attrNames deployHosts))}; - }; - } // lib.mapAttrs (n: v: v.activationPackage) homes; - - in - lib.recursiveUpdate tests deployChecks; - - mkTest = { pkgs, host }: - let - nixosTesting = - (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { - inherit (pkgs) system; - inherit (host.config.lib.builderArgs) specialArgs; - inherit pkgs; - extraConfigurations = host._module.args.modules; - }); - in - test: - let - loadedTest = - if builtins.typeOf test == "path" - then import test - else test; - calledTest = - if pkgs.lib.isFunction loadedTest - then pkgs.callPackage loadedTest { } - else loadedTest; - in - nixosTesting.makeTest calledTest; - - profilesTest = args@{ host, ... }: mkTest args { - name = "profiles"; - - machine = { suites, ... }: { - imports = suites.allProfiles; - }; - - testScript = '' - ${host.config.networking.hostName}.systemctl("is-system-running --wait") - ''; - }; -in -{ inherit mkTest profilesTest mkChecks; } diff --git a/lib/pkgs-lib/tests/lib.nix b/lib/pkgs-lib/tests/lib.nix deleted file mode 100644 index 586eac3..0000000 --- a/lib/pkgs-lib/tests/lib.nix +++ /dev/null @@ -1,93 +0,0 @@ -{ pkgs, lib, ... }: -with lib; -lib.runTests { - testConcatAttrs = { - expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; - - expected = { foo = 1; bar = 2; baz = 3; }; - }; - - testGenAttrs' = { - expr = genAttrs' - [ "/foo/bar" "/baz/buzz" ] - (path: { - name = baseNameOf path; - value = "${path}/fizz"; - }); - - expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; }; - }; - - testMapFilterAttrs = { - expr = mapFilterAttrs - (n: v: n == "foobar" && v == 1) - (n: v: lib.nameValuePair ("${n}bar") (v + 1)) - { foo = 0; bar = 2; }; - - expected = { foobar = 1; }; - }; - - testPathsIn = { - expr = pathsIn (toString ./testPathsIn); - - expected = map toString [ - ./testPathsIn/bar - ./testPathsIn/baz - ./testPathsIn/foo - ]; - }; - - testPathsToImportedAttrs = { - expr = - pathsToImportedAttrs [ - (toString ./testPathsToImportedAttrs/dir) - ./testPathsToImportedAttrs/foo.nix - ./testPathsToImportedAttrs/bar.nix - ./testPathsToImportedAttrs/t.nix - ./testPathsToImportedAttrs/f.nix - ]; - - expected = { - dir = { a = 5; }; - foo = { bar = 1; }; - bar = { foo = 2; }; - t = true; - f = false; - }; - }; - - testRgxToString = lib.testAllTrue [ - (rgxToString ".+x" "vxk" == "vx") - (rgxToString "^fo" "foo" == "fo") - (rgxToString "a?" "a" == "a") - (rgxToString "hat" "foohatbar" == "hat") - ]; - - testSafeReadDir = { - expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir; - expected = { - foo = "directory"; - t = "directory"; - }; - }; - - testSuites = - let - profiles = os.mkProfileAttrs (toString ./profiles); - users = ""; - userProfiles = ""; - suites = { profiles, ... }: { - system.bar = [ profiles.foo ]; - }; - in - { - expr = os.mkSuites { inherit profiles users userProfiles suites; }; - expected = { - system = { - bar = [ profiles.foo.default ]; - allProfiles = [ profiles.foo.default profiles.t.default ]; - allUsers = [ ]; - }; - }; - }; -} diff --git a/lib/strings.nix b/lib/strings.nix deleted file mode 100644 index d411bab..0000000 --- a/lib/strings.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib }: -{ - # returns matching part of _regex_ _string_; null indicates failure. - rgxToString = regex: string: - let - match = - let - head = lib.substring 0 1 regex; - sec = lib.substring 1 2 regex; - in - if head == "^" - || head == "." - || (sec == "*" || sec == "+" || sec == "?") - then builtins.match "(${regex}).*" string - else builtins.match ".*(${regex}).*" string; - in - if lib.isList match - then lib.head match - else null; -} diff --git a/lib/tests/default.nix b/lib/tests/default.nix deleted file mode 100644 index ab4d516..0000000 --- a/lib/tests/default.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ pkgs, lib }: - -pkgs.runCommandNoCC "devos-lib-tests" -{ - buildInputs = [ - pkgs.nix - ( - let tests = import ./lib.nix { inherit pkgs lib; }; in - if tests == [ ] then null - else throw (builtins.toJSON tests) - ) - ]; -} '' - datadir="${pkgs.nix}/share" - export TEST_ROOT=$(pwd)/test-tmp - export NIX_BUILD_HOOK= - export NIX_CONF_DIR=$TEST_ROOT/etc - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix - export NIX_STATE_DIR=$TEST_ROOT/var/nix - export NIX_STORE_DIR=$TEST_ROOT/store - export PAGER=cat - cacheDir=$TEST_ROOT/binary-cache - nix-store --init - - touch $out -'' diff --git a/lib/tests/lib.nix b/lib/tests/lib.nix deleted file mode 100644 index 78536e7..0000000 --- a/lib/tests/lib.nix +++ /dev/null @@ -1,70 +0,0 @@ -{ pkgs, lib }: -with lib; -lib.runTests { - testConcatAttrs = { - expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }]; - - expected = { foo = 1; bar = 2; baz = 3; }; - }; - - testGenAttrs' = { - expr = genAttrs' - [ "/foo/bar" "/baz/buzz" ] - (path: { - name = baseNameOf path; - value = "${path}/fizz"; - }); - - expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; }; - }; - - testMapFilterAttrs = { - expr = mapFilterAttrs - (n: v: n == "foobar" && v == 1) - (n: v: lib.nameValuePair ("${n}bar") (v + 1)) - { foo = 0; bar = 2; }; - - expected = { foobar = 1; }; - }; - - testPathsIn = { - expr = pathsIn (toString ./testPathsIn); - - expected = map toString [ - ./testPathsIn/bar - ./testPathsIn/baz - ./testPathsIn/foo - ]; - }; - - testRgxToString = lib.testAllTrue [ - (rgxToString ".+x" "vxk" == "vx") - (rgxToString "^fo" "foo" == "fo") - (rgxToString "a?" "a" == "a") - (rgxToString "hat" "foohatbar" == "hat") - ]; - - testSafeReadDir = { - expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir; - expected = { - foo = "directory"; - t = "directory"; - }; - }; - - testSuites = { - expr = mkSuites { - suites = { profiles, ... }: with profiles; { - bar = [ foo ]; - }; - profiles = [ (./profiles) ]; - }; - expected = { - bar = [ (toString ./profiles/foo) ]; - allProfiles = [ - (toString ./profiles/foo) - (toString ./profiles/t) - ]; - }; - }; -} diff --git a/lib/tests/profiles/foo/default.nix b/lib/tests/profiles/foo/default.nix deleted file mode 100644 index 2181e56..0000000 --- a/lib/tests/profiles/foo/default.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ - bar = 5; -} diff --git a/lib/tests/profiles/t/default.nix b/lib/tests/profiles/t/default.nix deleted file mode 100644 index 8b13789..0000000 --- a/lib/tests/profiles/t/default.nix +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/tests/testPathsIn/bar b/lib/tests/testPathsIn/bar deleted file mode 100644 index e69de29..0000000 diff --git a/lib/tests/testPathsIn/baz b/lib/tests/testPathsIn/baz deleted file mode 100644 index e69de29..0000000 diff --git a/lib/tests/testPathsIn/foo b/lib/tests/testPathsIn/foo deleted file mode 100644 index e69de29..0000000 diff --git a/lib/tests/testPathsToImportedAttrs/bar.nix b/lib/tests/testPathsToImportedAttrs/bar.nix deleted file mode 100644 index 0e5233d..0000000 --- a/lib/tests/testPathsToImportedAttrs/bar.nix +++ /dev/null @@ -1 +0,0 @@ -{ foo = 2; } diff --git a/lib/tests/testPathsToImportedAttrs/dir/default.nix b/lib/tests/testPathsToImportedAttrs/dir/default.nix deleted file mode 100644 index 01cb926..0000000 --- a/lib/tests/testPathsToImportedAttrs/dir/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ a = 5; } diff --git a/lib/tests/testPathsToImportedAttrs/f.nix b/lib/tests/testPathsToImportedAttrs/f.nix deleted file mode 100644 index c4d456a..0000000 --- a/lib/tests/testPathsToImportedAttrs/f.nix +++ /dev/null @@ -1 +0,0 @@ -true && false diff --git a/lib/tests/testPathsToImportedAttrs/foo.nix b/lib/tests/testPathsToImportedAttrs/foo.nix deleted file mode 100644 index 2f11bd3..0000000 --- a/lib/tests/testPathsToImportedAttrs/foo.nix +++ /dev/null @@ -1 +0,0 @@ -{ bar = 1; } diff --git a/lib/tests/testPathsToImportedAttrs/t.nix b/lib/tests/testPathsToImportedAttrs/t.nix deleted file mode 100644 index 3be59dc..0000000 --- a/lib/tests/testPathsToImportedAttrs/t.nix +++ /dev/null @@ -1 +0,0 @@ -true || false From f4cd79194afdb9f965d9cc5521705d920e1e62f8 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 4 May 2021 21:49:16 -0700 Subject: [PATCH 108/137] add in-tree local lib, ourlib --- flake.nix | 5 ++++- lib/default.nix | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 8dc8e7e..90f84fc 100644 --- a/flake.nix +++ b/flake.nix @@ -44,9 +44,11 @@ latest = { }; }; + lib = import ./lib { lib = devlib.lib // nixos.lib; }; + sharedOverlays = [ (final: prev: { - ourlib = prev.devlib.extend (import ./lib); + ourlib = self.lib; }) ]; @@ -56,6 +58,7 @@ channelName = "nixos"; modules = ./modules/module-list.nix; externalModules = [ + { _module.args.ourlib = self.lib; } ci-agent.nixosModules.agent-profile home.nixosModules.home-manager ./modules/customBuilds.nix diff --git a/lib/default.nix b/lib/default.nix index c4da46c..2356e1f 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,2 +1,2 @@ -lfinal: lprev: { -} +{ lib }: +lib.makeExtensible (self: { }) From 6e906e87bc07b593ea66066a807b744f54035e77 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:17:41 -0700 Subject: [PATCH 109/137] doc/extern: improve overlay filtering explanation Co-authored-by: David Arnold --- doc/concepts/extern.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index 171d8c5..ba24918 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -13,7 +13,7 @@ flake.nix: channels.nixos.overlays = [ inputs.agenix.overlay ]; } ``` -These overlays will be automatically filtered by inspecting the `inputs` argument. +Upon exporting overlays, these overlays will be automatically filtered out by inspecting the `inputs` argument. ## Modules There is a dedicated `nixos.hostDefaults.externalModules` argument for external From 8f20bb069a082fb9ec7c6c1c64768b3db8e28df7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:19:31 -0700 Subject: [PATCH 110/137] doc/extern: elaborate external modules filtering Co-authored-by: David Arnold --- doc/concepts/extern.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concepts/extern.md b/doc/concepts/extern.md index ba24918..45d8dcb 100644 --- a/doc/concepts/extern.md +++ b/doc/concepts/extern.md @@ -38,5 +38,5 @@ flake.nix: ``` > ##### Note: -> The optimal solution would be to automatically export modules that were created in +> To avoid declaring "external" modules separately, which is obvious since they come from `inputs`, the optimal solution would be to automatically export modules that were created in > your flake. But this is not possible due to NixOS/nix#4740. From 725e459655d6695a7a2d998e9e8ad13a13a98a74 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 10 May 2021 12:22:16 -0700 Subject: [PATCH 111/137] doc/start: fix grammar Co-authored-by: David Arnold --- doc/start/from-nixos.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/start/from-nixos.md b/doc/start/from-nixos.md index a25fb99..0e1d48c 100644 --- a/doc/start/from-nixos.md +++ b/doc/start/from-nixos.md @@ -20,7 +20,7 @@ You must then add a host to `nixos.hosts` in flake.nix: ``` Make sure your `i18n.defaultLocale` and `time.timeZone` are set properly for -your region. Keep in mind that `networking.hostName` with be automatically +your region. Keep in mind that `networking.hostName` will be automatically set to the name of your host; Now might be a good time to read the docs on [suites](../concepts/suites.md) and @@ -52,4 +52,3 @@ This calls `nixos-rebuild` with sudo to build and install your configuration. > simply `sudo nixos-rebuild switch` from anywhere on the system, but it is > not required. - From 8a590c9fefa893dd738bc3161052ac9ea5c72c80 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 11:40:37 -0700 Subject: [PATCH 112/137] core: use self for nixos-option compat path --- profiles/core/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles/core/default.nix b/profiles/core/default.nix index aa3290c..41b5136 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ self, config, lib, pkgs, ... }: let inherit (lib) fileContents; in { @@ -76,7 +76,7 @@ in ''; # fix nixos-option - nixos-option = "nixos-option -I nixpkgs=${toString ../../lib/compat}"; + nixos-option = "nixos-option -I nixpkgs=${self}/lib/compat"; # sudo s = ifSudo "sudo -E "; From 0d7eb1c48840c99c24512833d157168201f2b2e3 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 11:44:05 -0700 Subject: [PATCH 113/137] doc/lib: explain ourlib usage --- doc/lib.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/lib.md b/doc/lib.md index ed19b1a..ee402eb 100644 --- a/doc/lib.md +++ b/doc/lib.md @@ -3,8 +3,7 @@ The lib directory mirrors the upstream concepts of [`nixpkgs:./lib`][nixpkgs-lib [`nixpkgs:./nixos/lib`][nixpkgs-nixos-lib] and [`nixpkgs:./pkgs/pkgs-lib`][nixpkgs-pkgs-lib], but also occasionally [`nixpkgs:./pkgs/build-support`][nixpkgs-pkgs-build-support]. -It comes with functions necesary to declutter `devos` itself, but you are -welcome to extend it to your needs. +All functions defined in lib can be accessed in modules and packages as `ourlib`. For example: From a081a922a5f1816e1f3bb0d4d0a3851d5961f89c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 11 May 2021 23:41:34 -0700 Subject: [PATCH 114/137] flake: update devlib input drop ca experimental features and filterPackages improvements --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index db2f914..4a98d12 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620188794, - "narHash": "sha256-BDwtrbUkrSnBQJBXuaJg9QBu3MYL0iuJPE8P30o0x7I=", + "lastModified": 1620801549, + "narHash": "sha256-8a5eqj6neVdRiBzF6xWEqwGWhlGBSgE65q9E6B+DDkA=", "owner": "divnix", "repo": "devlib", - "rev": "ffda6add9eb984d986cf5b6a838a52334317302f", + "rev": "738b9bd0b587b0dfb92206c1beb68f43adfdc234", "type": "github" }, "original": { @@ -141,11 +141,11 @@ }, "flake-utils": { "locked": { - "lastModified": 1619345332, - "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "lastModified": 1620759905, + "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", "owner": "numtide", "repo": "flake-utils", - "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", "type": "github" }, "original": { @@ -355,11 +355,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1619714004, - "narHash": "sha256-xoP81rWAM2cVpEFrQv9sUEIvNxGXAg4UH9kBt83a5u4=", + "lastModified": 1620801141, + "narHash": "sha256-XPJ+/nP/s218E11R+4LJyvkrQXvdT3D6TzNjfWVYZnI=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "0642ac572a87a0beb78a7c6ddce1267aa5817d05", + "rev": "1a742047f3f7c97b22768ba7738ac5a01052099e", "type": "github" }, "original": { From 858e8546fe799ac42a23bec5701dbb93f23cc6fb Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 08:17:40 -0700 Subject: [PATCH 115/137] flake: update devlib input includes ability to customize shell from template --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 4a98d12..b530dc7 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620801549, - "narHash": "sha256-8a5eqj6neVdRiBzF6xWEqwGWhlGBSgE65q9E6B+DDkA=", + "lastModified": 1620832565, + "narHash": "sha256-6K+ZPoIQwaVP1hYER3PUxDxs4TTEilfQ+VoJWnEfd3Q=", "owner": "divnix", "repo": "devlib", - "rev": "738b9bd0b587b0dfb92206c1beb68f43adfdc234", + "rev": "454b01d875bb8a31bb3d669366462e7fd978b963", "type": "github" }, "original": { From 2b73d3bf53b35256faa30ad7dc3431ecbb78d634 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 11:43:27 -0700 Subject: [PATCH 116/137] customBuilds: add TODO to drop builderArgs --- modules/customBuilds.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix index b9648dc..59ae524 100644 --- a/modules/customBuilds.nix +++ b/modules/customBuilds.nix @@ -1,6 +1,7 @@ { lib, self, devlib, config, modules, channel, ... }: let mkBuild = buildModule: + # TODO: get specialArgs as a module argument and drop builderArgs usage channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { modules = [ buildModule ]; }); From 3ee831f8529f123c66f94901accedff8ab5428e1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 12:29:00 -0700 Subject: [PATCH 117/137] flake.nix: explicitly append overlays from path Co-authored-by: David Arnold --- flake.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 90f84fc..0705534 100644 --- a/flake.nix +++ b/flake.nix @@ -34,8 +34,9 @@ channels = { nixos = { - overlays = [ - (devlib.lib.pathsIn ./overlays) + overlays = + (devlib.lib.importers.pathsIn ./overlays) ++ + [ ./pkgs/default.nix pkgs.overlay # for `srcs` nur.overlay From 67f545123c994c96fe0752d7964e621c9178f2b7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 12:31:43 -0700 Subject: [PATCH 118/137] flake: format and update to devlib api changes --- flake.lock | 6 +++--- flake.nix | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index b530dc7..c080704 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620832565, - "narHash": "sha256-6K+ZPoIQwaVP1hYER3PUxDxs4TTEilfQ+VoJWnEfd3Q=", + "lastModified": 1620845932, + "narHash": "sha256-ShC2IuJD1MHC0DtQWeUuWpD1HDL7cuK3oBWQmVqjmdk=", "owner": "divnix", "repo": "devlib", - "rev": "454b01d875bb8a31bb3d669366462e7fd978b963", + "rev": "5a04146dc08f0a15a4489babe584162fdde1ca1f", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 0705534..d8fd366 100644 --- a/flake.nix +++ b/flake.nix @@ -37,10 +37,10 @@ overlays = (devlib.lib.importers.pathsIn ./overlays) ++ [ - ./pkgs/default.nix - pkgs.overlay # for `srcs` - nur.overlay - ]; + ./pkgs/default.nix + pkgs.overlay # for `srcs` + nur.overlay + ]; }; latest = { }; }; @@ -66,7 +66,7 @@ ]; }; hosts = nixos.lib.mkMerge [ - (devlib.lib.importHosts ./hosts) + (devlib.lib.importers.importHosts ./hosts) { /* set host specific properties here */ } ]; profiles = [ ./profiles ./users ]; From c89dfed81c37bde4ebe5db96f3b8db83f8eea672 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 12 May 2021 19:18:11 -0700 Subject: [PATCH 119/137] don't import cachix in suites its already imported in the core profile --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d8fd366..02ef12a 100644 --- a/flake.nix +++ b/flake.nix @@ -71,7 +71,7 @@ ]; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { - base = [ cachix core users.nixos users.root ]; + base = [ core users.nixos users.root ]; }; }; From 7793ab42da34c77d14f58226190c5949de133738 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 13 May 2021 16:59:52 -0700 Subject: [PATCH 120/137] flake: update devlib input includes nixos option improvements and importHosts change --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index c080704..3e6b0f3 100644 --- a/flake.lock +++ b/flake.lock @@ -79,11 +79,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1620845932, - "narHash": "sha256-ShC2IuJD1MHC0DtQWeUuWpD1HDL7cuK3oBWQmVqjmdk=", + "lastModified": 1620950194, + "narHash": "sha256-3fh8kUxZ/by7QP7vop+C+X6nj/YzYHnld9epGbRWKQ0=", "owner": "divnix", "repo": "devlib", - "rev": "5a04146dc08f0a15a4489babe584162fdde1ca1f", + "rev": "213afcefb2db0bb5fd3fad871303c43b158d8204", "type": "github" }, "original": { From ccc0fc97fe168e13d8c9cb7374f91e2b326a63d8 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 13 May 2021 17:03:51 -0700 Subject: [PATCH 121/137] flake.nix: use `imports` for auto-import of hosts This makes the auto-importing of hosts obvious and explicitly indicates how the options would end up getting merged. --- flake.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 02ef12a..59d9155 100644 --- a/flake.nix +++ b/flake.nix @@ -65,10 +65,12 @@ ./modules/customBuilds.nix ]; }; - hosts = nixos.lib.mkMerge [ - (devlib.lib.importers.importHosts ./hosts) - { /* set host specific properties here */ } - ]; + + imports = [ (devlib.lib.importers.importHosts ./hosts) ]; + hosts = { + /* set host specific properties here */ + NixOS = { }; + }; profiles = [ ./profiles ./users ]; suites = { profiles, users, ... }: with profiles; { base = [ core users.nixos users.root ]; From 923ce7feff875706adb1d336fb959fbdb06b3f14 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 10:17:53 -0700 Subject: [PATCH 122/137] tree: rename devlib -> digga --- flake.lock | 77 +++++++++++++++++++++++++++------------- flake.nix | 19 +++++----- modules/customBuilds.nix | 6 ++-- 3 files changed, 64 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index 3e6b0f3..a4e7fd6 100644 --- a/flake.lock +++ b/flake.lock @@ -69,29 +69,6 @@ "type": "github" } }, - "devlib": { - "inputs": { - "deploy": "deploy", - "devshell": "devshell", - "nixpkgs": [ - "nixos" - ], - "utils": "utils_2" - }, - "locked": { - "lastModified": 1620950194, - "narHash": "sha256-3fh8kUxZ/by7QP7vop+C+X6nj/YzYHnld9epGbRWKQ0=", - "owner": "divnix", - "repo": "devlib", - "rev": "213afcefb2db0bb5fd3fad871303c43b158d8204", - "type": "github" - }, - "original": { - "owner": "divnix", - "repo": "devlib", - "type": "github" - } - }, "devshell": { "locked": { "lastModified": 1618523768, @@ -107,6 +84,28 @@ "type": "github" } }, + "digga": { + "inputs": { + "deploy": "deploy", + "devshell": "devshell", + "nixlib": "nixlib", + "nixpkgs": "nixpkgs_2", + "utils": "utils_2" + }, + "locked": { + "lastModified": 1621012625, + "narHash": "sha256-xRBbDpQDUz3mSwL2WoePz6c3zIUtZ2ML3qW0B9CVspU=", + "owner": "divnix", + "repo": "digga", + "rev": "b0de71f4924e513e21d21a0ec60a2cb180f2187c", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "digga", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -229,6 +228,21 @@ "type": "github" } }, + "nixlib": { + "locked": { + "lastModified": 1620519687, + "narHash": "sha256-+6Dd72b2CASuXm2W7KRxZIE7AOy/dj4mU28vaF+zxcs=", + "owner": "divnix", + "repo": "nixpkgs.lib", + "rev": "c7b6169809c5f74dd0c34f3d69e9d12ba4d448de", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixos": { "locked": { "lastModified": 1615797423, @@ -275,6 +289,21 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1620962350, + "narHash": "sha256-9ASW4d4/Z8HmRvuJI8rxbEOTbXTBpQ8y+CmFYBwtXzE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5d4a430472cafada97888cc80672fab255231f57", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, "nur": { "locked": { "lastModified": 1615921934, @@ -325,7 +354,7 @@ "inputs": { "ci-agent": "ci-agent", "darwin": "darwin", - "devlib": "devlib", + "digga": "digga", "home": "home", "latest": "latest", "naersk": "naersk_2", diff --git a/flake.nix b/flake.nix index 59d9155..212df34 100644 --- a/flake.nix +++ b/flake.nix @@ -5,10 +5,7 @@ { nixos.url = "nixpkgs/nixos-unstable"; latest.url = "nixpkgs"; - devlib.url = "github:divnix/devlib"; - devlib.inputs = { - nixpkgs.follows = "nixos"; - }; + digga.url = "github:divnix/digga"; ci-agent = { url = "github:hercules-ci/hercules-ci-agent"; @@ -26,8 +23,8 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ self, pkgs, devlib, nixos, ci-agent, home, nixos-hardware, nur, ... }: - devlib.lib.mkFlake { + outputs = inputs@{ self, pkgs, digga, nixos, ci-agent, home, nixos-hardware, nur, ... }: + digga.lib.mkFlake { inherit self inputs; channelsConfig = { allowUnfree = true; }; @@ -35,7 +32,7 @@ channels = { nixos = { overlays = - (devlib.lib.importers.pathsIn ./overlays) ++ + (digga.lib.importers.pathsIn ./overlays) ++ [ ./pkgs/default.nix pkgs.overlay # for `srcs` @@ -45,7 +42,7 @@ latest = { }; }; - lib = import ./lib { lib = devlib.lib // nixos.lib; }; + lib = import ./lib { lib = digga.lib // nixos.lib; }; sharedOverlays = [ (final: prev: { @@ -66,7 +63,7 @@ ]; }; - imports = [ (devlib.lib.importers.importHosts ./hosts) ]; + imports = [ (digga.lib.importers.importHosts ./hosts) ]; hosts = { /* set host specific properties here */ NixOS = { }; @@ -86,9 +83,9 @@ }; }; - homeConfigurations = devlib.lib.mkHomeConfigurations self.nixosConfigurations; + homeConfigurations = digga.lib.mkHomeConfigurations self.nixosConfigurations; - deploy.nodes = devlib.lib.mkDeployNodes self.nixosConfigurations { }; + deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { }; #defaultTemplate = self.templates.flk; templates.flk.path = ./.; diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix index 59ae524..875d23a 100644 --- a/modules/customBuilds.nix +++ b/modules/customBuilds.nix @@ -1,14 +1,14 @@ -{ lib, self, devlib, config, modules, channel, ... }: +{ lib, self, diggaLib, config, modules, channel, ... }: let mkBuild = buildModule: # TODO: get specialArgs as a module argument and drop builderArgs usage - channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { + channel.input.lib.nixosSystem (diggaLib.mergeAny config.lib.builderArgs { modules = [ buildModule ]; }); in { system.build = { - iso = (mkBuild (devlib.modules.isoConfig { + iso = (mkBuild (diggaLib.modules.isoConfig { inherit self; inherit (self) inputs; fullHostConfig = config; From dd6c481791cf38f5feb408253e40490ccd7d7716 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 11:01:44 -0700 Subject: [PATCH 123/137] flake: format ourlib for consistency with digga --- flake.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 212df34..ffce39c 100644 --- a/flake.nix +++ b/flake.nix @@ -46,7 +46,9 @@ sharedOverlays = [ (final: prev: { - ourlib = self.lib; + lib = prev.lib.extend (lfinal: lprev: { + our = self.lib; + }); }) ]; @@ -56,7 +58,7 @@ channelName = "nixos"; modules = ./modules/module-list.nix; externalModules = [ - { _module.args.ourlib = self.lib; } + { _module.args.ourLib = self.lib; } ci-agent.nixosModules.agent-profile home.nixosModules.home-manager ./modules/customBuilds.nix From 2f474e37f72121679a720445385aea677a7adadc Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 16:49:12 -0700 Subject: [PATCH 124/137] flake: update to latest digga api allows overlays to also be used with `imports` and renames importHosts --- flake.lock | 6 +++--- flake.nix | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/flake.lock b/flake.lock index a4e7fd6..2195b9a 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1621012625, - "narHash": "sha256-xRBbDpQDUz3mSwL2WoePz6c3zIUtZ2ML3qW0B9CVspU=", + "lastModified": 1621027569, + "narHash": "sha256-ugwMMfZagrWnt6yw+k1YGbydoMQ0OTYJ3WJ1kncsKCg=", "owner": "divnix", "repo": "digga", - "rev": "b0de71f4924e513e21d21a0ec60a2cb180f2187c", + "rev": "c162f5f46206346f431f3905642a8a9f17d42217", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ffce39c..6b6860f 100644 --- a/flake.nix +++ b/flake.nix @@ -31,13 +31,12 @@ channels = { nixos = { - overlays = - (digga.lib.importers.pathsIn ./overlays) ++ - [ - ./pkgs/default.nix - pkgs.overlay # for `srcs` - nur.overlay - ]; + imports = [ (digga.lib.importers.overlays ./overlays) ]; + overlays = [ + ./pkgs/default.nix + pkgs.overlay # for `srcs` + nur.overlay + ]; }; latest = { }; }; @@ -65,7 +64,7 @@ ]; }; - imports = [ (digga.lib.importers.importHosts ./hosts) ]; + imports = [ (digga.lib.importers.hosts ./hosts) ]; hosts = { /* set host specific properties here */ NixOS = { }; From 634cfcb30162b18f194cb2ca90a54a5c937cba3c Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 21:27:49 -0700 Subject: [PATCH 125/137] flake: update digga includes fix for flk config generation --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 2195b9a..5dd2560 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1621027569, - "narHash": "sha256-ugwMMfZagrWnt6yw+k1YGbydoMQ0OTYJ3WJ1kncsKCg=", + "lastModified": 1621048725, + "narHash": "sha256-LVQOLO56xuBAlElxikU3Qvw1BMB3914HN+QePls0yl0=", "owner": "divnix", "repo": "digga", - "rev": "c162f5f46206346f431f3905642a8a9f17d42217", + "rev": "04c4bdd1d1449168307d6262631466d59b9ed3bd", "type": "github" }, "original": { From 00f8b477a60deaeb25855b409cf9dc0daaf0de96 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Fri, 14 May 2021 22:49:39 -0700 Subject: [PATCH 126/137] bors.toml: don't delete merged branches This caused develop to be deleted. And if most people send PR's from forks of devos, this line doesn't really help much. --- bors.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/bors.toml b/bors.toml index 72690c0..6703d41 100644 --- a/bors.toml +++ b/bors.toml @@ -3,5 +3,3 @@ status = [ "check" ] required_approvals = 1 up_to_date_approvals = true - -delete_merged_branches = true From 2ab4df3f600faae4c5f3c658c717827602fb0136 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 15 May 2021 10:31:54 -0700 Subject: [PATCH 127/137] suites: re-add `rec` to simplify suite definitions --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 6b6860f..535c717 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,7 @@ NixOS = { }; }; profiles = [ ./profiles ./users ]; - suites = { profiles, users, ... }: with profiles; { + suites = { profiles, users, ... }: with profiles; rec { base = [ core users.nixos users.root ]; }; }; @@ -79,7 +79,7 @@ modules = ./users/modules/module-list.nix; externalModules = [ ]; profiles = [ ./users/profiles ]; - suites = { profiles, ... }: with profiles; { + suites = { profiles, ... }: with profiles; rec { base = [ direnv git ]; }; }; From 5151380d61c30851ffabe29b45213af5ec981e65 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 16 May 2021 10:22:40 -0700 Subject: [PATCH 128/137] default.nix: fix path to compat --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 5d437c7..0e6bdee 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ let inherit (default.inputs.nixos) lib; - default = (import "${./lib}/compat").defaultNix; + default = (import ./lib/compat).defaultNix; ciSystems = [ "aarch64-linux" From 18d4c78ea5ae926284636d068692c9b23e33caeb Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 16 May 2021 19:35:52 -0700 Subject: [PATCH 129/137] flake: un-comment defaultTemplate This was accidentally commented. fixes #288 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 535c717..27024b0 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { }; - #defaultTemplate = self.templates.flk; + defaultTemplate = self.templates.flk; templates.flk.path = ./.; templates.flk.description = "flk template"; From cf47170d6f703906aa546dfee29f2083701a82ef Mon Sep 17 00:00:00 2001 From: Narice Date: Mon, 17 May 2021 10:46:02 +0200 Subject: [PATCH 130/137] Modified wording of iso documentation --- doc/start/iso.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/start/iso.md b/doc/start/iso.md index 5a0ecf3..efa515a 100644 --- a/doc/start/iso.md +++ b/doc/start/iso.md @@ -12,13 +12,13 @@ This works for any file matching `hosts/*.nix` excluding `default.nix`. ## ISO image nix store & cache -The iso image holds the store to the live environment and _also_ acts as a binay cache +The iso image holds the store to the live environment and _also_ acts as a binary cache to the installer. To considerably speed up things, the image already includes all flake `inputs` as well as the `devshell` closures. -While you _could_ provision any machine with a single stick, a bespoke iso maximises -those local cache hits. +While you _could_ provision any machine with a single stick, a custom-made iso for +the host you want to install DevOS to, maximises those local cache hits. -For hosts that don't differ too much, a common usb stick might be ok, whereas when -there are bigger differences, a bespoke usb stick will be considerably faster. +For hosts that don't differ too much, a single usb stick might be ok, whereas when +there are bigger differences, a custom-made usb stick will be considerably faster. From 629a50975fab9e85aefa5c43a13ed55c48555339 Mon Sep 17 00:00:00 2001 From: Yannick Markus Date: Tue, 18 May 2021 18:11:29 +0200 Subject: [PATCH 131/137] hosts doc: fix hardware module in example --- doc/concepts/hosts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index 1fa9028..b8cc849 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -38,7 +38,7 @@ flake.nix: { librem = { channelName = "latest"; - modules = [ hardware.purism-librem-13v3 ]; + modules = [ nixos-hardware.nixosModules.purism-librem-13v3 ]; }; } ]; From 564888d1fef8ff4b664a3be862d43eb2fef13159 Mon Sep 17 00:00:00 2001 From: Yannick Markus Date: Tue, 18 May 2021 18:12:36 +0200 Subject: [PATCH 132/137] remove profiles/suites.nix --- profiles/suites.nix | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 profiles/suites.nix diff --git a/profiles/suites.nix b/profiles/suites.nix deleted file mode 100644 index eadb20c..0000000 --- a/profiles/suites.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ users, profiles, userProfiles, ... }: - -{ - system = with profiles; rec { - base = [ core users.nixos users.root ]; - }; - user = with userProfiles; rec { - base = [ direnv git ]; - }; -} From adaf76e1fbd592d933149128f26d61a02f96a2c9 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 18 May 2021 10:23:43 -0700 Subject: [PATCH 133/137] doc/hosts: update to new auto-import style --- doc/concepts/hosts.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/concepts/hosts.md b/doc/concepts/hosts.md index b8cc849..37130f3 100644 --- a/doc/concepts/hosts.md +++ b/doc/concepts/hosts.md @@ -33,15 +33,15 @@ that you intend to use on your machine. flake.nix: ```nix { - nixos.hosts = mkMerge [ - (devos.lib.importHosts ./hosts) - { + nixos = { + imports = [ (devos.lib.importHosts ./hosts) ]; + hosts = { librem = { channelName = "latest"; modules = [ nixos-hardware.nixosModules.purism-librem-13v3 ]; }; - } - ]; + }; + }; } ``` From 21cba8024d0c26df0c999b1e92651f4086d372c1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 18 May 2021 11:29:56 -0700 Subject: [PATCH 134/137] flake: update digga input no longer builds all packages from overlays in devShell --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 5dd2560..b082071 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "utils": "utils_2" }, "locked": { - "lastModified": 1621048725, - "narHash": "sha256-LVQOLO56xuBAlElxikU3Qvw1BMB3914HN+QePls0yl0=", + "lastModified": 1621354376, + "narHash": "sha256-b597Jj8B1Nq4NX/Gl/+bYGKqJxpSfUtr1Nmp9m1DND8=", "owner": "divnix", "repo": "digga", - "rev": "04c4bdd1d1449168307d6262631466d59b9ed3bd", + "rev": "5ef9b8cabbc10c9b4fe5534107224c7241c63b3d", "type": "github" }, "original": { From a81930af36be9f78484ce16e95409f4f56064f93 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 19 May 2021 20:15:49 -0400 Subject: [PATCH 135/137] readme: declare it beta and update some other things --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ef7ed23..f347f4a 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ > maturing _well_ [for a while](https://github.com/divnix/devos/tree/17713c22d07c54525c728c62060a0428b76dee3b). # Introduction -DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for -personal and productive use. A sane repository structure is provided, +DevOS grants a simple template to use, deploy and manage [NixOS][nixos] systems +for personal and productive use. A sane repository structure is provided, integrating several popular projects like [home-manager][home-manager], [devshell][devshell], and [more](./doc/integrations). @@ -21,14 +21,17 @@ a [flake centric][flake-doc] approach is taken for useful conveniences such as Skip the indeterminate nature of other systems, _and_ the perceived tedium of bootstrapping Nix. It's easier than you think! -### Status: Alpha -A lot of the implementation is less than perfect, and huge -[redesigns](https://github.com/divnix/devos/issues/152) _will_ happen. There -are unstable versions (0._x_._x_) to help users keep track of changes and -progress. +### Status: Beta +Although this project has already matured quite a bit, especially through +recent outfactoring of [`digga`][digga], a fair amount of api polishing is still +expected. There are unstable versions (0._x_._x_) to help users keep track +of changes and progress. ## Getting Started Check out the [guide](https://devos.divnix.com/start) to get up and running. +Also, have a look at [_flake.nix_][toc]. If anything is not immediately +discoverable from there through [`digga`][digga] library's [`mkFlake`][mk-flake], +please file a bug report. ## In the Wild The author maintains his own branch, so you can take inspiration, direction, or @@ -43,12 +46,6 @@ and its satellite projects, from which best practices can evolve. ___The future is declarative! 🎉___ -## Upstream -I'd love to see this in the nix-community should anyone believe its reached a -point of maturity to be generally useful, but I'm all for waiting until -1.0[#121](https://github.com/divnix/devos/issues/121) to save the cache work, -too. - ## Community Profiles There are two branches from which to choose: [core][core] and [community][community]. The community branch builds on core and includes @@ -60,6 +57,22 @@ without building anything. This is especially useful for the packages that are [overridden](./concepts/overrides.md) from master, as without the cache, rebuilds are quite frequent. +## Shoulders +This work does not reinvent the wheel. It stands on the [shoulders of the +following giants][giants]: + +### :onion: — like the layers of an onion +- [`divnix/digga`][digga] +- [`gytis-ivaskevicius/flake-utils-plus`][fup] +- [`numtide/flake-utils`][fu] + +### :family: — like family +- [`numtide/devshell`][devshell] +- [`serokell/deploy-rs`][deploy] +- [`NixOS/nixpkgs`][nixpkgs] + +:heart: + ## Inspiration & Art - [hlissner/dotfiles][dotfiles] - [nix-user-chroot](https://github.com/nix-community/nix-user-chroot) @@ -67,9 +80,29 @@ rebuilds are quite frequent. - [Awesome Nix](https://github.com/nix-community/awesome-nix) - [devshell](https://github.com/numtide/devshell) +## Divnix +The divnix org is an open space that spontaniously formed out of "the Nix". +It is really just a place where otherwise unrelated people a) get +together and b) stuff done. + +It's a place to stop "geeking out in isolation" (or within company boundaries), +experiment and learn together and iterate quickly on best practices. That's what it is. + +It might eventually become a non-profit if that's not too complicated or if those +goals are sufficiently upstreamed into "the Nix", dissolved. + # License DevOS is licensed under the [MIT License][mit]. +[mk-flake]: https://github.com/divnix/digga/tree/master/src/mkFlake +[nixpkgs]: https://github.com/NixOS/nixpkgs +[deploy]: https://github.com/serokell/deploy-rs +[toc]: https://github.com/divnix/devos/blob/core/flake.nix +[giants]: https://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants +[digga]: https://github.com/divnix/digga +[fup]: https://github.com/gytis-ivaskevicius/flake-utils-plus +[fu]: https://github.com/numtide/flake-utils +[devshell]: https://github.com/numtide/devshell [nix]: https://nixos.org/manual/nix/stable [mit]: https://mit-license.org [nixos]: https://nixos.org/manual/nixos/stable @@ -79,5 +112,4 @@ DevOS is licensed under the [MIT License][mit]. [core]: https://github.com/divnix/devos [community]: https://github.com/divnix/devos/tree/community [dotfiles]: https://github.com/hlissner/dotfiles -[devshell]: https://github.com/numtide/devshell [please]: https://github.com/nrdxp/devos/tree/nrd From 20649fb3a9861734ff1507144499dff1083f85d1 Mon Sep 17 00:00:00 2001 From: Narice Date: Mon, 24 May 2021 10:28:52 +0200 Subject: [PATCH 136/137] Added note about cache in the start index This resolves #292. --- doc/start/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/start/index.md b/doc/start/index.md index 1cc252b..fbfab09 100644 --- a/doc/start/index.md +++ b/doc/start/index.md @@ -31,6 +31,8 @@ In addition, the [binary cache](../integrations/cachix.md) is added for faster d > files before building the system. > - You can choose to simply clone the repo with git if you want to follow > upstream changes. +> - If the `nix-shell -p cachix --run "cachix use nrdxp"` line doesn't work +> you can try with sudo: `sudo nix-shell -p cachix --run "cachix use nrdxp"` ## Next Steps: - [Make installable ISO](./iso.md) From 0f72f26a5750502ed505a57090b55dc53b879191 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Thu, 27 May 2021 17:02:40 +0000 Subject: [PATCH 137/137] Update Changelog for tag --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bbb678..b8d9a68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [v0.10.0](https://github.com/divnix/devos/tree/v0.10.0) (2021-05-24) + +**Implemented enhancements:** + +- Providing an interface to nixpkgs.config [\#237](https://github.com/divnix/devos/issues/237) +- Making the user available in profiles [\#230](https://github.com/divnix/devos/issues/230) +- copy evaluation store paths to iso [\#195](https://github.com/divnix/devos/issues/195) +- Extract custom system builds from devosSystem out of lib [\#170](https://github.com/divnix/devos/issues/170) +- Allow setting of channel host-wide [\#117](https://github.com/divnix/devos/issues/117) +- alacritty: CSIu support [\#51](https://github.com/divnix/devos/issues/51) + +**Fixed bugs:** + +- Cachix timeouts + how to disable nrdxp cachix \(if needed\) [\#294](https://github.com/divnix/devos/issues/294) +- default.nix flake-compat is broken [\#285](https://github.com/divnix/devos/issues/285) +- All suites return "attribute missing" [\#282](https://github.com/divnix/devos/issues/282) +- nix is built two times [\#203](https://github.com/divnix/devos/issues/203) +- fix lib docs [\#166](https://github.com/divnix/devos/issues/166) + +**Closed issues:** + +- eliminate userFlakeNixOS [\#257](https://github.com/divnix/devos/issues/257) +- devos-as-library [\#214](https://github.com/divnix/devos/issues/214) + +**Merged pull requests:** + +- Update evalArgs to match the new planned API [\#239](https://github.com/divnix/devos/pull/239) + ## [v0.9.0](https://github.com/divnix/devos/tree/v0.9.0) (2021-04-19) **Implemented enhancements:** @@ -77,6 +105,10 @@ - add github action for cachix build ci [\#59](https://github.com/divnix/devos/issues/59) +## [12052020](https://github.com/divnix/devos/tree/12052020) (2020-12-06) + +## [07092020](https://github.com/divnix/devos/tree/07092020) (2020-07-09) + \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*