2021-01-17 22:08:34 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.sconfig.flakes;
|
|
|
|
in
|
|
|
|
{
|
2021-04-05 21:56:06 +00:00
|
|
|
options.sconfig.flakes = {
|
|
|
|
enable = lib.mkEnableOption "Enable Flakes";
|
|
|
|
rebuildPath = lib.mkOption {
|
|
|
|
default = "/etc/nixos";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Flake to use when running nixos-rebuild helper scripts";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-01-17 22:08:34 +00:00
|
|
|
|
2021-04-01 03:43:23 +00:00
|
|
|
nix.package = pkgs.nixFlakes;
|
|
|
|
nix.extraOptions = ''
|
|
|
|
experimental-features = nix-command flakes
|
|
|
|
'';
|
2021-04-05 21:56:06 +00:00
|
|
|
|
2021-04-06 03:39:07 +00:00
|
|
|
system.autoUpgrade.flake = cfg.rebuildPath;
|
|
|
|
|
2021-04-05 21:56:06 +00:00
|
|
|
environment.systemPackages = map
|
|
|
|
(x: (pkgs.writeShellScriptBin
|
|
|
|
"sc-${builtins.head x}"
|
|
|
|
"nixos-rebuild ${lib.concatStringsSep " " (builtins.tail x)} --flake ${cfg.rebuildPath}"
|
|
|
|
))
|
|
|
|
[
|
|
|
|
[ "switch" "switch" ]
|
|
|
|
[ "build" "build" ]
|
|
|
|
[ "boot" "boot" ]
|
2021-04-06 03:27:42 +00:00
|
|
|
[ "switch-upgrade" "switch" "--refresh" (lib.optionalString (cfg.rebuildPath == "/etc/nixos") "--recreate-lock-file") ]
|
|
|
|
[ "build-upgrade" "build" "--refresh" (lib.optionalString (cfg.rebuildPath == "/etc/nixos") "--recreate-lock-file") ]
|
|
|
|
[ "boot-upgrade" "boot" "--refresh" (lib.optionalString (cfg.rebuildPath == "/etc/nixos") "--recreate-lock-file") ]
|
2021-04-05 21:56:06 +00:00
|
|
|
];
|
|
|
|
|
2021-01-17 22:08:34 +00:00
|
|
|
};
|
|
|
|
}
|