Skip to content

Instantly share code, notes, and snippets.

@msteen msteen/nixpkgs.nix Secret
Created Feb 4, 2019

Embed
What would you like to do?
{
allowUnfree = true;
pulseaudio = true;
}
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system;
in {
options = with types; {
system = {
nixpkgsConfig = mkOption {
type = path;
default = ./nixpkgs.nix;
description = ''
Path of the Nixpkgs configuration file.
'';
};
nixpkgsOverlayFiles = mkOption {
type = loeOf path;
default = [];
description = ''
List of Nixpkgs overlay file paths.
'';
};
nixosConfig = mkOption {
type = path;
description = ''
Path of the NixOS configuration file.
'';
};
};
};
config = mkMerge [
{
# Need to set both `variables` and `sessionVariables`, because session variables are also assigned to be regular variables,
# but when copying over attributes, `mkForce` is not copied over.
environment.variables.NIXPKGS_CONFIG = mkForce (toString cfg.nixpkgsConfig);
environment.sessionVariables.NIXPKGS_CONFIG = toString cfg.nixpkgsConfig;
environment.etc."nix/nixpkgs-config.nix".source = toString cfg.nixpkgsConfig;
nixpkgs.config = import cfg.nixpkgsConfig;
}
{
nix.nixPath = [ "nixpkgs-overlays=/etc/nixpkgs/overlays" ];
nixpkgs.overlays = map import cfg.nixpkgsOverlayFiles;
environment.etc = listToAttrs (imap1 (i: overlayFile:
# If we do not call `toString` on `overlayFile` the relative paths will break.
nameValuePair "nixpkgs/overlays/overlay${toString i}.nix" { source = toString overlayFile; }
) cfg.nixpkgsOverlayFiles);
}
{
system.nixosConfig =
let nixosConfig = maybeEnv "NIXOS_CONFIG" (maybeNixPath "nixos-config" "/etc/nixos/configuration.nix");
in mkIf (pathExists nixosConfig) (mkDefault nixosConfig);
environment.sessionVariables.NIXOS_CONFIG = toString cfg.nixosConfig;
environment.etc."nixos/configuration.nix".source = toString cfg.nixosConfig;
nix.nixPath = [ "nixos-config=${toString cfg.nixosConfig}" ];
}
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.