Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from NobbZ/overhaul
Browse files Browse the repository at this point in the history
Redesign how the system is built
  • Loading branch information
NobbZ committed Mar 20, 2022
2 parents 891b6d5 + 29bae74 commit 658379d
Show file tree
Hide file tree
Showing 154 changed files with 5,577 additions and 2,738 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
@@ -1 +1 @@
/result
/result*
File renamed without changes.
39 changes: 39 additions & 0 deletions apps/switch/default.nix
@@ -0,0 +1,39 @@
{
self,
unstable,
...
}: let
pkgs = unstable.legacyPackages.x86_64-linux;
type = "app";
program = "${switch}/bin/switch";

nixosConfigs = pkgs.writeText "nixosConfigs" ''
${__toJSON (__attrNames self.nixosConfigurations)}
'';

homeConfigs = pkgs.writeText "homeConfigs" ''
${__toJSON (__attrNames self.homeConfigurations)}
'';

switch = pkgs.stdenv.mkDerivation {
pname = "nobbz-flake-switcher";
version = "0.0.1";

buildInputs = [self.packages.x86_64-linux.zx];

src = ./.;

installPhase = ''
mkdir -p $out/{bin,lib}
cat <<EOF > $out/bin/switch
#!${pkgs.bash}/bin/bash
exec $out/lib/switch.mjs --nixos ${nixosConfigs} --home ${homeConfigs} "\$@"
EOF
chmod ugo=rx $out/bin/switch
install --mode=555 switch.mjs $out/lib/switch.mjs
'';
};
in {inherit type program;}
52 changes: 52 additions & 0 deletions apps/switch/switch.mjs
@@ -0,0 +1,52 @@
#!/usr/bin/env zx

const info = (line) => console.log(chalk.yellow(line));

const trim = (str) => str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');

console.log(process.argv.slice(2))

console.log(argv)

info("loading nixos names")

const nixosConfigs = JSON.parse(await fs.readFile(argv.nixos))

info("loading home manager names")

const homeConfigs = JSON.parse(await fs.readFile(argv.home))

info("reading hostname");

const hostName = (await fs.readFile("/etc/hostname", "utf8")).trim()

info("reading user");

const user = process.env.USER.trim();

info("finished reading inputs")

const targets = [
`.#nixos/config/${hostName}`,
`.#home/config/${user}@${hostName}`,
]

await $`nix build --keep-going --log-format bar-with-logs -v ${targets}`

await fs.readdir('.')
.then(dirs => Promise.all(dirs
.filter(name => name.startsWith('result'))
.map(async link => {
const activate = `./${link}/bin/home-manager-generation`;

await fs.stat(activate)
.then(() => $`${activate}`)
.catch(() => {})
})))

await $`sudo nixos-rebuild switch --flake .#${hostName}`

await fs.readdir('.')
.then(dirs => Promise.all(dirs
.filter(name => name.startsWith('result'))
.map(async link => await $`rm ${link}`)))
31 changes: 31 additions & 0 deletions apps/update/default.nix
@@ -0,0 +1,31 @@
{
self,
unstable,
...
}: let
pkgs = unstable.legacyPackages.x86_64-linux;
type = "app";
program = "${update}/bin/update";

update = pkgs.stdenv.mkDerivation {
pname = "nobbz-flake-updater";
version = "0.0.1";

buildInputs = [self.packages.x86_64-linux.zx];

src = ./.;

installPhase = ''
mkdir -p $out/{bin,lib}
cat <<EOF > $out/bin/update
#!${pkgs.bash}/bin/bash
exec $out/lib/update.mjs
EOF
chmod ugo=rx $out/bin/update
install --mode=555 update.mjs $out/lib/update.mjs
'';
};
in {inherit type program;}
3 changes: 3 additions & 0 deletions apps/update/update.mjs
@@ -0,0 +1,3 @@
#!/usr/bin/env zx

await $`nix flake update --commit-lock-file`

0 comments on commit 658379d

Please sign in to comment.