colemickens / nixcfg

NixOS and Home-Manager configs for my devices. dotfiles, but way better
367 stars 9 forks source link

how to install locally #3

Closed seghers closed 3 years ago

seghers commented 3 years ago

Dear Cole

You have a beautiful config and I'd like to use it to bootstrap my own flake based config.

Your config is one of the only ones which has sway, I'm currently on gnome.

I have a script which partitions the disk: grub, zfs(single, or mirror) Copies you slightly modified(hashedPasswords,hardware-configurations.nix) config to /mnt/tmp/nixcfg

But when I try to install slynux I get errors. What command do you use to install a new system?

I tried:

nix build /mnt/tmp/nixcfg#slynux --out-link /tmp/outsystem
error: flake 'git+file:///mnt/tmp/nixcfg' does not provide attribute 
    'packages.x86_64-linux.slynux',
    'legacyPackages.x86_64-linux.slynux' or 
    'slynux'

and

sudo nixos-install --root /mnt --flake '.#slynux'
error: flake 'git+file:///mnt/tmp/nixcfg' does not provide attribute 
     'packages.x86_64-linux.nixosConfigurations."slynux".config.system.build.toplevel',
     'legacyPackages.x86_64-linux.nixosConfigurations."slynux".config.system.build.toplevel' or 
     'nixosConfigurations."slynux".config.system.build.toplevel'

Do I have to change the secrets/passwords? (I try to get started without figuring out sops,age,git-crypt,...) I did build my own iso which has a copy of this repo.

nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=./my_iso.nix

my_iso.nix

# Configuration for (re)installing NixOS.
# { pkgs, lib, modulesPath, self, ... }:
{ pkgs, lib, modulesPath, ... }:

##   - Build iso:
# nix build .#iso --impure
#  # or if flake.nix is not configured
# nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=./my_iso.nix
##   - Test iso:
# mkdir -p ~/test_iso_mount
# mount -o loop -t iso9660 ./result/iso/my-nixos-live.iso ~/test_iso_mount
# umount ~/test_iso_mount && rm -rf ~/test_iso_mount
##   - Find installation device (eg. /dev/sdX):
# lsblk
##   - Write to thumb-drive:
# sudo dd bs=4M if=result/iso/my-nixos-live.iso of=/dev/sdX status=progress oflag=sync

{
  imports =
    [
      # (modulesPath + "/installer/cd-dvd/installation-cd-minimal-new-kernel.nix"
      (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
      ## GUI
      # (modulesPath + "/installer/cd-dvd/installation-cd-graphical-gnome.nix")

      # (modulesPath + "/profiles/qemu-guest.nix")
    ];

  nix = {
    package = pkgs.nixUnstable;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
  };

  environment.systemPackages = with pkgs;
    [
      git
      htop
      tree
      neovim
      silver-searcher
      # cryptsetup
      # veracrypt

      ## GUI
      # alacritty
    ];

  ## FIX for running out of space / tmp, which is used for building
  fileSystems."/nix/.rw-store" = {
    fsType = "tmpfs";
    # options = [ "mode=0755" ];
    options = [ "mode=0755" "nosuid" "nodev" "relatime" "size=14G" ];
    neededForBoot = true;
  };

  isoImage.volumeID = lib.mkForce "my-nixos-live";
  isoImage.isoName = lib.mkForce "my-nixos-live.iso";
  isoImage.contents = [
    # { source = ./README.md;
    #   target = "/README.md";
    # }
    { source = pkgs.writeText "readme"
        ''
          This Live Iso was generated by ME.
          See nixcfg/README.md
        '';
      target = "/README.txt"; # /iso/README.txt
    }
    ## Use --impure to solve error: "error: access to path '/home/my/nixcfg' is forbidden in restricted mode"
    { source = /home/my/nixcfg;
    ## self doesn't work.
    # { source = self;
      target = "/nixcfg/"; # /iso/nixcfg
    }
  ];
  # isoImage.storeContents = []; # TODO: Put a full offline store in the iso?

  time.timeZone = "UTC";
  # time.timeZone = "Europe/Brussels";
  i18n.defaultLocale = "en_US.UTF-8";
  console = {
    # https://github.com/NixOS/nixpkgs/issues/114698
    earlySetup = true; # Sets the font size much earlier in the boot process
    # font = "Lat2-Terminus16";
    font = "ter-v20n";
    # keyMap = "us";
    keyMap = "colemak/colemak";
  };

  networking = {
    hostName = "my-nixos-live";
    usePredictableInterfaceNames = false;
    interfaces.eth0.ipv4.addresses = [
      { address = "192.168.1.69"; prefixLength = 24; }
    ];
    defaultGateway = "192.168.1.1";
    nameservers = [ "192.168.1.1" "1.1.1.1" "8.8.8.8" ];
  };
}

Thanks for reading.

seghers commented 3 years ago

forgot to uncomment https://github.com/colemickens/nixcfg/blob/bd440e277965ac58c3aec36ef50adb51158bf52c/flake.nix#L185

colemickens commented 3 years ago

nice! :) glad you got it working, glad it's helpful!

seghers commented 3 years ago

Dear Cole

When I try to add './hardware-configuration.nix' in the imports, nix can't find it. Do I have to add it somewhere else, or is that the reason you put it all in 'configuration.nix'

https://github.com/colemickens/nixcfg/blob/ac4971f7285af12514ab597b5257ed4ffe22baa0/hosts/slynux/configuration.nix#L7

During installation the id's change, that's why I'd like it in a separate file which is generated independently.

cd /mnt/tmp/nixcfg
sudo nixos-install --root /mnt --flake ".#slynux
colemickens commented 3 years ago

idk, it's flakes, so you need to make sure git can see it git add . or git add hardware-configuration.nix or whatever.