diff options
author | Lluís Batlle i Rossell <viric@vicerveza.homeunix.net> | 2012-03-27 20:33:49 +0000 |
---|---|---|
committer | Lluís Batlle i Rossell <viric@vicerveza.homeunix.net> | 2012-03-27 20:33:49 +0000 |
commit | 68b5044cc00224ef650e10db29d6e179c038450a (patch) | |
tree | 01396f7b2f4a416555f7b72afd1db52c2bab0ce4 /pkgs | |
parent | db28c68df050ff788f3a1cd723e401bebc9bb70e (diff) | |
download | nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar.gz nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar.bz2 nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar.lz nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar.xz nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.tar.zst nixpkgs-68b5044cc00224ef650e10db29d6e179c038450a.zip |
Adding 'usernixos', where I start a modular kind-of-nixos that can go into
"nix-env -i" profiles, as a container for flexible configuration at the style of nixos, to be defined in .nixpkgs/config.nix, with the main target of generating an activation script. svn path=/nixpkgs/trunk/; revision=33445
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/build-support/usernixos/activation.nix | 26 | ||||
-rw-r--r-- | pkgs/build-support/usernixos/bashrc.nix | 59 | ||||
-rw-r--r-- | pkgs/build-support/usernixos/eval-config.nix | 31 | ||||
-rw-r--r-- | pkgs/build-support/usernixos/module-list.nix | 4 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 10 |
5 files changed, 130 insertions, 0 deletions
diff --git a/pkgs/build-support/usernixos/activation.nix b/pkgs/build-support/usernixos/activation.nix new file mode 100644 index 00000000000..2e3f0af2bf7 --- /dev/null +++ b/pkgs/build-support/usernixos/activation.nix @@ -0,0 +1,26 @@ +{ pkgs, config, ... }: + +let + script = pkgs.writeScriptBin "usernixos" ('' + #!${pkgs.bash}/bin/bash + '' + config.activationContents); +in +with pkgs.lib; +{ + options = { + activation = mkOption { + default = {}; + }; + + activationContents = mkOption { + default = ""; + internal = true; + merge = concatStringsSep "\n"; + description = '' + Commands to run at activation + ''; + }; + }; + + config.activation.toplevel = script; +} diff --git a/pkgs/build-support/usernixos/bashrc.nix b/pkgs/build-support/usernixos/bashrc.nix new file mode 100644 index 00000000000..1860f4b2e89 --- /dev/null +++ b/pkgs/build-support/usernixos/bashrc.nix @@ -0,0 +1,59 @@ +# Generator for .bashrc +{pkgs, config, ...}: + +with pkgs.lib; + +let + bashrcFile = pkgs.writeScript "bashrc" config.bashrc.contents; + cfg = config.bashrc; +in +{ + options = { + environment.editor = mkOption { + default = "${pkgs.vim}/bin/vim"; + type = types.string; + description = '' + Editor + ''; + }; + + bashrc = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Enable of .bashrc generation on activation + ''; + }; + + destination = mkOption { + default = "~/.bashrc"; + type = types.string; + description = '' + The symlink that will point to the generated bashrc at activation time + ''; + }; + + contents = mkOption { + default = ""; + type = types.string; + merge = concatStringsSep "\n"; + description = '' + Enable of .bashrc generation on activation + ''; + }; + }; + }; + + config.bashrc.contents = '' + export EDITOR="${config.environment.editor}" + ''; + + config.activationContents = mkIf cfg.enable '' + if [ -e "${cfg.destination}" ]; then + echo Cannot set "${cfg.destination}", it exists + exit 1 + fi + ln -sf ${bashrcFile} "${cfg.destination}" + ''; +} diff --git a/pkgs/build-support/usernixos/eval-config.nix b/pkgs/build-support/usernixos/eval-config.nix new file mode 100644 index 00000000000..300ddd2444e --- /dev/null +++ b/pkgs/build-support/usernixos/eval-config.nix @@ -0,0 +1,31 @@ +{ system ? builtins.currentSystem +, pkgs ? null +, baseModules ? import ./module-list.nix +, extraArgs ? {} +, modules +}: + +let extraArgs_ = extraArgs; pkgs_ = pkgs; system_ = system; in + +rec { + + # These are the NixOS modules that constitute the system configuration. + configComponents = modules ++ baseModules; + + # Merge the option definitions in all modules, forming the full + # system configuration. It's not checked for undeclared options. + systemModule = + pkgs.lib.fixMergeModules configComponents extraArgs; + + optionDefinitions = systemModule.config; + optionDeclarations = systemModule.options; + inherit (systemModule) options; + + # These are the extra arguments passed to every module. In + # particular, Nixpkgs is passed through the "pkgs" argument. + extraArgs = extraArgs_ // { + inherit pkgs modules baseModules; + }; + + config = systemModule.config; +} diff --git a/pkgs/build-support/usernixos/module-list.nix b/pkgs/build-support/usernixos/module-list.nix new file mode 100644 index 00000000000..2aa5329940b --- /dev/null +++ b/pkgs/build-support/usernixos/module-list.nix @@ -0,0 +1,4 @@ +[ + ./activation.nix + ./bashrc.nix +] diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 00b810a6439..1299081d516 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -353,6 +353,16 @@ let inherit pkgs lib; }; + usernixos = let + configmodule = getConfig [ "usernixos" ] null; + eval = (import ../build-support/usernixos/eval-config.nix) { + inherit pkgs system; + modules = [ configmodule ]; + }; + in + assert configmodule != null; + eval.config.activation.toplevel; + platforms = import ./platforms.nix; |