Add experimental NixOS module

This commit is contained in:
Robert Helgesson 2017-10-14 20:56:02 +02:00
parent 5d64fec19a
commit 7265ef755a
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
7 changed files with 141 additions and 66 deletions

View file

@ -11,4 +11,6 @@ rec {
"home-manager-install" "home-manager-install"
{ propagatedBuildInputs = [ home-manager ]; } { propagatedBuildInputs = [ home-manager ]; }
""; "";
nixos = import ./nixos;
} }

View file

@ -10,60 +10,6 @@ with lib;
let let
modules = [
./files.nix
./home-environment.nix
./manual.nix
./misc/fontconfig.nix
./misc/gtk.nix
./misc/news.nix
./misc/nixpkgs.nix
./misc/pam.nix
./programs/bash.nix
./programs/beets.nix
./programs/browserpass.nix
./programs/command-not-found/command-not-found.nix
./programs/eclipse.nix
./programs/emacs.nix
./programs/feh.nix
./programs/firefox.nix
./programs/git.nix
./programs/gnome-terminal.nix
./programs/home-manager.nix
./programs/htop.nix
./programs/info.nix
./programs/lesspipe.nix
./programs/man.nix
./programs/rofi.nix
./programs/ssh.nix
./programs/termite.nix
./programs/texlive.nix
./programs/vim.nix
./programs/zsh.nix
./services/blueman-applet.nix
./services/compton.nix
./services/dunst.nix
./services/gnome-keyring.nix
./services/gpg-agent.nix
./services/keepassx.nix
./services/network-manager-applet.nix
./services/owncloud-client.nix
./services/polybar.nix
./services/random-background.nix
./services/redshift.nix
./services/screen-locker.nix
./services/syncthing.nix
./services/taffybar.nix
./services/tahoe-lafs.nix
./services/udiskie.nix
./services/xscreensaver.nix
./systemd.nix
./xresources.nix
./xsession.nix
<nixpkgs/nixos/modules/misc/assertions.nix>
<nixpkgs/nixos/modules/misc/meta.nix>
];
collectFailed = cfg: collectFailed = cfg:
map (x: x.message) (filter (x: !x.assertion) cfg.assertions); map (x: x.message) (filter (x: !x.assertion) cfg.assertions);
@ -73,15 +19,9 @@ let
in in
fold f res res.config.warnings; fold f res res.config.warnings;
pkgsModule = {
config._module.args.baseModules = modules;
config._module.args.pkgs = lib.mkDefault pkgs;
config._module.check = check;
config.nixpkgs.system = mkDefault pkgs.system;
};
rawModule = lib.evalModules { rawModule = lib.evalModules {
modules = [ configuration ] ++ modules ++ [ pkgsModule ]; modules = [ configuration ]
++ (import ./modules.nix { inherit check lib pkgs; });
}; };
module = showWarnings ( module = showWarnings (

View file

@ -234,9 +234,13 @@ in
# script's "check" and the "write" phases. # script's "check" and the "write" phases.
home.activation.writeBoundary = dagEntryAnywhere ""; home.activation.writeBoundary = dagEntryAnywhere "";
home.activation.installPackages = dagEntryAfter ["writeBoundary"] '' # Install packages to the user environment. This is a no-op if
$DRY_RUN_CMD nix-env -i ${cfg.path} # Home Manager is used as a NixOS module.
''; home.activation.installPackages = dagEntryAfter ["writeBoundary"] (
optionalString (!config.nixosSubmodule) ''
$DRY_RUN_CMD nix-env -i ${cfg.path}
''
);
home.activationPackage = home.activationPackage =
let let

85
modules/modules.nix Normal file
View file

@ -0,0 +1,85 @@
{ pkgs
, lib
# Whether to enable module type checking.
, check ? true
# Whether these modules are inside a NixOS submodule.
, nixosSubmodule ? false
}:
with lib;
let
modules = [
./files.nix
./home-environment.nix
./manual.nix
./misc/fontconfig.nix
./misc/gtk.nix
./misc/news.nix
./misc/nixpkgs.nix
./misc/pam.nix
./programs/bash.nix
./programs/beets.nix
./programs/browserpass.nix
./programs/command-not-found/command-not-found.nix
./programs/eclipse.nix
./programs/emacs.nix
./programs/feh.nix
./programs/firefox.nix
./programs/git.nix
./programs/gnome-terminal.nix
./programs/home-manager.nix
./programs/htop.nix
./programs/info.nix
./programs/lesspipe.nix
./programs/man.nix
./programs/rofi.nix
./programs/ssh.nix
./programs/termite.nix
./programs/texlive.nix
./programs/vim.nix
./programs/zsh.nix
./services/blueman-applet.nix
./services/compton.nix
./services/dunst.nix
./services/gnome-keyring.nix
./services/gpg-agent.nix
./services/keepassx.nix
./services/network-manager-applet.nix
./services/owncloud-client.nix
./services/polybar.nix
./services/random-background.nix
./services/redshift.nix
./services/screen-locker.nix
./services/syncthing.nix
./services/taffybar.nix
./services/tahoe-lafs.nix
./services/udiskie.nix
./services/xscreensaver.nix
./systemd.nix
./xresources.nix
./xsession.nix
<nixpkgs/nixos/modules/misc/assertions.nix>
<nixpkgs/nixos/modules/misc/meta.nix>
];
pkgsModule = {
options.nixosSubmodule = mkOption {
type = types.bool;
internal = true;
readOnly = true;
};
config._module.args.baseModules = modules;
config._module.args.pkgs = lib.mkDefault pkgs;
config._module.check = check;
config.nixosSubmodule = nixosSubmodule;
config.nixpkgs.system = mkDefault pkgs.system;
};
in
map import modules ++ [ pkgsModule ]

View file

@ -45,7 +45,7 @@ in
}; };
}; };
config = mkIf cfg.enable { config = mkIf (cfg.enable && !config.nixosSubmodule) {
assertions = [{ assertions = [{
assertion = cfg.path == null || cfg.modulesPath == null; assertion = cfg.path == null || cfg.modulesPath == null;
message = "Cannot simultaneously use " message = "Cannot simultaneously use "

View file

@ -117,7 +117,9 @@ in
++ ++
(buildServices "timer" cfg.timers) (buildServices "timer" cfg.timers)
); );
})
(mkIf (pkgs.stdenv.isLinux && !config.nixosSubmodule) {
home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] '' home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] ''
function systemdPostReload() { function systemdPostReload() {
local workDir local workDir

42
nixos/default.nix Normal file
View file

@ -0,0 +1,42 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.home-manager;
hmModule = types.submodule (
import ../modules/modules.nix {
inherit lib pkgs;
nixosSubmodule = true;
}
);
activateUser = username: usercfg: ''
echo Activating home-manager configuration for ${username}
${pkgs.sudo}/bin/sudo -u ${username} ${usercfg.home.activationPackage}/activate
'';
in
{
options = {
home-manager.users = mkOption {
type = types.attrsOf hmModule;
default = {};
description = ''
Per-user Home Manager configuration.
'';
};
};
config = {
system.activationScripts.home-manager =
stringAfter [ "users" ] (
concatStringsSep "\n" (
mapAttrsToList activateUser cfg.users));
users.users = mapAttrs (n: v: { packages = v.home.packages; } ) cfg.users;
};
}