nixos-config/modules/flakes.nix

42 lines
1.1 KiB
Nix
Raw Normal View History

2021-01-17 22:08:34 +00:00
{ config, pkgs, lib, ... }:
let
cfg = config.sconfig.flakes;
2021-04-09 01:55:37 +00:00
upgradeArg = if cfg.rebuildPath == "/etc/nixos" then "--recreate-lock-file" else "--refresh";
2021-01-17 22:08:34 +00:00
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;
2021-04-09 01:55:37 +00:00
system.autoUpgrade.flags = [ upgradeArg ];
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:55:37 +00:00
[ "switch-upgrade" "switch" upgradeArg ]
[ "build-upgrade" "build" upgradeArg ]
[ "boot-upgrade" "boot" upgradeArg ]
];
2021-01-17 22:08:34 +00:00
};
}