From 6fe4ca5f40a79acf359e1e56a4e640c1100a08b3 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Mon, 19 Feb 2024 12:50:19 +0100 Subject: [PATCH] WIP --- README.md | 3 ++ flake.nix | 33 ++++++++++++++++++++++ flakes.nix | 0 home.nix | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 README.md create mode 100644 flake.nix delete mode 100644 flakes.nix create mode 100644 home.nix create mode 100644 setup.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..94b8965 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager +nix-channel --update +nix-shell '' -A install diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1daf946 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + description = "My Dotfiles Flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + home-manager.url = "github:nix-community/home-manager"; + + darwin = { + url = "github:/lnl7/nix-darwin/master"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + home-manager = { + url = "github:nix-community/home-manager/master"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, home-manager, ... }: + let + lib = nixpkgs.lib; + pkgs = nixpacks.legacyPackages.${nixpkgs.system}; + in { + homeConfigurations = { + menno = gome-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [ + ./home.nix + ]; + }; + }; + } +} \ No newline at end of file diff --git a/flakes.nix b/flakes.nix deleted file mode 100644 index e69de29..0000000 diff --git a/home.nix b/home.nix new file mode 100644 index 0000000..922b33a --- /dev/null +++ b/home.nix @@ -0,0 +1,75 @@ +{ config, pkgs, ... }: + +{ + # Home Manager needs a bit of information about you and the paths it should + # manage. + home.username = "menno"; + home.homeDirectory = "/home/menno"; + + # This value determines the Home Manager release that your configuration is + # compatible with. This helps avoid breakage when a new Home Manager release + # introduces backwards incompatible changes. + # + # You should not change this value, even if you update Home Manager. If you do + # want to update the value, then make sure to first check the Home Manager + # release notes. + home.stateVersion = "23.11"; # Please read the comment before changing. + + # The home.packages option allows you to install Nix packages into your + # environment. + home.packages = [ + # # Adds the 'hello' command to your environment. It prints a friendly + # # "Hello, world!" when run. + pkgs.hello + + # # It is sometimes useful to fine-tune packages, for example, by applying + # # overrides. You can do that directly here, just don't forget the + # # parentheses. Maybe you want to install Nerd Fonts with a limited number of + # # fonts? + # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) + + # # You can also create simple shell scripts directly inside your + # # configuration. For example, this adds a command 'my-hello' to your + # # environment: + # (pkgs.writeShellScriptBin "my-hello" '' + # echo "Hello, ${config.home.username}!" + # '') + ]; + + # Home Manager is pretty good at managing dotfiles. The primary way to manage + # plain files is through 'home.file'. + home.file = { + # # Building this configuration will create a copy of 'dotfiles/screenrc' in + # # the Nix store. Activating the configuration will then make '~/.screenrc' a + # # symlink to the Nix store copy. + # ".screenrc".source = dotfiles/screenrc; + + # # You can also set the file content immediately. + # ".gradle/gradle.properties".text = '' + # org.gradle.console=verbose + # org.gradle.daemon.idletimeout=3600000 + # ''; + }; + + # Home Manager can also manage your environment variables through + # 'home.sessionVariables'. If you don't want to manage your shell through Home + # Manager then you have to manually source 'hm-session-vars.sh' located at + # either + # + # ~/.nix-profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # /etc/profiles/per-user/menno/etc/profile.d/hm-session-vars.sh + # + home.sessionVariables = { + # EDITOR = "emacs"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..6bbf57f --- /dev/null +++ b/setup.sh @@ -0,0 +1,83 @@ +#!/bin/bash +NIX_CONFIG_URL="https://gist.githubusercontent.com/vleeuwenmenno/4671a99beca2e45dc4b0211de7865dfe/raw/8eb0656fe956db81b18d31caad54aaff66298e0a/nix.conf" + +help() { + echo "Usage: $0 [option...]" >&2 + echo + echo " -i, --init Initial installation" + echo " -c, --continue Continue installation" + echo " -h, --help Display this help message" + echo + exit 1 +} + +install_nix() { + # Check if nix is installed (nix command is available) + if command -v nix > /dev/null; then + echo 'NIX is already installed.' + else + echo 'Installing NIX' + sh <(curl -L https://nixos.org/nix/install) --daemon + + echo 'Please restart your shell to continue...' + touch ~/.setup-initial-done + fi +} + +hush_login() { + # If .hushlogin does not exist, create it + if [ -f ~/.hushlogin ]; then + echo 'Login message is already disabled.' + else + echo 'Disabling login message.' + touch ~/.hushlogin + fi +} + +nix_experimental() { + if command -v nix > /dev/null; then + echo 'NIX is already installed.' + else + install_nix + fi + + echo "Adding experimental-features to nix.conf..." + grep -qxF 'experimental-features = nix-command flakes' /etc/nix/nix.conf || echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf +} + +nix_config_import() { + # Check if nix configuration is already inserted + if [ -f ~/.config/nix/nix.conf ]; then + echo "Nix configuration is already inserted." + exit 1 + else + echo "Inserting nix configuration..." + mkdir -p ~/.config/nix + curl -s $NIX_CONFIG_URL -o ~/.config/nix/nix.conf + fi +} + +# Check if parameter is help, continue or initial +if [ "$1" == "-c" ] || [ "$1" == "--continue" ]; then + rm ~/.setup-initial-done + + # Add experimental-features to nix.conf + nix_experimental + + # Insert nix configuration from github gist + nix_config_import + + +elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + help +elif [ "$1" == "-i" ] || [ "$1" == "--init" ]; then + # Ubuntu specific, hide login message + hush_login + + # Install nix + install_nix +else + help +fi + +