nixos-config/modules/flakes.nix

41 lines
1.3 KiB
Nix
Raw Normal View History

2021-01-17 22:08:34 +00:00
{ config, pkgs, lib, ... }:
let
cfg = config.sconfig.flakes;
in
{
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-06 03:39:07 +00:00
system.autoUpgrade.flake = cfg.rebuildPath;
system.autoUpgrade.flags = [ (lib.optionalString (cfg.rebuildPath == "/etc/nixos") "--recreate-lock-file") ];
2021-04-06 03:39:07 +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-09 01:45:49 +00:00
[ "switch-upgrade" "switch" (if cfg.rebuildPath == "/etc/nixos" then "--recreate-lock-file" else "--refresh") ]
[ "build-upgrade" "build" (if cfg.rebuildPath == "/etc/nixos" then "--recreate-lock-file" else "--refresh") ]
[ "boot-upgrade" "boot" (if cfg.rebuildPath == "/etc/nixos" then "--recreate-lock-file" else "--refresh") ]
];
2021-01-17 22:08:34 +00:00
};
}