2021-02-12 09:23:43 +01:00
|
|
|
{ pkgs ? (import ./compat).defaultNix.nixosConfigurations.NixOS.config.nixpkgs.pkgs
|
2021-01-19 08:51:23 +01:00
|
|
|
, nixos ? (import ./compat).defaultNix.inputs.nixos
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
build = "config.system.build";
|
|
|
|
|
|
|
|
installPkgs = (import "${nixos}/nixos" {
|
|
|
|
configuration = { };
|
|
|
|
system = pkgs.system;
|
|
|
|
}).config.system.build;
|
|
|
|
|
|
|
|
flk = pkgs.writeShellScriptBin "flk" ''
|
|
|
|
if [[ -z "$1" ]]; then
|
2021-02-06 22:51:57 +01:00
|
|
|
echo "Usage: $(basename $0) [ up | get [core|community] {dest} | iso {host} | install {host} | {host} [switch|boot|test] | home {host} {user} [switch] ]"
|
2021-01-19 08:51:23 +01:00
|
|
|
elif [[ "$1" == "up" ]]; then
|
2021-02-02 04:10:26 +01:00
|
|
|
mkdir -p "$DEVSHELL_ROOT/up"
|
|
|
|
hostname="$(hostname)"
|
|
|
|
nixos-generate-config --dir "$DEVSHELL_ROOT/up/$hostname"
|
2021-01-19 08:51:23 +01:00
|
|
|
echo \
|
|
|
|
"{
|
|
|
|
imports = [ ../up/$hostname/configuration.nix ];
|
2021-02-02 04:10:26 +01:00
|
|
|
}" > "$DEVSHELL_ROOT/hosts/up-$hostname.nix"
|
|
|
|
git add -f "$DEVSHELL_ROOT/up/$hostname"
|
|
|
|
git add -f "$DEVSHELL_ROOT/hosts/up-$hostname.nix"
|
2021-01-19 08:51:23 +01:00
|
|
|
elif [[ "$1" == "iso" ]]; then
|
2021-02-02 04:10:26 +01:00
|
|
|
nix build "$DEVSHELL_ROOT#nixosConfigurations.$2.${build}.iso" "${"\${@:3}"}"
|
2021-01-19 08:51:23 +01:00
|
|
|
elif [[ "$1" == "install" ]]; then
|
2021-01-25 17:23:51 +01:00
|
|
|
sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${"\${@:3}"}"
|
2021-01-16 19:28:20 +01:00
|
|
|
elif [[ "$1" == "home" ]]; then
|
2021-02-04 07:44:58 +01:00
|
|
|
nix build "./#hmActivationPackages.$2.$3" "${"\${@:4}"}"
|
2021-01-16 19:28:20 +01:00
|
|
|
if [[ "$4" == "switch" ]]; then
|
|
|
|
./result/activate && unlink result
|
|
|
|
fi
|
2021-02-06 22:51:57 +01:00
|
|
|
elif [[ "$1" == "get" ]]; then
|
|
|
|
if [[ "$2" == "core" || "$2" == "community" ]]; then
|
|
|
|
nix flake new -t "github:nrdxp/nixflk/$2" "${"\${3:-flk}"}"
|
|
|
|
else
|
|
|
|
echo "flk get [core|community] {dest}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-19 08:51:23 +01:00
|
|
|
else
|
2021-01-25 17:23:51 +01:00
|
|
|
sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${"\${@:2}"}"
|
2021-01-19 08:51:23 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
name = "flk";
|
|
|
|
in
|
2021-01-27 16:31:17 +01:00
|
|
|
pkgs.devshell.mkShell {
|
2021-01-19 08:51:23 +01:00
|
|
|
inherit name;
|
|
|
|
|
|
|
|
packages = with pkgs; with installPkgs; [
|
|
|
|
git-crypt
|
|
|
|
nixos-install
|
|
|
|
nixos-generate-config
|
|
|
|
nixos-enter
|
2021-02-06 22:51:57 +01:00
|
|
|
mdbook
|
2021-01-19 08:51:23 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
env = { inherit name; };
|
|
|
|
|
2021-01-27 16:31:17 +01:00
|
|
|
git.hooks = with pkgs; {
|
|
|
|
enable = true;
|
|
|
|
pre-commit.text = ''
|
2021-02-02 07:16:26 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-01-27 16:31:17 +01:00
|
|
|
if ${git}/bin/git rev-parse --verify HEAD >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
against=HEAD
|
|
|
|
else
|
|
|
|
# Initial commit: diff against an empty tree object
|
|
|
|
against=$(${git}/bin/git hash-object -t tree /dev/null)
|
|
|
|
fi
|
2021-02-02 07:16:26 +01:00
|
|
|
|
|
|
|
diff="${git}/bin/git diff-index --name-only --cached $against --diff-filter d"
|
|
|
|
|
|
|
|
nix_files=($($diff -- '*.nix'))
|
|
|
|
|
|
|
|
all_files=($($diff))
|
2021-01-27 16:31:17 +01:00
|
|
|
|
|
|
|
# Format staged nix files.
|
2021-02-04 05:24:53 +01:00
|
|
|
${nixpkgs-fmt}/bin/nixpkgs-fmt "${"\${nix_files[@]}"}" \
|
|
|
|
&& git add "${"\${nix_files[@]}"}"
|
2021-02-02 07:16:26 +01:00
|
|
|
|
|
|
|
# check editorconfig
|
|
|
|
${editorconfig-checker}/bin/editorconfig-checker -- "${"\${all_files[@]}"}"
|
|
|
|
if [[ $? != '0' ]]; then
|
|
|
|
{
|
|
|
|
echo -e "\nCode is not aligned with .editorconfig"
|
|
|
|
echo "Review the output and commit your fixes"
|
|
|
|
} >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-27 16:31:17 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-19 08:51:23 +01:00
|
|
|
commands = with pkgs; [
|
|
|
|
{
|
|
|
|
name = nixpkgs-fmt.pname;
|
|
|
|
package = nixpkgs-fmt;
|
|
|
|
help = nixpkgs-fmt.meta.description;
|
|
|
|
category = "linters";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = flk.name;
|
|
|
|
help = "Build, deploy, and install nixflk";
|
|
|
|
category = "main";
|
|
|
|
package = flk;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "grip";
|
|
|
|
help = python38Packages.grip.meta.description;
|
|
|
|
category = "servers";
|
|
|
|
package = python38Packages.grip;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = git.pname;
|
|
|
|
help = git.meta.description;
|
|
|
|
category = "vcs";
|
|
|
|
package = git;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "nix";
|
|
|
|
help = nixFlakes.meta.description;
|
|
|
|
category = "main";
|
|
|
|
command = ''${nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@"'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|