1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-23 08:02:21 +03:00

ref: split digga shell into divnix/flk & divnix/devos/shell (devshell)

This commit is contained in:
David Arnold 2021-06-25 18:45:08 -05:00 committed by Parthiv Seetharaman
parent a2411ee0ec
commit a6fadb1288
10 changed files with 11 additions and 312 deletions

View File

@ -27,11 +27,11 @@
},
"devshell": {
"locked": {
"lastModified": 1622013274,
"narHash": "sha256-mK/Lv0lCbl07dI5s7tR/7nb79HunKnJik3KyR6yeI2k=",
"lastModified": 1625086391,
"narHash": "sha256-IpNPv1v8s4L3CoxhwcgZIitGpcrnNgnj09X7TA0QV3k=",
"owner": "numtide",
"repo": "devshell",
"rev": "e7faf69e6bf8546517cc936c7f6d31c7eb3abcb2",
"rev": "4b5ac7cf7d9a1cc60b965bb51b59922f2210cbc7",
"type": "github"
},
"original": {

View File

@ -59,18 +59,13 @@
};
mkFlake = {
__functor = import ./src/mkFlake { inherit deploy; lib = combinedLib; };
__functor = import ./src/mkFlake { inherit deploy devshell; lib = combinedLib; };
evalArgs = import ./src/mkFlake/evalArgs.nix {
lib = combinedLib;
inherit devshell;
};
};
pkgs-lib = import ./src/pkgs-lib {
lib = combinedLib;
inherit deploy devshell;
};
inherit (attrs) mapFilterAttrs genAttrs' concatAttrs;
inherit (lists) unifyOverlays;
inherit (strings) rgxToString;

View File

@ -1,4 +1,4 @@
{ lib, deploy }:
{ lib, deploy, devshell }:
let
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
in
@ -96,8 +96,8 @@ lib.systemFlake (lib.mergeAny
outputsBuilder = channels:
let
defaultChannel = channels.${cfg.nixos.hostDefaults.channelName};
system = defaultChannel.system;
pkgs = channels.${cfg.nixos.hostDefaults.channelName};
system = pkgs.system;
defaultOutputsBuilder = {
packages = lib.exporters.fromOverlays self.overlays channels;
@ -144,8 +144,7 @@ lib.systemFlake (lib.mergeAny
createProfilesTestOp = n: host: {
name = "allProfilesTestFor-${n}";
value = lib.tests.profilesTest {
inherit host;
pkgs = defaultChannel;
inherit host pkgs;
};
};
@ -160,9 +159,9 @@ lib.systemFlake (lib.mergeAny
)
;
devShell = lib.pkgs-lib.shell {
pkgs = defaultChannel;
extraModules = cfg.devshell.modules ++ cfg.devshell.externalModules;
devShell = (import devshell { inherit system pkgs; }).mkShell {
name = lib.mkDefault cfg.nixos.hostDefaults.channelName;
imports = cfg.devshell.modules ++ cfg.devshell.externalModules;
};
};

View File

@ -59,7 +59,6 @@
];
# package and option is from fup
environment.systemPackages = [ pkgs.fup-repl ];
nix.generateRegistryFromInputs = lib.mkDefault true;
nix.extraOptions = ''

View File

@ -1,5 +0,0 @@
{ lib, deploy, devshell }:
{
shell = import ./shell { inherit lib devshell deploy; };
}

View File

@ -1,64 +0,0 @@
{ lib, devshell, deploy }:
{ pkgs, extraModules ? [ ] }:
let
overlays = [
devshell.overlay
(final: prev: {
deploy-rs =
deploy.packages.${prev.system}.deploy-rs;
})
(final: prev: {
nixos-rebuild = prev.nixos-rebuild.override {
nix = prev.nixFlakes;
};
})
];
pkgs' = pkgs.appendOverlays overlays;
flk = pkgs'.callPackage ./flk.nix { };
installPkgs = (import "${toString pkgs.path}/nixos/lib/eval-config.nix" {
inherit (pkgs') system;
modules = [ ];
}).config.system.build;
configuration = {
imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]
++ extraModules;
packages = with installPkgs; [
nixos-install
nixos-generate-config
nixos-enter
pkgs'.nixos-rebuild
pkgs'.fup-repl
];
git.hooks = {
pre-commit.text = lib.fileContents ./pre-commit.sh;
};
commands = with pkgs'; [
{ package = flk; }
{
name = "nix";
help = pkgs'.nixFlakes.meta.description;
command = ''
${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}"
'';
}
{
name = "deploy";
package = deploy-rs;
help = "A simple multi-profile Nix-flake deploy tool.";
}
]
++ lib.optional (system != "i686-linux") { package = cachix; };
};
in
pkgs'.devshell.mkShell configuration

View File

@ -1,42 +0,0 @@
imports = [ "git.hooks" ]
[devshell]
packages = [
"git-crypt"
]
[[commands]]
package = "git"
category = "vcs"
[[commands]]
package = "nixpkgs-fmt"
category = "linters"
[[commands]]
package = "editorconfig-checker"
category = "linters"
[[commands]]
package = "python3Packages.grip"
category = "documentation"
[[commands]]
package = "mdbook"
category = "documentation"
[[commands]]
name = "ssh-show-ed25519"
category = "secrets"
command = '''
user="$(cut -d ';' -f 1 <<< "$1")"
if [[ "$user" == "root" ]]; then
ssh $1 "cat /etc/ssh/ssh_host_ed25519_key.pub"
else
ssh $1 "cat ~/.ssh/id_ed25519.pub"
fi
'''
help = "ssh-show-ed25519 <user@hostName> | Show target host's SSH ed25519 key"
[git.hooks]
enable = true

View File

@ -1,23 +0,0 @@
{ stdenv }:
let
name = "flk";
in
stdenv.mkDerivation {
inherit name;
src = ./flk.sh;
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin
install $src $out/bin/${name}
'';
checkPhase = ''
${stdenv.shell} -n -O extglob $out/bin/${name}
'';
meta.description = "Build, deploy, and install NixOS";
}

View File

@ -1,131 +0,0 @@
#!/usr/bin/env bash
[[ -d "$DEVSHELL_ROOT" ]] ||
{
echo "This script must be run from devos's devshell" >&2
exit 1
}
shopt -s extglob
HOSTNAME="$(hostname)"
usage () {
printf "%b\n" \
"\e[4mUsage\e[0m: $(basename $0) COMMAND [ARGS]\n" \
"\e[4mCommands\e[0m:"
printf " %-30s %s\n\n" \
"up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \
"update [INPUT]" "Update and commit the lock file, or specific input" \
"get (core|community) [DEST]" "Copy the desired template to DEST" \
"build HOST BUILD" "Build a variant of your configuration from system.build"
"vm HOST" "Generate a vm for HOST" \
"vm run HOST" "run a one-shot vm for HOST" \
"install HOST [ARGS]" "Shortcut for nixos-install" \
"home HOST USER [switch]" "Home-manager config of USER from HOST" \
"HOST (switch|boot|test)" "Shortcut for nixos-rebuild" \
"repl FLAKE" "Enter a repl with the flake's outputs"
}
case "$1" in
""|"-h"|"help"|*(-)"help")
usage
;;
"up")
mkdir -p "$DEVSHELL_ROOT/up"
# `sudo` is necessary for `btrfs subvolume show`
sudo nixos-generate-config --dir "$DEVSHELL_ROOT/up/$HOSTNAME"
printf "%s\n" \
"{ suites, ... }:" \
"{" \
" imports = [" \
" ../up/$HOSTNAME/configuration.nix" \
" ] ++ suites.core;" \
"}" > "$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
git add -f \
"$DEVSHELL_ROOT/up/$HOSTNAME" \
"$DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix"
;;
"update")
if [[ -n "$2" ]]; then
if [[ -n "$3" ]]; then
(cd $2; nix flake lock --update-input "$3")
else
(cd $2; nix flake update)
fi
nix flake lock --update-input "$2" "$DEVSHELL_ROOT"
else
nix flake update "$DEVSHELL_ROOT"
fi
;;
"get")
if [[ "$2" == "core" || "$2" == "community" ]]; then
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
else
echo "flk get (core|community) [DEST]"
exit 1
fi
;;
"build")
nix build \
"$DEVSHELL_ROOT#nixosConfigurations.$2.config.system.build.$3" \
"${@:4}"
;;
"vm")
if [[ "$2" == "run" ]]; then
rm -rf "$DEVSHELL_ROOT/vm/tmp/$3"* \
&& nix build \
"$DEVSHELL_ROOT#nixosConfigurations.$3.config.system.build.vm" \
-o "$DEVSHELL_ROOT/vm/tmp/$3" \
"${@:4}" \
&& \
( \
export NIX_DISK_IMAGE="$DEVSHELL_ROOT/vm/tmp/$3.qcow2" \
&& "$DEVSHELL_ROOT/vm/tmp/$3/bin/run-$3-vm" \
) \
&& rm -rf "$DEVSHELL_ROOT/vm/tmp/$3"* \
&& rmdir --ignore-fail-on-non-empty "$DEVSHELL_ROOT/vm/tmp"
else
nix build \
"$DEVSHELL_ROOT#nixosConfigurations.$2.config.system.build.vm" \
-o "$DEVSHELL_ROOT/vm/$2" \
"${@:3}" \
&& echo "export NIX_DISK_IMAGE=\"$DEVSHELL_ROOT/vm/$2.qcow2\"" > "$DEVSHELL_ROOT/vm/run-$2" \
&& echo "$DEVSHELL_ROOT/vm/$2/bin/run-$2-vm" >> "$DEVSHELL_ROOT/vm/run-$2" \
&& chmod +x "$DEVSHELL_ROOT/vm/run-$2"
fi
;;
"install")
sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${@:3}"
;;
"home")
ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.activationPackage"
if [[ "$4" == "switch" ]]; then
nix build "$ref" && result/activate &&
unlink result
else
nix build "$ref" "${@:4}"
fi
;;
"repl")
repl ${@:2}
;;
*)
sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${@:2}"
;;
esac

View File

@ -1,29 +0,0 @@
#!/usr/bin/env bash
if 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
diff="git diff-index --name-only --cached $against --diff-filter d"
nix_files=($($diff -- '*.nix'))
all_files=($($diff))
# Format staged nix files.
if [[ -n "${nix_files[@]}" ]]; then
nixpkgs-fmt "${nix_files[@]}" \
&& git add "${nix_files[@]}"
fi
# check editorconfig
editorconfig-checker -- "${all_files[@]}"
if [[ $? != '0' ]]; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
fi