From 5fdae43a99af8783549e8b7d1424556d1f219bf6 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 19 Oct 2015 21:20:38 +0200 Subject: move user namespaces into "users" attribute IOW get ${user-name} -> get users.${user-name} --- default.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 841882f5..ff782e28 100644 --- a/default.nix +++ b/default.nix @@ -25,16 +25,18 @@ in with klib; let kpkgs // upkgs; }; - out = - { inherit (eval {}) config options pkgs; } // - lib.mapAttrs - (name: _: - if builtins.pathExists (nspath name "default.nix") - then import (nspath name "default.nix") - else import-1systems (nspath name "1systems")) - (lib.filterAttrs - (n: t: !lib.hasPrefix "." n && t == "directory") - (builtins.readDir ./.)); + out = { + inherit (eval {}) config options pkgs; + krebs = import ./krebs; + users = lib.mapAttrs + (name: _: + if builtins.pathExists (nspath name "default.nix") + then import (nspath name "default.nix") + else import-1systems (nspath name "1systems")) + (lib.filterAttrs + (n: t: !lib.hasPrefix "." n && t == "directory" && n != "krebs") + (builtins.readDir ./.)); + }; eval = path: import { modules = [ -- cgit v1.2.3 From cb654782fa9b8130d056579a7922062a92501b77 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 02:33:58 +0200 Subject: document top-level default.nix --- default.nix | 126 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 45 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index ff782e28..831a71f0 100644 --- a/default.nix +++ b/default.nix @@ -1,74 +1,110 @@ +# Welcome to the top-level default.nix of stockholm. +# +# You can discover the whole thing easily using the `get` utility, +# which can be found at http://cgit.cd.krebsco.de/get/tree/get +# To install `get` on any Nix-enabled system, use: +# +# nix-env -f /path/to/stockholm -iA pkgs.get +# +# The "current" arguments are used to provide information about the user who's +# evaluating this file. This information is used to determine which user +# namespace is to be used. Of course there's nothing trying to prevent you +# from forging this information. E.g. you could try to generate the deployment +# script for some random user's system, targeting some random host: +# +# LOGNAME=tv get krebs.deploy system=nomic target=8.8.8.8 +# { current-date ? abort "current-date not defined" , current-host-name ? abort "current-host-name not defined" , current-user-name ? builtins.getEnv "LOGNAME" -}: +}@current: -assert current-user-name != ""; +let out = { + # The generated scripts to deploy (or infest) systems can be found in the + # `krebs` attribute. There's also an init script, but it's in its early + # stages, not well integrated and mostly useless at the moment. :) + # + # You'll also find lib here, which is nixpkgs/lib + krebs lib, but nobody + # is really accessing this directly, as this lib gets reexported below. + inherit krebs; -let - lib = import ; - klib = import ./krebs/4lib { inherit lib; }; -in with klib; let + # All systems of all users can be found here. + # + # /!\ Please note that `get users.${user-name}.${host-name}.system` is a + # bad idea because it will produce vast amounts of output. These are the + # actual and complete system derivations that can be installed on the + # respective host. + # + # Another thing to notice here is that other user's systems might not be + # evaluable because of missing secrets. If you _are_ able to evaluate + # another user's system, then you probably share a similar naming scheme + # for your secret files! :) + inherit users; - nspath = ns: p: ./. + "/${ns}/${p}"; - kpath = nspath "krebs"; - upath = nspath current-user-name; + # Additionally, output lib and pkgs for easy access from the shell. + # Notice how we're evaluating just the stockholm module to obtain pkgs. + inherit lib; + inherit (eval {}) pkgs; + }; + + krebs = import ./krebs current; + inherit (krebs) lib; + # Path resolvers for common and individual files. + # Example: `upath "3modules"` produces the current user's 3modules directory + kpath = lib.nspath "krebs"; + upath = lib.nspath current-user-name; + + # This is the base stockholm NixOS module. It's purpose is to provide a + # modules and packages, both common ones, found in krebs/ as well as the + # current user's, found in the user's namespace. stockholm = { imports = map (f: f "3modules") [ kpath upath ]; nixpkgs.config.packageOverrides = pkgs: let + # Notice the ordering. Krebs packages can only depend on Nixpkgs, + # whereas user packages additionally can depend on krebs packages. kpkgs = import (kpath "5pkgs") { inherit pkgs; }; upkgs = import (upath "5pkgs") { pkgs = pkgs // kpkgs; }; in kpkgs // upkgs; }; - out = { - inherit (eval {}) config options pkgs; - krebs = import ./krebs; - users = lib.mapAttrs - (name: _: - if builtins.pathExists (nspath name "default.nix") - then import (nspath name "default.nix") - else import-1systems (nspath name "1systems")) - (lib.filterAttrs - (n: t: !lib.hasPrefix "." n && t == "directory" && n != "krebs") - (builtins.readDir ./.)); - }; - - eval = path: import { + # The above stockholm module is used together with a NixOS configuration to + # produce a system. Stockholm really just provides additional packages and + # modules that don't fit upstream for one reason or another. + # TODO provide krebs lib, so modules don't have to import it awkwardly + eval = config: import { modules = [ stockholm - path + config ]; }; - import-1systems = path: lib.mapAttrs (_: mk-system) (nixDir path); + # Any top-level directory other than krebs/ is considered to be a user + # namespace, configuring a bunch of systems. + # Have a look at the definition of install in krebs/default.nix to see how + # nix-env is using this attribute set to obtain the system to be installed. + # TODO move user namespaces' to users/, so no exception for krebs/ is needed + users = + lib.mapAttrs + (name: _: eval-all-systems (lib.nspath name "1systems")) + (lib.filterAttrs + (n: t: !lib.hasPrefix "." n && t == "directory" && n != "krebs") + (builtins.readDir ./.)); + + # Given a path to a user namespace, provide an attribute of evaluated + # system configurations, keyed by system names (AKA host names). + eval-all-systems = path: + lib.mapAttrs' + (n: _: (lib.nameValuePair (lib.removeSuffix ".nix" n) + (eval-system (path + "/${n}")))) + (builtins.readDir path); - mk-system = path: rec { + eval-system = path: rec { inherit (eval path) config options; system = config.system.build.toplevel; - fetch = import ./krebs/0tools/fetch.nix { inherit config lib; }; }; - nixDir = path: - builtins.listToAttrs - (catMaybes - (lib.mapAttrsToList - (k: v: { - directory = - let p = path + "/${k}/default.nix"; in - if builtins.pathExists p - then Just (lib.nameValuePair k p) - else Nothing; - regular = - let p = path + "/${k}"; in - if lib.hasSuffix ".nix" p - then Just (lib.nameValuePair (lib.removeSuffix ".nix" k) p) - else Nothing; - }.${v} or Nothing) - (builtins.readDir path))); - in out -- cgit v1.2.3 From 433479bc517d966ff6b56fb55e0b91500cad9e45 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 03:31:38 +0200 Subject: top-level default.nix provides stockholm Collaterally, define krebs/default.nix's output in a concise way. --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 831a71f0..dbf7fdde 100644 --- a/default.nix +++ b/default.nix @@ -47,7 +47,7 @@ let out = { inherit (eval {}) pkgs; }; - krebs = import ./krebs current; + krebs = import ./krebs (current // { stockholm = out; }); inherit (krebs) lib; # Path resolvers for common and individual files. -- cgit v1.2.3 From f3873a264000119ff3f1bd92965573733750febe Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 03:49:10 +0200 Subject: stockholm: call the base module what it is This reduces confusion when referring to stockholm, which is either the whole repository or the value of the top-level default.nix, which is in a way the same thing. :) --- default.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index dbf7fdde..f88acd28 100644 --- a/default.nix +++ b/default.nix @@ -42,7 +42,7 @@ let out = { inherit users; # Additionally, output lib and pkgs for easy access from the shell. - # Notice how we're evaluating just the stockholm module to obtain pkgs. + # Notice how we're evaluating just the base module to obtain pkgs. inherit lib; inherit (eval {}) pkgs; }; @@ -55,10 +55,10 @@ let out = { kpath = lib.nspath "krebs"; upath = lib.nspath current-user-name; - # This is the base stockholm NixOS module. It's purpose is to provide a - # modules and packages, both common ones, found in krebs/ as well as the - # current user's, found in the user's namespace. - stockholm = { + # This is the base module. Its purpose is to provide modules and + # packages, both common ones, found in krebs/ as well as the current user's, + # found in the user's namespace. + base-module = { imports = map (f: f "3modules") [ kpath upath ]; nixpkgs.config.packageOverrides = pkgs: @@ -71,13 +71,15 @@ let out = { kpkgs // upkgs; }; - # The above stockholm module is used together with a NixOS configuration to - # produce a system. Stockholm really just provides additional packages and - # modules that don't fit upstream for one reason or another. + # The above base module is used together with a NixOS configuration to + # produce a system. Notice how stockholm really just provides additional + # packages and modules on top of NixOS. Some of this stuff might become + # useful to a broader audience, at which point it should probably be merged + # and pull-requested for inclusion into NixOS/nixpkgs. # TODO provide krebs lib, so modules don't have to import it awkwardly eval = config: import { modules = [ - stockholm + base-module config ]; }; -- cgit v1.2.3 From c08a46fd54f4e4c21029b1b9cf3c12d2fbfc40d4 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 03:56:38 +0200 Subject: clarify even harder what's meant by "stockholm" --- default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index f88acd28..11bae7d9 100644 --- a/default.nix +++ b/default.nix @@ -19,7 +19,7 @@ , current-user-name ? builtins.getEnv "LOGNAME" }@current: -let out = { +let stockholm = { # The generated scripts to deploy (or infest) systems can be found in the # `krebs` attribute. There's also an init script, but it's in its early # stages, not well integrated and mostly useless at the moment. :) @@ -47,7 +47,7 @@ let out = { inherit (eval {}) pkgs; }; - krebs = import ./krebs (current // { stockholm = out; }); + krebs = import ./krebs (current // { inherit stockholm; }); inherit (krebs) lib; # Path resolvers for common and individual files. @@ -109,4 +109,4 @@ let out = { system = config.system.build.toplevel; }; -in out +in stockholm -- cgit v1.2.3