From 34d6f22b61dcbaf23d6d74c5e8256ab0f202d51d Mon Sep 17 00:00:00 2001 From: DashieTM Date: Sat, 31 Aug 2024 14:29:16 +0200 Subject: [PATCH] Add iso --- .github/workflows/release.yaml | 30 ++++++++ base/common_hardware.nix | 3 +- docs/default.nix | 2 +- docs/src/README.md | 15 ++-- example/flake.nix | 2 +- example/hosts/example/configuration.nix | 5 +- example/{hosts => }/secrets/secrets.md | 0 example/{hosts => }/secrets/secrets.yaml | 0 flake.nix | 8 ++- iso/configuration.nix | 50 ++++++++++++++ lib/default.nix | 88 +++++++++++++++--------- modules/conf.nix | 9 --- result | 2 +- 13 files changed, 153 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/release.yaml rename example/{hosts => }/secrets/secrets.md (100%) rename example/{hosts => }/secrets/secrets.yaml (100%) create mode 100644 iso/configuration.nix diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ecee195 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,30 @@ +# by https://github.com/danth/stylix/blob/master/.github/workflows/docs.yml +name: Release +on: + release: + types: [created] +jobs: + build: + name: Release + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + extra-conf: | + extra-experimental-features = nix-command flakes + - name: Set up cache + uses: DeterminateSystems/magic-nix-cache-action@main + - name: Build ISO + run: nix build github:${{ github.repository }}/${{ github.sha }}#iso + - name: Prepare ISO for upload + run: | + cp -r --dereference --no-preserve=mode,ownership result/ public/ + - name: upload ISO + uses: softprops/action-gh-release@v1 + with: + path: path/ + diff --git a/base/common_hardware.nix b/base/common_hardware.nix index 5bbd1e3..7d7282c 100644 --- a/base/common_hardware.nix +++ b/base/common_hardware.nix @@ -2,6 +2,7 @@ pkgs, config, lib, + hostName, modulesPath, ... }: @@ -47,7 +48,7 @@ in networking = { useDHCP = lib.mkDefault true; networkmanager.enable = true; - hostName = config.conf.hostname; + hostName = hostName; }; # Set your time zone. diff --git a/docs/default.nix b/docs/default.nix index ba2bfdd..a5a5f8d 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -14,7 +14,7 @@ let summaryAppend = name: '' echo "- [${name}](${name}.md)" >> src/SUMMARY.md ''; - system = (build_systems [ "example" ] ../example/.)."example".options; + system = (build_systems ../example/.)."example".options; makeOptionsDocPrograms = name: pkgs.nixosOptionsDoc { options = system.mods.${name}; }; conf = makeOptionsDoc system.conf; paths = builtins.readDir ../modules/programs; diff --git a/docs/src/README.md b/docs/src/README.md index 813c0c0..2caf918 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -26,13 +26,12 @@ dashNix = { You can then configure your systems in your flake outputs with a provided library command: ```nix -nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems [ - "system1" - "system2" - "system3" -] ./.); +nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems ./.); ``` +The paremeter specifies where your hosts directory will be placed, in said directory you can then create a directory for each system. +Note, the name of the systems directory is also its hostname. + In order for your configuration to work, you are required to at least provide a single config file with a further config file being optional for custom configuration. The hardware.nix specifies additional NixOS configuration, while home.nix specifies additional home-manager configuration. (both optional) @@ -55,7 +54,7 @@ The hardware.nix specifies additional NixOS configuration, while home.nix specif Here is a minimal required configuration.nix (the TODOs mention a required change): ```nix -{ +{config, ...}: { # variables for system # TODO important changes conf = { @@ -64,8 +63,6 @@ Here is a minimal required configuration.nix (the TODOs mention a required chang monitor = "YOURMONITOR"; # your username username = "YOURNAME"; - # the name of your system - hostname = "YOURNAME"; # TODO only needed when you use intel -> amd is default # cpu = "intel"; locale = "something.UTF-8"; @@ -100,7 +97,7 @@ Here is a minimal required configuration.nix (the TODOs mention a required chang hyprland.monitor = [ # default # TODO change this to your resolution - "DP-1,1920x1080@144,0x0,1" + "${config.conf.monitor},1920x1080@144,0x0,1" # all others ",highrr,auto,1" ]; diff --git a/example/flake.nix b/example/flake.nix index 6f42a57..4ae9e17 100644 --- a/example/flake.nix +++ b/example/flake.nix @@ -24,7 +24,7 @@ outputs = { ... }@inputs: { - nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems [ "example" ] ./.); + nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems ./.); }; nixConfig = { diff --git a/example/hosts/example/configuration.nix b/example/hosts/example/configuration.nix index f1db2e5..392656e 100644 --- a/example/hosts/example/configuration.nix +++ b/example/hosts/example/configuration.nix @@ -1,3 +1,4 @@ +{ config, ... }: { # variables for system # TODO important changes @@ -7,8 +8,6 @@ monitor = "YOURMONITOR"; # your username username = "YOURNAME"; - # the name of your system - hostname = "YOURNAME"; # TODO only needed when you use intel -> amd is default # cpu = "intel"; locale = "something.UTF-8"; @@ -52,7 +51,7 @@ hyprland.monitor = [ # default # TODO change this to your resolution - "DP-1,1920x1080@144,0x0,1" + "${config.conf.monitor},1920x1080@144,0x0,1" # all others ",highrr,auto,1" ]; diff --git a/example/hosts/secrets/secrets.md b/example/secrets/secrets.md similarity index 100% rename from example/hosts/secrets/secrets.md rename to example/secrets/secrets.md diff --git a/example/hosts/secrets/secrets.yaml b/example/secrets/secrets.yaml similarity index 100% rename from example/hosts/secrets/secrets.yaml rename to example/secrets/secrets.yaml diff --git a/flake.nix b/flake.nix index 290d194..52680f9 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,7 @@ }; outputs = - { ... }@inputs: + { self, ... }@inputs: let stable = import inputs.stable { system = "x86_64-linux"; @@ -67,7 +67,10 @@ }; in rec { - dashNixLib = import ./lib { inherit inputs pkgs; }; + dashNixLib = import ./lib { + inherit self inputs pkgs; + lib = inputs.nixpkgs.lib; + }; docs = import ./docs { inherit inputs pkgs; lib = inputs.nixpkgs.lib; @@ -77,6 +80,7 @@ stablePkgs = stable; unstablePkgs = pkgs; modules = ./modules; + iso = dashNixLib.buildIso.config.system.build.isoImage; }; nixConfig = { diff --git a/iso/configuration.nix b/iso/configuration.nix new file mode 100644 index 0000000..7461131 --- /dev/null +++ b/iso/configuration.nix @@ -0,0 +1,50 @@ +{ + pkgs, + lib, + modulesPath, + self, + ... +}: +{ + + imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix" ]; + nixpkgs.hostPlatform = { + system = "x86_64-linux"; + }; + + environment.systemPackages = with pkgs; [ + neovim + disko + git + vesktop + vscodium + firefox + kitty + ]; + networking = { + wireless.enable = false; + networkmanager.enable = true; + }; + + services.greetd = { + enable = true; + settings = { + initial_session = { + command = "${pkgs.hyprland}/bin/Hyprland"; + user = "nixos"; + }; + }; + }; + + isoImage = { + isoName = lib.mkForce "DashNix.iso"; + makeEfiBootable = true; + makeUsbBootable = true; + contents = [ + { + source = "${self}/example"; + target = "example-config"; + } + ]; + }; +} diff --git a/lib/default.nix b/lib/default.nix index c50257b..f16ceb3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,6 +1,8 @@ { inputs, pkgs, + self, + lib, additionalMods ? { nixos = [ ]; home = [ ]; @@ -42,12 +44,6 @@ The second parameter is the root of your configuration, which should be ./. in most cases. - # Inputs - - `systems` - - : a list of strings with hostnames - `root` : the root path of your configuration @@ -60,36 +56,60 @@ ``` ::: */ + # let + # paths = builtins.readDir ; + # names = lib.lists.remove "default" ( + # map (name: lib.strings.removeSuffix ".nix" name) (lib.attrsets.mapAttrsToList (name: _: name) paths) + # ); + + # in build_systems = - systems: root: + root: builtins.listToAttrs ( - map (name: { - name = name; - value = - let - mod = root + /hosts/${name}/configuration.nix; - additionalNixosConfig = root + /hosts/${name}/hardware.nix; - additionalHomeConfig = root + /hosts/${name}/home.nix; - in - inputs.nixpkgs.lib.nixosSystem { - specialArgs = { - inherit - inputs - pkgs - mod - additionalHomeConfig - root - ; - homeMods = mods.home; - additionalHomeMods = additionalMods.home; + map + (name: { + name = name; + value = + let + mod = root + /hosts/${name}/configuration.nix; + additionalNixosConfig = root + /hosts/${name}/hardware.nix; + additionalHomeConfig = root + /hosts/${name}/home.nix; + in + inputs.nixpkgs.lib.nixosSystem { + specialArgs = { + inherit + self + inputs + pkgs + mod + additionalHomeConfig + root + ; + hostName = name; + homeMods = mods.home; + additionalHomeMods = additionalMods.home; + }; + modules = + [ mod ] + ++ mods.nixos + ++ additionalMods.nixos + ++ inputs.nixpkgs.lib.optional (builtins.pathExists additionalNixosConfig) additionalNixosConfig + ++ inputs.nixpkgs.lib.optional (builtins.pathExists mod) mod; }; - modules = - [ mod ] - ++ mods.nixos - ++ additionalMods.nixos - ++ inputs.nixpkgs.lib.optional (builtins.pathExists additionalNixosConfig) additionalNixosConfig - ++ inputs.nixpkgs.lib.optional (builtins.pathExists mod) mod; - }; - }) systems + }) + ( + lib.lists.remove "" ( + lib.attrsets.mapAttrsToList (name: fType: if fType == "directory" then name else "") ( + builtins.readDir (root + /hosts) + ) + ) + ) ); + + buildIso = inputs.nixpkgs.lib.nixosSystem { + specialArgs = { + inherit self inputs pkgs; + }; + modules = [ ../iso/configuration.nix ]; + }; } diff --git a/modules/conf.nix b/modules/conf.nix index f1f2b34..dcaa1e7 100644 --- a/modules/conf.nix +++ b/modules/conf.nix @@ -103,15 +103,6 @@ ''; }; - hostname = lib.mkOption { - default = "nixos"; - example = "spaceship"; - type = lib.types.str; - description = '' - The name of the system - ''; - }; - username = lib.mkOption { default = "dashie"; example = "pingpang"; diff --git a/result b/result index 35e10bf..f3888e2 120000 --- a/result +++ b/result @@ -1 +1 @@ -/nix/store/3y1kplrb4rnks5hpb3n9c0r3x5x3lw54-dashNix-book \ No newline at end of file +/nix/store/9snhsj18w6vyi4f25sq93az859yigcdp-DashNix.iso \ No newline at end of file