Skip to content

Commit

Permalink
Add experimental NixOS module
Browse files Browse the repository at this point in the history
  • Loading branch information
rycee committed Oct 19, 2017
1 parent b18aeea commit c155e81
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 63 deletions.
62 changes: 2 additions & 60 deletions modules/default.nix
Expand Up @@ -10,59 +10,6 @@ with lib;

let

modules = [
./home-environment.nix
./files.nix
./manual.nix
./misc/fontconfig.nix
./misc/gtk.nix
./misc/news.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:
map (x: x.message) (filter (x: !x.assertion) cfg.assertions);

Expand All @@ -72,14 +19,9 @@ let
in
fold f res res.config.warnings;

pkgsModule = {
config._module.args.pkgs = lib.mkForce pkgs;
config._module.args.baseModules = modules;
config._module.check = check;
};

rawModule = lib.evalModules {
modules = [ configuration ] ++ modules ++ [ pkgsModule ];
modules = [ configuration ]
++ (import ./modules.nix { inherit check lib pkgs; });
};

module = showWarnings (
Expand Down
10 changes: 7 additions & 3 deletions modules/home-environment.nix
Expand Up @@ -225,9 +225,13 @@ in
# script's "check" and the "write" phases.
home.activation.writeBoundary = dagEntryAnywhere "";

home.activation.installPackages = dagEntryAfter ["writeBoundary"] ''
$DRY_RUN_CMD nix-env -i ${cfg.path}
'';
# Install packages to the user environment. This is a no-op if
# 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 =
let
Expand Down
83 changes: 83 additions & 0 deletions modules/modules.nix
@@ -0,0 +1,83 @@
{ pkgs
, lib

# Whether to enable module type checking.
, check ? true

# Whether these modules are inside a NixOS submodule.
, nixosSubmodule ? false
}:

with lib;

let

modules = [
./home-environment.nix
./files.nix
./manual.nix
./misc/fontconfig.nix
./misc/gtk.nix
./misc/news.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.nixosSubmodule = nixosSubmodule;
config._module.args.pkgs = mkForce pkgs;
config._module.args.baseModules = modules;
config._module.check = check;
};

in

map import modules ++ [ pkgsModule ]
2 changes: 2 additions & 0 deletions modules/systemd.nix
Expand Up @@ -106,7 +106,9 @@ in
++
(buildServices "timer" cfg.timers)
);
})

(mkIf (pkgs.stdenv.isLinux && !config.nixosSubmodule) {
home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] ''
function systemdPostReload() {
local workDir
Expand Down
42 changes: 42 additions & 0 deletions nixos/default.nix
@@ -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;
};
}

0 comments on commit c155e81

Please sign in to comment.