From e33f53ff2e227fbba9256f1fd695e7071a64fef4 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 11 Jan 2021 13:15:55 -0700 Subject: [PATCH 1/4] shell: add `flk up` command Automatically generate a configuration for your current system using nixos-generate-config, placed in the `up` directory. A file is added in hosts/up-$(hostname).nix importing said configuration. --- README.md | 9 +++------ shell.nix | 9 ++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5cfd37a..4ab0ed2 100644 --- a/README.md +++ b/README.md @@ -104,12 +104,9 @@ for ease of use. Once inside: # This will setup nix-command and pull in the needed tools nix-shell # or `direnv allow` if you prefer -# quick way to setup your fileSystems (assuming they are partioned): -sudo mount /dev/ /mnt -nixos-generate-config --root /mnt --show-hardware-config > hosts/yourConfig.nix - -# Edit your config to add a bootloader -$EDITOR hosts/yourConfig.nix +# use nixos-generate-config to generate a basic config for your system +# edit hosts/up-$(hostname).nix to modify. +flk up # The following should work fine for EFI systems. # boot.loader.systemd-boot.enable = true; diff --git a/shell.nix b/shell.nix index dd7e309..3b23540 100644 --- a/shell.nix +++ b/shell.nix @@ -17,7 +17,14 @@ let flk = pkgs.writeShellScriptBin "flk" '' if [[ -z "$1" ]]; then - echo "Usage: $(basename "$0") [ iso | install {host} | {host} [switch|boot|test] ]" + echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] ]" + elif [[ "$1" == "up" ]]; then + mkdir -p up + nixos-generate-config --dir up + echo \ + "{ + imports = [ ../up/configuration.nix ]; + }" > hosts/up-$(hostname).nix elif [[ "$1" == "iso" ]]; then nix build ${configs}.niximg.${build}.isoImage elif [[ "$1" == "install" ]]; then From 86ee73655284323e8f8b51e7e720dafcfd29c6fd Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 11 Jan 2021 13:20:52 -0700 Subject: [PATCH 2/4] shell: ignore `flk up` generated configs --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 726d2d6..4e131a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ result +up +hosts/up-* .direnv From 620849bcf081465bdd3f306fad119137ab203c50 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 11 Jan 2021 16:21:40 -0700 Subject: [PATCH 3/4] shell: namespace `flk up` Namespace and stage generated files so that the user can build it right away. --- shell.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shell.nix b/shell.nix index 3b23540..32c7920 100644 --- a/shell.nix +++ b/shell.nix @@ -20,11 +20,14 @@ let echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] ]" elif [[ "$1" == "up" ]]; then mkdir -p up - nixos-generate-config --dir up + hostname=$(hostname) + nixos-generate-config --dir up/$hostname echo \ "{ - imports = [ ../up/configuration.nix ]; - }" > hosts/up-$(hostname).nix + imports = [ ../up/$hostname/configuration.nix ]; + }" > hosts/up-$hostname.nix + git add -f up/$hostname + git add -f hosts/up-$hostname.nix elif [[ "$1" == "iso" ]]; then nix build ${configs}.niximg.${build}.isoImage elif [[ "$1" == "install" ]]; then From 253f175f558559a666e8790c82310671b74ff261 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 11 Jan 2021 17:32:58 -0700 Subject: [PATCH 4/4] README.md: add note on the up command --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 4ab0ed2..d92c3fa 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,15 @@ flk install yourConfig # deploys hosts/yourConfig.nix flk yourConfig switch ``` +### Note on `flk up`: +While the `up` sub-command is provided as a convenience to quickly set up and +install a "fresh" NixOS system on current hardware, committing these files is +discouraged. + +They are placed in the git staging area automatically because they would be +invisible to the flake otherwise, but it is best to move what you need from +them directly into your hosts file and commit that instead. + ## Build an ISO You can make an ISO and customize it by modifying the [niximg](./hosts/niximg.nix)